mirror of
https://github.com/phabelio/PHP-Parser.git
synced 2024-12-12 09:09:41 +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"
47 lines
1.4 KiB
PHP
47 lines
1.4 KiB
PHP
<?php declare(strict_types=1);
|
|
|
|
namespace PhpParser\Builder;
|
|
|
|
use PhpParser\Comment;
|
|
use PhpParser\Node\Name;
|
|
use PhpParser\Node\Stmt;
|
|
|
|
class TraitTest extends \PHPUnit\Framework\TestCase
|
|
{
|
|
protected function createTraitBuilder($class) {
|
|
return new Trait_($class);
|
|
}
|
|
|
|
public function testStmtAddition() {
|
|
$method1 = new Stmt\ClassMethod('test1');
|
|
$method2 = new Stmt\ClassMethod('test2');
|
|
$method3 = new Stmt\ClassMethod('test3');
|
|
$prop = new Stmt\Property(Stmt\Class_::MODIFIER_PUBLIC, [
|
|
new Stmt\PropertyProperty('test')
|
|
]);
|
|
$use = new Stmt\TraitUse([new Name('OtherTrait')]);
|
|
$trait = $this->createTraitBuilder('TestTrait')
|
|
->setDocComment('/** Nice trait */')
|
|
->addStmt($method1)
|
|
->addStmts([$method2, $method3])
|
|
->addStmt($prop)
|
|
->addStmt($use)
|
|
->getNode();
|
|
$this->assertEquals(new Stmt\Trait_('TestTrait', [
|
|
'stmts' => [$use, $prop, $method1, $method2, $method3]
|
|
], [
|
|
'comments' => [
|
|
new Comment\Doc('/** Nice trait */')
|
|
]
|
|
]), $trait);
|
|
}
|
|
|
|
public function testInvalidStmtError() {
|
|
$this->expectException(\LogicException::class);
|
|
$this->expectExceptionMessage('Unexpected node of type "Stmt_Echo"');
|
|
$this->createTraitBuilder('Test')
|
|
->addStmt(new Stmt\Echo_([]))
|
|
;
|
|
}
|
|
}
|