diff --git a/config/sets/phpunit100.php b/config/sets/phpunit100.php index eb9045c4..c5417ad0 100644 --- a/config/sets/phpunit100.php +++ b/config/sets/phpunit100.php @@ -4,7 +4,6 @@ use Rector\Config\RectorConfig; use Rector\PHPUnit\PHPUnit100\Rector\Class_\AddProphecyTraitRector; -use Rector\PHPUnit\PHPUnit100\Rector\Class_\ParentTestClassConstructorRector; use Rector\PHPUnit\PHPUnit100\Rector\Class_\PublicDataProviderClassMethodRector; use Rector\PHPUnit\PHPUnit100\Rector\Class_\StaticDataProviderClassMethodRector; use Rector\PHPUnit\PHPUnit100\Rector\MethodCall\PropertyExistsWithoutAssertRector; @@ -24,7 +23,6 @@ WithConsecutiveRector::class, RemoveSetMethodsMethodCallRector::class, PropertyExistsWithoutAssertRector::class, - ParentTestClassConstructorRector::class, ]); $rectorConfig->ruleWithConfiguration(RenameMethodRector::class, [ diff --git a/rules-tests/PHPUnit100/Rector/Class_/ParentTestClassConstructorRector/Fixture/mocking_helper.php.inc b/rules-tests/PHPUnit100/Rector/Class_/ParentTestClassConstructorRector/Fixture/mocking_helper.php.inc deleted file mode 100644 index e1cff0cf..00000000 --- a/rules-tests/PHPUnit100/Rector/Class_/ParentTestClassConstructorRector/Fixture/mocking_helper.php.inc +++ /dev/null @@ -1,27 +0,0 @@ - ------ - diff --git a/rules-tests/PHPUnit100/Rector/Class_/ParentTestClassConstructorRector/Fixture/skip_abstract_classes.php.inc b/rules-tests/PHPUnit100/Rector/Class_/ParentTestClassConstructorRector/Fixture/skip_abstract_classes.php.inc deleted file mode 100644 index fd52e97c..00000000 --- a/rules-tests/PHPUnit100/Rector/Class_/ParentTestClassConstructorRector/Fixture/skip_abstract_classes.php.inc +++ /dev/null @@ -1,9 +0,0 @@ -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/PHPUnit100/Rector/Class_/ParentTestClassConstructorRector/config/configured_rule.php b/rules-tests/PHPUnit100/Rector/Class_/ParentTestClassConstructorRector/config/configured_rule.php deleted file mode 100644 index ef03034e..00000000 --- a/rules-tests/PHPUnit100/Rector/Class_/ParentTestClassConstructorRector/config/configured_rule.php +++ /dev/null @@ -1,10 +0,0 @@ -rule(ParentTestClassConstructorRector::class); -}; diff --git a/rules/PHPUnit100/Rector/Class_/ParentTestClassConstructorRector.php b/rules/PHPUnit100/Rector/Class_/ParentTestClassConstructorRector.php deleted file mode 100644 index 528e727a..00000000 --- a/rules/PHPUnit100/Rector/Class_/ParentTestClassConstructorRector.php +++ /dev/null @@ -1,124 +0,0 @@ -> - */ - public function getNodeTypes(): array - { - return [Class_::class]; - } - - /** - * @param Class_ $node - */ - public function refactor(Node $node): ?Node - { - if (! $this->testsNodeAnalyzer->isInTestClass($node)) { - return null; - } - - if ($this->shouldSkipClass($node)) { - return null; - } - - // it already has a constructor, skip as it might require specific tweaking - if ($node->getMethod(MethodName::CONSTRUCT)) { - return null; - } - - $constructorClassMethod = new ClassMethod(MethodName::CONSTRUCT); - $constructorClassMethod->flags |= Modifiers::PUBLIC; - $constructorClassMethod->stmts[] = new Expression($this->createParentConstructorCall()); - - $node->stmts = array_merge([$constructorClassMethod], $node->stmts); - - return $node; - } - - private function createParentConstructorCall(): StaticCall - { - $staticClassConstFetch = new ClassConstFetch(new Name('static'), 'class'); - - return new StaticCall(new Name('parent'), MethodName::CONSTRUCT, [new Arg($staticClassConstFetch)]); - } - - private function shouldSkipClass(Class_ $class): bool - { - if ($class->isAbstract()) { - return true; - } - - if ($class->isAnonymous()) { - return true; - } - - $className = $this->getName($class); - - // loaded automatically by PHPUnit - if (str_ends_with((string) $className, 'Test')) { - return true; - } - - return str_ends_with((string) $className, 'TestCase'); - } -}