mirror of
https://github.com/danog/PHP-Parser.git
synced 2024-12-12 09:29:47 +01:00
b7e6361536
- "global" -> remove unused "use" statements - "phpunit" -> fix "@covers" comments - "phpunit" -> replace "->will($this->returnValue()" with "->willReturn()" - "UseTest.php" -> add missing namespace - "composer.json" -> use "autoload-dev" - remove -> "require_once" usage in the tests (use autoload-dev via composer.json) -> most of the changes are done automatically by "https://github.com/rectorphp/rector"
53 lines
1.5 KiB
PHP
53 lines
1.5 KiB
PHP
<?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_([]))
|
|
;
|
|
}
|
|
}
|