mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-18 05:48:21 +01:00
[Symfony] add ConstraintValidatorTestClass rename Rector
This commit is contained in:
parent
5bbc0443fa
commit
413f57d620
@ -0,0 +1,70 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\Rector\Contrib\Symfony;
|
||||
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Stmt\Class_;
|
||||
use Rector\Deprecation\SetNames;
|
||||
use Rector\Rector\AbstractRector;
|
||||
|
||||
/**
|
||||
* @todo decouple abstract class AbstractReplaceParentClass
|
||||
*
|
||||
* Ref: https://github.com/symfony/symfony/blob/master/UPGRADE-4.0.md#validator
|
||||
*
|
||||
* Converts all:
|
||||
* Symfony\Component\Validator\Tests\Constraints\AbstractConstraintValidatorTest
|
||||
*
|
||||
* into:
|
||||
* Symfony\Component\Validator\Test\ConstraintValidatorTestCase
|
||||
*/
|
||||
final class ConstraintValidatorTestClassRenameRector extends AbstractRector
|
||||
{
|
||||
public function getSetName(): string
|
||||
{
|
||||
return SetNames::SYMFONY;
|
||||
}
|
||||
|
||||
public function sinceVersion(): float
|
||||
{
|
||||
return 4.0;
|
||||
}
|
||||
|
||||
public function isCandidate(Node $node): bool
|
||||
{
|
||||
if (! $node instanceof Class_) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (! $node->extends) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/** @var Node\Name $parentClassName */
|
||||
$parentClassNameNode = $node->extends;
|
||||
|
||||
/** @var Node\Name\FullyQualified $fsqName */
|
||||
$fsqName = $parentClassNameNode->getAttribute('resolvedName');
|
||||
|
||||
return $fsqName->toString() === $this->getOldClassName();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Class_ $node
|
||||
*/
|
||||
public function refactor(Node $node): ?Node
|
||||
{
|
||||
$node->extends = new Node\Name('\\' . $this->getNewClassName());
|
||||
return $node;
|
||||
}
|
||||
|
||||
private function getOldClassName(): string
|
||||
{
|
||||
return 'Symfony\Component\Validator\Tests\Constraints\AbstractConstraintValidatorTest';
|
||||
}
|
||||
|
||||
private function getNewClassName(): string
|
||||
{
|
||||
return 'Symfony\Component\Validator\Test\ConstraintValidatorTestCase';
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
<?php declare (strict_types=1);
|
||||
|
||||
use Symfony\Component\Validator\Tests\Constraints\AbstractConstraintValidatorTest;
|
||||
|
||||
class MyCustomValidatorTest extends \Symfony\Component\Validator\Test\ConstraintValidatorTestCase
|
||||
{
|
||||
// ...
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\Tests\Rector\Contrib\Symfony\ConstraintValidatorTestClassRenameRector;
|
||||
|
||||
use Rector\Rector\Contrib\Symfony\ConstraintValidatorTestClassRenameRector;
|
||||
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
|
||||
final class Test extends AbstractRectorTestCase
|
||||
{
|
||||
public function test(): void
|
||||
{
|
||||
$this->doTestFileMatchesExpectedContent(
|
||||
__DIR__ . '/Wrong/wrong.php.inc',
|
||||
__DIR__ . '/Correct/correct.php.inc'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
protected function getRectorClasses(): array
|
||||
{
|
||||
return [ConstraintValidatorTestClassRenameRector::class];
|
||||
}
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
<?php declare (strict_types=1);
|
||||
|
||||
use Symfony\Component\Validator\Tests\Constraints\AbstractConstraintValidatorTest;
|
||||
|
||||
class MyCustomValidatorTest extends AbstractConstraintValidatorTest
|
||||
{
|
||||
// ...
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user