mirror of
https://github.com/danog/PHP-Parser.git
synced 2024-12-12 17:37:21 +01:00
29 lines
792 B
PHP
29 lines
792 B
PHP
<?php declare(strict_types=1);
|
|
|
|
namespace PhpParser\NodeVisitor;
|
|
|
|
use PhpParser\Node\Stmt\ClassMethod;
|
|
use PhpParser\NodeFinder;
|
|
use PhpParser\NodeTraverser;
|
|
use PhpParser\ParserFactory;
|
|
|
|
final class ParentConnectingVisitorTest extends \PHPUnit\Framework\TestCase
|
|
{
|
|
public function testConnectsChildNodeToParentNode()
|
|
{
|
|
$ast = (new ParserFactory)->create(ParserFactory::PREFER_PHP7)->parse(
|
|
'<?php class C { public function m() {} }'
|
|
);
|
|
|
|
$traverser = new NodeTraverser;
|
|
|
|
$traverser->addVisitor(new ParentConnectingVisitor);
|
|
|
|
$ast = $traverser->traverse($ast);
|
|
|
|
$node = (new NodeFinder)->findFirstInstanceof($ast, ClassMethod::class);
|
|
|
|
$this->assertSame('C', $node->getAttribute('parent')->name->toString());
|
|
}
|
|
}
|