Mercurial > hg > isophonics-drupal-site
diff vendor/nikic/php-parser/test/PhpParser/Builder/TraitUseTest.php @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:21:36 +0000 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vendor/nikic/php-parser/test/PhpParser/Builder/TraitUseTest.php Thu Feb 28 13:21:36 2019 +0000 @@ -0,0 +1,52 @@ +<?php declare(strict_types=1); + +namespace PhpParser\Builder; + +use PhpParser\Node\Name; +use PhpParser\Node\Stmt; + +class TraitUseTest extends \PHPUnit\Framework\TestCase +{ + protected function createTraitUseBuilder(...$traits) { + return new TraitUse(...$traits); + } + + public function testAnd() { + $node = $this->createTraitUseBuilder('SomeTrait') + ->and('AnotherTrait') + ->getNode() + ; + + $this->assertEquals( + new Stmt\TraitUse([ + new Name('SomeTrait'), + new Name('AnotherTrait') + ]), + $node + ); + } + + public function testWith() { + $node = $this->createTraitUseBuilder('SomeTrait') + ->with(new Stmt\TraitUseAdaptation\Alias(null, 'foo', null, 'bar')) + ->with((new TraitUseAdaptation(null, 'test'))->as('baz')) + ->getNode() + ; + + $this->assertEquals( + new Stmt\TraitUse([new Name('SomeTrait')], [ + new Stmt\TraitUseAdaptation\Alias(null, 'foo', null, 'bar'), + new Stmt\TraitUseAdaptation\Alias(null, 'test', null, 'baz') + ]), + $node + ); + } + + public function testInvalidAdaptationNode() { + $this->expectException(\LogicException::class); + $this->expectExceptionMessage('Adaptation must have type TraitUseAdaptation'); + $this->createTraitUseBuilder('Test') + ->with(new Stmt\Echo_([])) + ; + } +}