1 <?php declare(strict_types=1);
3 namespace PhpParser\Builder;
7 use PhpParser\Node\Name;
8 use PhpParser\Node\Stmt;
9 use PHPUnit\Framework\TestCase;
11 class TraitUseTest extends TestCase
13 protected function createTraitUseBuilder(...$traits) {
14 return new TraitUse(...$traits);
17 public function testAnd() {
18 $node = $this->createTraitUseBuilder('SomeTrait')
25 new Name('SomeTrait'),
26 new Name('AnotherTrait')
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'))
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')
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_([]))