3 namespace PhpParser\Builder;
6 use PhpParser\Node\Name;
7 use PhpParser\Node\Stmt;
9 class TraitTest extends \PHPUnit_Framework_TestCase
11 protected function createTraitBuilder($class) {
12 return new Trait_($class);
15 public function testStmtAddition() {
16 $method1 = new Stmt\ClassMethod('test1');
17 $method2 = new Stmt\ClassMethod('test2');
18 $method3 = new Stmt\ClassMethod('test3');
19 $prop = new Stmt\Property(Stmt\Class_::MODIFIER_PUBLIC, array(
20 new Stmt\PropertyProperty('test')
22 $use = new Stmt\TraitUse([new Name('OtherTrait')]);
23 $trait = $this->createTraitBuilder('TestTrait')
24 ->setDocComment('/** Nice trait */')
26 ->addStmts([$method2, $method3])
30 $this->assertEquals(new Stmt\Trait_('TestTrait', [
31 'stmts' => [$use, $prop, $method1, $method2, $method3]
34 new Comment\Doc('/** Nice trait */')
40 * @expectedException \LogicException
41 * @expectedExceptionMessage Unexpected node of type "Stmt_Echo"
43 public function testInvalidStmtError() {
44 $this->createTraitBuilder('Test')
45 ->addStmt(new Stmt\Echo_(array()))