From 225a632df11778ee078d7e1264a4a352317363b5 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 20 May 2025 17:07:35 +0700 Subject: [PATCH] [PHPUnit 10] Drop ParentTestClassConstructorRector --- config/sets/phpunit100.php | 2 - .../Fixture/mocking_helper.php.inc | 27 ---- .../Fixture/skip_abstract_classes.php.inc | 9 -- .../Fixture/skip_already_added.php.inc | 13 -- .../Fixture/skip_in_case_of_test.php.inc | 9 -- .../Fixture/skip_in_case_of_test_case.php.inc | 9 -- .../ParentTestClassConstructorRectorTest.php | 28 ---- .../config/configured_rule.php | 10 -- .../ParentTestClassConstructorRector.php | 124 ------------------ 9 files changed, 231 deletions(-) delete mode 100644 rules-tests/PHPUnit100/Rector/Class_/ParentTestClassConstructorRector/Fixture/mocking_helper.php.inc delete mode 100644 rules-tests/PHPUnit100/Rector/Class_/ParentTestClassConstructorRector/Fixture/skip_abstract_classes.php.inc delete mode 100644 rules-tests/PHPUnit100/Rector/Class_/ParentTestClassConstructorRector/Fixture/skip_already_added.php.inc delete mode 100644 rules-tests/PHPUnit100/Rector/Class_/ParentTestClassConstructorRector/Fixture/skip_in_case_of_test.php.inc delete mode 100644 rules-tests/PHPUnit100/Rector/Class_/ParentTestClassConstructorRector/Fixture/skip_in_case_of_test_case.php.inc delete mode 100644 rules-tests/PHPUnit100/Rector/Class_/ParentTestClassConstructorRector/ParentTestClassConstructorRectorTest.php delete mode 100644 rules-tests/PHPUnit100/Rector/Class_/ParentTestClassConstructorRector/config/configured_rule.php delete mode 100644 rules/PHPUnit100/Rector/Class_/ParentTestClassConstructorRector.php 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'); - } -}