Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / vendor / nikic / php-parser / test / PhpParser / Builder / TraitTest.php
1 <?php declare(strict_types=1);
2
3 namespace PhpParser\Builder;
4
5 use PhpParser\Comment;
6 use PhpParser\Node\Name;
7 use PhpParser\Node\Stmt;
8 use PHPUnit\Framework\TestCase;
9
10 class TraitTest extends TestCase
11 {
12     protected function createTraitBuilder($class) {
13         return new Trait_($class);
14     }
15
16     public function testStmtAddition() {
17         $method1 = new Stmt\ClassMethod('test1');
18         $method2 = new Stmt\ClassMethod('test2');
19         $method3 = new Stmt\ClassMethod('test3');
20         $prop = new Stmt\Property(Stmt\Class_::MODIFIER_PUBLIC, [
21             new Stmt\PropertyProperty('test')
22         ]);
23         $use = new Stmt\TraitUse([new Name('OtherTrait')]);
24         $trait = $this->createTraitBuilder('TestTrait')
25             ->setDocComment('/** Nice trait */')
26             ->addStmt($method1)
27             ->addStmts([$method2, $method3])
28             ->addStmt($prop)
29             ->addStmt($use)
30             ->getNode();
31         $this->assertEquals(new Stmt\Trait_('TestTrait', [
32             'stmts' => [$use, $prop, $method1, $method2, $method3]
33         ], [
34             'comments' => [
35                 new Comment\Doc('/** Nice trait */')
36             ]
37         ]), $trait);
38     }
39
40     public function testInvalidStmtError() {
41         $this->expectException(\LogicException::class);
42         $this->expectExceptionMessage('Unexpected node of type "Stmt_Echo"');
43         $this->createTraitBuilder('Test')
44             ->addStmt(new Stmt\Echo_([]))
45         ;
46     }
47 }