mirror of https://github.com/rectorphp/rector.git
improve tests
This commit is contained in:
parent
d818014477
commit
61c7ef9de0
|
@ -18,7 +18,7 @@ final class FileProcessor
|
|||
/**
|
||||
* @var FormatPerservingPrinter
|
||||
*/
|
||||
private $codeStyledPrinter;
|
||||
private $formatPerservingPrinter;
|
||||
|
||||
/**
|
||||
* @var NodeTraverser
|
||||
|
@ -37,7 +37,7 @@ final class FileProcessor
|
|||
NodeTraverser $nodeTraverser
|
||||
) {
|
||||
$this->parser = $parser;
|
||||
$this->codeStyledPrinter = $codeStyledPrinter;
|
||||
$this->formatPerservingPrinter = $codeStyledPrinter;
|
||||
$this->nodeTraverser = $nodeTraverser;
|
||||
$this->lexer = $lexer;
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ final class FileProcessor
|
|||
|
||||
$newStmts = $this->nodeTraverser->traverse($oldStmts);
|
||||
|
||||
$this->codeStyledPrinter->printToFile($file, $newStmts, $oldStmts, $oldTokens);
|
||||
$this->formatPerservingPrinter->printToFile($file, $newStmts, $oldStmts, $oldTokens);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -38,17 +38,24 @@ final class StatementGlue
|
|||
$classNode->stmts[] = $node;
|
||||
}
|
||||
|
||||
public function addAsFirstTrait(Class_ $classNode, TraitUse $traitUse): void
|
||||
public function addAsFirstTrait(Class_ $classNode, Node $node): void
|
||||
{
|
||||
foreach ($classNode->stmts as $key => $classElementNode) {
|
||||
if ($classElementNode instanceof TraitUse) {
|
||||
$this->insertBefore($classNode, $traitUse, $key);
|
||||
$this->addStatementToClassBeforeTypes($classNode, $node, TraitUse::class, Property::class);
|
||||
}
|
||||
|
||||
return;
|
||||
private function addStatementToClassBeforeTypes(Class_ $classNode, Node $node, string ...$types): void
|
||||
{
|
||||
foreach ($types as $type) {
|
||||
foreach ($classNode->stmts as $key => $classElementNode) {
|
||||
if (is_a($classElementNode, $type, true)) {
|
||||
$this->insertBefore($classNode, $node, $key);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$classNode->stmts[] = $traitUse;
|
||||
$classNode->stmts[] = $node;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -15,19 +15,6 @@ abstract class AbstraceReplaceDeprecatedConstantNodeVisitor extends NodeVisitorA
|
|||
|
||||
abstract public function getNewConstantName(): string;
|
||||
|
||||
/**
|
||||
* Return value semantics:
|
||||
* * null
|
||||
* => $node stays as-is
|
||||
* * NodeTraverser::DONT_TRAVERSE_CHILDREN
|
||||
* => Children of $node are not traversed. $node stays as-is
|
||||
* * NodeTraverser::STOP_TRAVERSAL
|
||||
* => Traversal is aborted. $node stays as-is
|
||||
* * otherwise
|
||||
* => $node is set to the return value.
|
||||
*
|
||||
* @return null|int|Node
|
||||
*/
|
||||
public function enterNode(Node $node): ?int
|
||||
{
|
||||
if ($this->isCandidate($node)) {
|
||||
|
|
|
@ -8,13 +8,17 @@ final class Test extends AbstractReconstructorTestCase
|
|||
{
|
||||
public function test(): void
|
||||
{
|
||||
// $this->doTestFileMatchesExpectedContent(
|
||||
// __DIR__ . '/wrong/wrong.php.inc',
|
||||
// __DIR__ . '/correct/correct.php.inc'
|
||||
// );
|
||||
$this->doTestFileMatchesExpectedContent(
|
||||
__DIR__ . '/wrong/wrong.php.inc',
|
||||
__DIR__ . '/correct/correct.php.inc'
|
||||
);
|
||||
$this->doTestFileMatchesExpectedContent(
|
||||
__DIR__ . '/wrong/wrong2.php.inc',
|
||||
__DIR__ . '/correct/correct2.php.inc'
|
||||
);
|
||||
$this->doTestFileMatchesExpectedContent(
|
||||
__DIR__ . '/wrong/wrong3.php.inc',
|
||||
__DIR__ . '/correct/correct3.php.inc'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
<?php declare (strict_types=1);
|
||||
|
||||
class ClassWithExternalConstant
|
||||
{
|
||||
use \Nette\SmartObject;
|
||||
public $property;
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
<?php declare (strict_types=1);
|
||||
|
||||
class ClassWithExternalConstant extends Nette\Object
|
||||
{
|
||||
public $property;
|
||||
}
|
Loading…
Reference in New Issue