diff --git a/config/sets/phpunit110.php b/config/sets/phpunit110.php index 74a42ef4..576dd372 100644 --- a/config/sets/phpunit110.php +++ b/config/sets/phpunit110.php @@ -3,6 +3,8 @@ declare(strict_types=1); use Rector\Config\RectorConfig; +use Rector\PHPUnit\PHPUnit110\Rector\Class_\NamedArgumentForDataProviderRector; return static function (RectorConfig $rectorConfig): void { + $rectorConfig->rule(NamedArgumentForDataProviderRector::class); }; diff --git a/config/sets/phpunit120.php b/config/sets/phpunit120.php new file mode 100644 index 00000000..5a1fc60b --- /dev/null +++ b/config/sets/phpunit120.php @@ -0,0 +1,10 @@ +rule(RemoveOverrideFinalConstructTestCaseRector::class); +}; diff --git a/rules-tests/PHPUnit120/Rector/Class_/RemoveOverrideFinalConstructTestCaseRector/Fixture/fixture.php.inc b/rules-tests/PHPUnit120/Rector/Class_/RemoveOverrideFinalConstructTestCaseRector/Fixture/fixture.php.inc new file mode 100644 index 00000000..00fbfda1 --- /dev/null +++ b/rules-tests/PHPUnit120/Rector/Class_/RemoveOverrideFinalConstructTestCaseRector/Fixture/fixture.php.inc @@ -0,0 +1,25 @@ + +----- + diff --git a/rules-tests/PHPUnit120/Rector/Class_/RemoveOverrideFinalConstructTestCaseRector/RemoveOverrideFinalConstructTestCaseRectorTest.php b/rules-tests/PHPUnit120/Rector/Class_/RemoveOverrideFinalConstructTestCaseRector/RemoveOverrideFinalConstructTestCaseRectorTest.php new file mode 100644 index 00000000..524c4e6b --- /dev/null +++ b/rules-tests/PHPUnit120/Rector/Class_/RemoveOverrideFinalConstructTestCaseRector/RemoveOverrideFinalConstructTestCaseRectorTest.php @@ -0,0 +1,28 @@ +doTestFile($filePath); + } + + public static function provideData(): Iterator + { + return self::yieldFilesFromDirectory(__DIR__ . '/Fixture'); + } + + public function provideConfigFilePath(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/rules-tests/PHPUnit120/Rector/Class_/RemoveOverrideFinalConstructTestCaseRector/config/configured_rule.php b/rules-tests/PHPUnit120/Rector/Class_/RemoveOverrideFinalConstructTestCaseRector/config/configured_rule.php new file mode 100644 index 00000000..5a1fc60b --- /dev/null +++ b/rules-tests/PHPUnit120/Rector/Class_/RemoveOverrideFinalConstructTestCaseRector/config/configured_rule.php @@ -0,0 +1,10 @@ +rule(RemoveOverrideFinalConstructTestCaseRector::class); +}; diff --git a/rules/PHPUnit100/Rector/Class_/ParentTestClassConstructorRector.php b/rules/PHPUnit100/Rector/Class_/ParentTestClassConstructorRector.php index 528e727a..870ef270 100644 --- a/rules/PHPUnit100/Rector/Class_/ParentTestClassConstructorRector.php +++ b/rules/PHPUnit100/Rector/Class_/ParentTestClassConstructorRector.php @@ -119,6 +119,10 @@ private function shouldSkipClass(Class_ $class): bool return true; } - return str_ends_with((string) $className, 'TestCase'); + if (str_ends_with((string) $className, 'TestCase')) { + return true; + } + + return (bool) $class->getAttribute('hasRemovedFinalConstruct'); } } diff --git a/rules/PHPUnit120/Rector/Class_/RemoveOverrideFinalConstructTestCaseRector.php b/rules/PHPUnit120/Rector/Class_/RemoveOverrideFinalConstructTestCaseRector.php new file mode 100644 index 00000000..f7938a82 --- /dev/null +++ b/rules/PHPUnit120/Rector/Class_/RemoveOverrideFinalConstructTestCaseRector.php @@ -0,0 +1,89 @@ +> + */ + public function getNodeTypes(): array + { + return [Class_::class]; + } + + /** + * @param Class_ $node + */ + public function refactor(Node $node): Node|null + { + if (! $this->testsNodeAnalyzer->isInTestClass($node)) { + return null; + } + + $constructClassMethod = $node->getMethod(MethodName::CONSTRUCT); + + if ($constructClassMethod instanceof ClassMethod) { + foreach ($node->stmts as $key => $stmt) { + if ($stmt instanceof ClassMethod && $this->isName($stmt, MethodName::CONSTRUCT)) { + unset($node->stmts[$key]); + + $node->setAttribute('hasRemovedFinalConstruct', true); + return $node; + } + } + } + + return null; + } +} diff --git a/src/Set/PHPUnitSetList.php b/src/Set/PHPUnitSetList.php index 271601f3..c1b20fcb 100644 --- a/src/Set/PHPUnitSetList.php +++ b/src/Set/PHPUnitSetList.php @@ -49,6 +49,11 @@ final class PHPUnitSetList */ public const PHPUNIT_110 = __DIR__ . '/../../config/sets/phpunit110.php'; + /** + * @var string + */ + public const PHPUNIT_120 = __DIR__ . '/../../config/sets/phpunit120.php'; + /** * @var string */