Class Kitab\Compiler\Target\DocTest\CodeBlockHandler\IntoPHPTestCaseBody

class IntoPHPTestCaseBody extends PhpParser\NodeVisitorAbstract
{
    public function leaveNode(PhpParser\Node $node);
}

A visitor to transform an Abstract Syntax Tree (AST) into a test case body candidate.

So far, it applies the following transformations:

  • Remove the use statements, assuming all names have been resolved.

Examples

$code = '<?php use A\B\C; new C();';
$ast  = Kitab\Compiler\Parser::getPhpParser()->parse($code);

$traverser = new PhpParser\NodeTraverser();
$traverser->addVisitor(new PhpParser\NodeVisitor\NameResolver());
$traverser->addVisitor(new Kitab\Compiler\Target\DocTest\CodeBlockHandler\IntoPHPTestCaseBody());

$ast = $traverser->traverse($ast);

$testCaseCandidate = Kitab\Compiler\Parser::getPhpPrettyPrinter()->prettyPrint($ast);

assert('new \A\B\C();' === $testCaseCandidate);

Methods

public function leaveNode(PhpParser\Node $node)