createTraitBuilder('TestTrait') ->setDocComment('/** Nice trait */') ->addStmt($method1) ->addStmts([$method2, $method3]) ->addStmt($prop) ->addStmt($use) ->addStmt($const) ->getNode(); $this->assertEquals(new Stmt\Trait_('TestTrait', [ 'stmts' => [$use, $const, $prop, $method1, $method2, $method3] ], [ 'comments' => [ new Comment\Doc('/** Nice trait */') ] ]), $trait); } public function testInvalidStmtError(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Unexpected node of type "Stmt_Echo"'); $this->createTraitBuilder('Test') ->addStmt(new Stmt\Echo_([])) ; } public function testGetMethods(): void { $methods = [ new ClassMethod('foo'), new ClassMethod('bar'), new ClassMethod('fooBar'), ]; $trait = new Stmt\Trait_('Foo', [ 'stmts' => [ new TraitUse([]), $methods[0], new ClassConst([]), $methods[1], new Property(0, []), $methods[2], ] ]); $this->assertSame($methods, $trait->getMethods()); } public function testGetProperties(): void { $properties = [ new Property(Modifiers::PUBLIC, [new PropertyItem('foo')]), new Property(Modifiers::PUBLIC, [new PropertyItem('bar')]), ]; $trait = new Stmt\Trait_('Foo', [ 'stmts' => [ new TraitUse([]), $properties[0], new ClassConst([]), $properties[1], new ClassMethod('fooBar'), ] ]); $this->assertSame($properties, $trait->getProperties()); } public function testAddAttribute(): void { $attribute = new Attribute( new Name('Attr'), [new Arg(new Int_(1), false, false, [], new Identifier('name'))] ); $attributeGroup = new AttributeGroup([$attribute]); $node = $this->createTraitBuilder('AttributeGroup') ->addAttribute($attributeGroup) ->getNode() ; $this->assertEquals( new Stmt\Trait_( 'AttributeGroup', [ 'attrGroups' => [$attributeGroup], ] ), $node ); } }