ec4e9400aab499231b92be41b647fcaffc748b0a
[yaffs-website] / vendor / nikic / php-parser / test / PhpParser / Builder / TraitUseTest.php
1 <?php declare(strict_types=1);
2
3 namespace PhpParser\Builder;
4
5 use PhpParser\Comment;
6 use PhpParser\Node;
7 use PhpParser\Node\Name;
8 use PhpParser\Node\Stmt;
9 use PHPUnit\Framework\TestCase;
10
11 class TraitUseTest extends TestCase
12 {
13     protected function createTraitUseBuilder(...$traits) {
14         return new TraitUse(...$traits);
15     }
16
17     public function testAnd() {
18         $node = $this->createTraitUseBuilder('SomeTrait')
19             ->and('AnotherTrait')
20             ->getNode()
21         ;
22
23         $this->assertEquals(
24             new Stmt\TraitUse([
25                 new Name('SomeTrait'),
26                 new Name('AnotherTrait')
27             ]),
28             $node
29         );
30     }
31
32     public function testWith() {
33         $node = $this->createTraitUseBuilder('SomeTrait')
34             ->with(new Stmt\TraitUseAdaptation\Alias(null, 'foo', null, 'bar'))
35             ->with((new TraitUseAdaptation(null, 'test'))->as('baz'))
36             ->getNode()
37         ;
38
39         $this->assertEquals(
40             new Stmt\TraitUse([new Name('SomeTrait')], [
41                 new Stmt\TraitUseAdaptation\Alias(null, 'foo', null, 'bar'),
42                 new Stmt\TraitUseAdaptation\Alias(null, 'test', null, 'baz')
43             ]),
44             $node
45         );
46     }
47
48     public function testInvalidAdaptationNode() {
49         $this->expectException(\LogicException::class);
50         $this->expectExceptionMessage('Adaptation must have type TraitUseAdaptation');
51         $this->createTraitUseBuilder('Test')
52             ->with(new Stmt\Echo_([]))
53         ;
54     }
55 }