Mercurial > hg > isophonics-drupal-site
comparison vendor/nikic/php-parser/test/PhpParser/Builder/TraitTest.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children | 5fb285c0d0e3 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 namespace PhpParser\Builder; | |
4 | |
5 use PhpParser\Comment; | |
6 use PhpParser\Node\Name; | |
7 use PhpParser\Node\Stmt; | |
8 | |
9 class TraitTest extends \PHPUnit_Framework_TestCase | |
10 { | |
11 protected function createTraitBuilder($class) { | |
12 return new Trait_($class); | |
13 } | |
14 | |
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') | |
21 )); | |
22 $use = new Stmt\TraitUse([new Name('OtherTrait')]); | |
23 $trait = $this->createTraitBuilder('TestTrait') | |
24 ->setDocComment('/** Nice trait */') | |
25 ->addStmt($method1) | |
26 ->addStmts([$method2, $method3]) | |
27 ->addStmt($prop) | |
28 ->addStmt($use) | |
29 ->getNode(); | |
30 $this->assertEquals(new Stmt\Trait_('TestTrait', [ | |
31 'stmts' => [$use, $prop, $method1, $method2, $method3] | |
32 ], [ | |
33 'comments' => [ | |
34 new Comment\Doc('/** Nice trait */') | |
35 ] | |
36 ]), $trait); | |
37 } | |
38 | |
39 /** | |
40 * @expectedException \LogicException | |
41 * @expectedExceptionMessage Unexpected node of type "Stmt_Echo" | |
42 */ | |
43 public function testInvalidStmtError() { | |
44 $this->createTraitBuilder('Test') | |
45 ->addStmt(new Stmt\Echo_(array())) | |
46 ; | |
47 } | |
48 } |