diff --git a/docs/rector_rules_overview.md b/docs/rector_rules_overview.md index 63abea1ce6a9..aab21c99de70 100644 --- a/docs/rector_rules_overview.md +++ b/docs/rector_rules_overview.md @@ -13965,7 +13965,7 @@ return static function (ContainerConfigurator $containerConfigurator): void { $services->set(InferParamFromClassMethodReturnRector::class) ->call('configure', [[ - InferParamFromClassMethodReturnRector::INFER_PARAMS_FROM_CLASS_METHOD_RETURNS => ValueObjectInliner::inline([ + InferParamFromClassMethodReturnRector::PARAM_FROM_CLASS_METHOD_RETURNS => ValueObjectInliner::inline([ new InferParamFromClassMethodReturn('SomeClass', 'process', 'getNodeTypes'), ]), ]]); diff --git a/packages/testing/src/PHPUnit/AbstractRectorTestCase.php b/packages/testing/src/PHPUnit/AbstractRectorTestCase.php index 85e88d83dee8..dbf50897753a 100644 --- a/packages/testing/src/PHPUnit/AbstractRectorTestCase.php +++ b/packages/testing/src/PHPUnit/AbstractRectorTestCase.php @@ -101,11 +101,6 @@ abstract class AbstractRectorTestCase extends AbstractKernelTestCase */ private $autoloadTestFixture = true; - /** - * @var mixed[] - */ - private $oldParameterValues = []; - /** * @var BetterStandardPrinter */ @@ -167,18 +162,6 @@ protected function setUp(): void $this->nodeScopeResolver = $this->getService(NodeScopeResolver::class); $this->configurePhpVersionFeatures(); - - $this->oldParameterValues = []; - } - - protected function tearDown(): void - { - $this->restoreOldParameterValues(); - - // restore PHP version if changed - if ($this->getPhpVersion() !== self::PHP_VERSION_UNDEFINED) { - $this->setParameter(Option::PHP_VERSION_FEATURES, PhpVersion::PHP_10); - } } protected function getRectorClass(): string @@ -211,25 +194,10 @@ protected function yieldFilesFromDirectory(string $directory, string $suffix = ' return StaticFixtureFinder::yieldDirectory($directory, $suffix); } - /** - * @param mixed $value - */ - protected function setParameter(string $name, $value): void - { - $parameterProvider = $this->getService(ParameterProvider::class); - - if ($name !== Option::PHP_VERSION_FEATURES) { - $oldParameterValue = $parameterProvider->provideParameter($name); - $this->oldParameterValues[$name] = $oldParameterValue; - } - - $parameterProvider->changeParameter($name, $value); - } - protected function getPhpVersion(): int { - // to be implemented - return self::PHP_VERSION_UNDEFINED; + // default value to be implemented for testing lower versions + return PhpVersion::PHP_10; } protected function doTestFileInfoWithoutAutoload(SmartFileInfo $fileInfo): void @@ -379,20 +347,7 @@ private function configurePhpVersionFeatures(): void return; } - $this->setParameter(Option::PHP_VERSION_FEATURES, $this->getPhpVersion()); - } - - private function restoreOldParameterValues(): void - { - if ($this->oldParameterValues === []) { - return; - } - - $parameterProvider = $this->getService(ParameterProvider::class); - - foreach ($this->oldParameterValues as $name => $oldParameterValue) { - $parameterProvider->changeParameter($name, $oldParameterValue); - } + $this->parameterProvider->changeParameter(Option::PHP_VERSION_FEATURES, $this->getPhpVersion()); } private function ensureRectorClassIsValid(string $rectorClass, string $methodName): void @@ -418,7 +373,7 @@ private function doTestFileMatchesExpectedContent( SmartFileInfo $fixtureFileInfo, array $extraFiles = [] ): void { - $this->setParameter(Option::SOURCE, [$originalFileInfo->getRealPath()]); + $this->parameterProvider->changeParameter(Option::SOURCE, [$originalFileInfo->getRealPath()]); if (! Strings::endsWith($originalFileInfo->getFilename(), '.blade.php') && in_array( $originalFileInfo->getSuffix(), diff --git a/rector.php b/rector.php index e56dcd9dbc6b..708b70a99036 100644 --- a/rector.php +++ b/rector.php @@ -25,7 +25,7 @@ ]); $services->set(InferParamFromClassMethodReturnRector::class) ->call('configure', [[ - InferParamFromClassMethodReturnRector::INFER_PARAMS_FROM_CLASS_METHOD_RETURNS => $configuration, + InferParamFromClassMethodReturnRector::PARAM_FROM_CLASS_METHOD_RETURNS => $configuration, ]]); $services->set(PreferThisOrSelfMethodCallRector::class) diff --git a/rules/code-quality/tests/Rector/Return_/SimplifyUselessVariableRector/SimplifyUselessVariableRectorTest.php b/rules/code-quality/tests/Rector/Return_/SimplifyUselessVariableRector/SimplifyUselessVariableRectorTest.php index d887481d5ca9..56e997451d05 100644 --- a/rules/code-quality/tests/Rector/Return_/SimplifyUselessVariableRector/SimplifyUselessVariableRectorTest.php +++ b/rules/code-quality/tests/Rector/Return_/SimplifyUselessVariableRector/SimplifyUselessVariableRectorTest.php @@ -6,7 +6,6 @@ use Iterator; use Rector\CodeQuality\Rector\Return_\SimplifyUselessVariableRector; -use Rector\Core\Configuration\Option; use Rector\Testing\PHPUnit\AbstractRectorTestCase; use Symplify\SmartFileSystem\SmartFileInfo; @@ -22,8 +21,6 @@ final class SimplifyUselessVariableRectorTest extends AbstractRectorTestCase */ public function test(SmartFileInfo $fileInfo): void { - $this->setParameter(Option::AUTO_IMPORT_NAMES, true); - $this->doTestFileInfo($fileInfo); } diff --git a/rules/coding-style/tests/Rector/FuncCall/PreslashSimpleFunctionRector/AutoImportTest.php b/rules/coding-style/tests/Rector/FuncCall/PreslashSimpleFunctionRector/AutoImportTest.php index c7f928e88bed..03975b9c9257 100644 --- a/rules/coding-style/tests/Rector/FuncCall/PreslashSimpleFunctionRector/AutoImportTest.php +++ b/rules/coding-style/tests/Rector/FuncCall/PreslashSimpleFunctionRector/AutoImportTest.php @@ -5,8 +5,6 @@ namespace Rector\CodingStyle\Tests\Rector\FuncCall\PreslashSimpleFunctionRector; use Iterator; -use Rector\CodingStyle\Rector\FuncCall\PreslashSimpleFunctionRector; -use Rector\Core\Configuration\Option; use Rector\Testing\PHPUnit\AbstractRectorTestCase; use Symplify\SmartFileSystem\SmartFileInfo; @@ -17,7 +15,6 @@ final class AutoImportTest extends AbstractRectorTestCase */ public function test(SmartFileInfo $fileInfo): void { - $this->setParameter(Option::AUTO_IMPORT_NAMES, true); $this->doTestFileInfo($fileInfo); } @@ -26,8 +23,8 @@ public function provideData(): Iterator return $this->yieldFilesFromDirectory(__DIR__ . '/FixtureAutoImport'); } - protected function getRectorClass(): string + protected function provideConfigFileInfo(): ?SmartFileInfo { - return PreslashSimpleFunctionRector::class; + return new SmartFileInfo(__DIR__ . '/config/auto_import.php'); } } diff --git a/rules/coding-style/tests/Rector/FuncCall/PreslashSimpleFunctionRector/config/auto_import.php b/rules/coding-style/tests/Rector/FuncCall/PreslashSimpleFunctionRector/config/auto_import.php new file mode 100644 index 000000000000..666870f1a704 --- /dev/null +++ b/rules/coding-style/tests/Rector/FuncCall/PreslashSimpleFunctionRector/config/auto_import.php @@ -0,0 +1,15 @@ +parameters(); + $parameters->set(Option::AUTO_IMPORT_NAMES, true); + + $services = $containerConfigurator->services(); + $services->set(PreslashSimpleFunctionRector::class); +}; diff --git a/rules/coding-style/tests/Rector/Namespace_/ImportFullyQualifiedNamesRector/DocBlockRectorTest.php b/rules/coding-style/tests/Rector/Namespace_/ImportFullyQualifiedNamesRector/DocBlockRectorTest.php index 67b9bcf7be6b..30e0c4551846 100644 --- a/rules/coding-style/tests/Rector/Namespace_/ImportFullyQualifiedNamesRector/DocBlockRectorTest.php +++ b/rules/coding-style/tests/Rector/Namespace_/ImportFullyQualifiedNamesRector/DocBlockRectorTest.php @@ -5,8 +5,6 @@ namespace Rector\CodingStyle\Tests\Rector\Namespace_\ImportFullyQualifiedNamesRector; use Iterator; -use Rector\Core\Configuration\Option; -use Rector\Renaming\Rector\Name\RenameClassRector; use Rector\Testing\PHPUnit\AbstractRectorTestCase; use Symplify\SmartFileSystem\SmartFileInfo; @@ -20,9 +18,6 @@ final class DocBlockRectorTest extends AbstractRectorTestCase */ public function test(SmartFileInfo $fileInfo): void { - $this->setParameter(Option::AUTO_IMPORT_NAMES, true); - $this->setParameter(Option::IMPORT_DOC_BLOCKS, true); - $this->doTestFileInfo($fileInfo); } @@ -31,9 +26,8 @@ public function provideData(): Iterator return $this->yieldFilesFromDirectory(__DIR__ . '/FixtureDocBlock'); } - protected function getRectorClass(): string + protected function provideConfigFileInfo(): ?SmartFileInfo { - // here can be any Rector rule, as we're testing \Rector\PostRector\Rector\NameImportingPostRector in the full Retcor life cycle - return RenameClassRector::class; + return new SmartFileInfo(__DIR__ . '/config/import_doc_block_config.php'); } } diff --git a/rules/coding-style/tests/Rector/Namespace_/ImportFullyQualifiedNamesRector/ImportRootNamespaceClassesDisabledTest.php b/rules/coding-style/tests/Rector/Namespace_/ImportFullyQualifiedNamesRector/ImportRootNamespaceClassesDisabledTest.php index b647774142d4..210fa394477d 100644 --- a/rules/coding-style/tests/Rector/Namespace_/ImportFullyQualifiedNamesRector/ImportRootNamespaceClassesDisabledTest.php +++ b/rules/coding-style/tests/Rector/Namespace_/ImportFullyQualifiedNamesRector/ImportRootNamespaceClassesDisabledTest.php @@ -5,8 +5,6 @@ namespace Rector\CodingStyle\Tests\Rector\Namespace_\ImportFullyQualifiedNamesRector; use Iterator; -use Rector\Core\Configuration\Option; -use Rector\Renaming\Rector\Name\RenameClassRector; use Rector\Testing\PHPUnit\AbstractRectorTestCase; use Symplify\SmartFileSystem\SmartFileInfo; @@ -20,9 +18,6 @@ final class ImportRootNamespaceClassesDisabledTest extends AbstractRectorTestCas */ public function test(SmartFileInfo $fileInfo): void { - $this->setParameter(Option::AUTO_IMPORT_NAMES, true); - $this->setParameter(Option::IMPORT_SHORT_CLASSES, false); - $this->doTestFileInfo($fileInfo); } @@ -34,9 +29,8 @@ public function provideData(): iterable return $this->yieldFilesFromDirectory(__DIR__ . '/FixtureRoot'); } - protected function getRectorClass(): string + protected function provideConfigFileInfo(): ?SmartFileInfo { - // the must be any rector class to run - return RenameClassRector::class; + return new SmartFileInfo(__DIR__ . '/config/not_import_short_classes.php'); } } diff --git a/rules/coding-style/tests/Rector/Namespace_/ImportFullyQualifiedNamesRector/config/import_doc_block_config.php b/rules/coding-style/tests/Rector/Namespace_/ImportFullyQualifiedNamesRector/config/import_doc_block_config.php new file mode 100644 index 000000000000..d0180bcfa94e --- /dev/null +++ b/rules/coding-style/tests/Rector/Namespace_/ImportFullyQualifiedNamesRector/config/import_doc_block_config.php @@ -0,0 +1,16 @@ +parameters(); + $parameters->set(Option::AUTO_IMPORT_NAMES, true); + $parameters->set(Option::IMPORT_DOC_BLOCKS, true); + + $services = $containerConfigurator->services(); + $services->set(RenameClassRector::class); +}; diff --git a/rules/coding-style/tests/Rector/Namespace_/ImportFullyQualifiedNamesRector/config/not_import_short_classes.php b/rules/coding-style/tests/Rector/Namespace_/ImportFullyQualifiedNamesRector/config/not_import_short_classes.php new file mode 100644 index 000000000000..94f2fe001874 --- /dev/null +++ b/rules/coding-style/tests/Rector/Namespace_/ImportFullyQualifiedNamesRector/config/not_import_short_classes.php @@ -0,0 +1,16 @@ +parameters(); + $parameters->set(Option::AUTO_IMPORT_NAMES, true); + $parameters->set(Option::IMPORT_SHORT_CLASSES, false); + + $services = $containerConfigurator->services(); + $services->set(RenameClassRector::class); +}; diff --git a/rules/dead-code/tests/Rector/ClassConst/RemoveUnusedClassConstantRector/OpenSourceRectorTest.php b/rules/dead-code/tests/Rector/ClassConst/RemoveUnusedClassConstantRector/OpenSourceRectorTest.php index 18687ebb5a6f..3ff9e73c901a 100644 --- a/rules/dead-code/tests/Rector/ClassConst/RemoveUnusedClassConstantRector/OpenSourceRectorTest.php +++ b/rules/dead-code/tests/Rector/ClassConst/RemoveUnusedClassConstantRector/OpenSourceRectorTest.php @@ -5,9 +5,6 @@ namespace Rector\DeadCode\Tests\Rector\ClassConst\RemoveUnusedClassConstantRector; use Iterator; -use Rector\Core\Configuration\Option; -use Rector\Core\ValueObject\ProjectType; -use Rector\DeadCode\Rector\ClassConst\RemoveUnusedClassConstantRector; use Rector\Testing\PHPUnit\AbstractRectorTestCase; use Symplify\SmartFileSystem\SmartFileInfo; @@ -18,7 +15,6 @@ final class OpenSourceRectorTest extends AbstractRectorTestCase */ public function test(SmartFileInfo $fileInfo): void { - $this->setParameter(Option::PROJECT_TYPE, ProjectType::OPEN_SOURCE); $this->doTestFileInfo($fileInfo); } @@ -27,8 +23,8 @@ public function provideData(): Iterator return $this->yieldFilesFromDirectory(__DIR__ . '/FixtureOpenSource'); } - protected function getRectorClass(): string + protected function provideConfigFileInfo(): ?SmartFileInfo { - return RemoveUnusedClassConstantRector::class; + return new SmartFileInfo(__DIR__ . '/config/project_open_source.php'); } } diff --git a/rules/dead-code/tests/Rector/ClassConst/RemoveUnusedClassConstantRector/config/project_open_source.php b/rules/dead-code/tests/Rector/ClassConst/RemoveUnusedClassConstantRector/config/project_open_source.php new file mode 100644 index 000000000000..2ca82792651e --- /dev/null +++ b/rules/dead-code/tests/Rector/ClassConst/RemoveUnusedClassConstantRector/config/project_open_source.php @@ -0,0 +1,16 @@ +parameters(); + $parameters->set(Option::PROJECT_TYPE, ProjectType::OPEN_SOURCE); + + $services = $containerConfigurator->services(); + $services->set(RemoveUnusedClassConstantRector::class); +}; diff --git a/rules/dead-code/tests/Rector/ClassMethod/RemoveUnusedParameterRector/OpenSourceRectorTest.php b/rules/dead-code/tests/Rector/ClassMethod/RemoveUnusedParameterRector/OpenSourceRectorTest.php index d5fab14b2030..44544cc1429e 100644 --- a/rules/dead-code/tests/Rector/ClassMethod/RemoveUnusedParameterRector/OpenSourceRectorTest.php +++ b/rules/dead-code/tests/Rector/ClassMethod/RemoveUnusedParameterRector/OpenSourceRectorTest.php @@ -5,9 +5,6 @@ namespace Rector\DeadCode\Tests\Rector\ClassMethod\RemoveUnusedParameterRector; use Iterator; -use Rector\Core\Configuration\Option; -use Rector\Core\ValueObject\ProjectType; -use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedParameterRector; use Rector\Testing\PHPUnit\AbstractRectorTestCase; use Symplify\SmartFileSystem\SmartFileInfo; @@ -18,7 +15,6 @@ final class OpenSourceRectorTest extends AbstractRectorTestCase */ public function test(SmartFileInfo $fileInfo): void { - $this->setParameter(Option::PROJECT_TYPE, ProjectType::OPEN_SOURCE); $this->doTestFileInfo($fileInfo); } @@ -27,8 +23,8 @@ public function provideData(): Iterator return $this->yieldFilesFromDirectory(__DIR__ . '/FixtureOpenSource'); } - protected function getRectorClass(): string + protected function provideConfigFileInfo(): ?SmartFileInfo { - return RemoveUnusedParameterRector::class; + return new SmartFileInfo(__DIR__ . '/config/project_open_source.php'); } } diff --git a/rules/dead-code/tests/Rector/ClassMethod/RemoveUnusedParameterRector/config/project_open_source.php b/rules/dead-code/tests/Rector/ClassMethod/RemoveUnusedParameterRector/config/project_open_source.php new file mode 100644 index 000000000000..975d77ff235e --- /dev/null +++ b/rules/dead-code/tests/Rector/ClassMethod/RemoveUnusedParameterRector/config/project_open_source.php @@ -0,0 +1,16 @@ +parameters(); + $parameters->set(Option::PROJECT_TYPE, ProjectType::OPEN_SOURCE); + + $services = $containerConfigurator->services(); + $services->set(RemoveUnusedParameterRector::class); +}; diff --git a/rules/dead-code/tests/Rector/ClassMethod/RemoveUnusedPublicMethodRector/OpenSourceRectorTest.php b/rules/dead-code/tests/Rector/ClassMethod/RemoveUnusedPublicMethodRector/OpenSourceRectorTest.php index 439bf7834684..2120dffbac17 100644 --- a/rules/dead-code/tests/Rector/ClassMethod/RemoveUnusedPublicMethodRector/OpenSourceRectorTest.php +++ b/rules/dead-code/tests/Rector/ClassMethod/RemoveUnusedPublicMethodRector/OpenSourceRectorTest.php @@ -5,9 +5,6 @@ namespace Rector\DeadCode\Tests\Rector\ClassMethod\RemoveUnusedPublicMethodRector; use Iterator; -use Rector\Core\Configuration\Option; -use Rector\Core\ValueObject\ProjectType; -use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPublicMethodRector; use Rector\Testing\PHPUnit\AbstractRectorTestCase; use Symplify\SmartFileSystem\SmartFileInfo; @@ -18,7 +15,6 @@ final class OpenSourceRectorTest extends AbstractRectorTestCase */ public function test(SmartFileInfo $fileInfo): void { - $this->setParameter(Option::PROJECT_TYPE, ProjectType::OPEN_SOURCE); $this->doTestFileInfo($fileInfo); } @@ -27,8 +23,8 @@ public function provideData(): Iterator return $this->yieldFilesFromDirectory(__DIR__ . '/FixtureOpenSource'); } - protected function getRectorClass(): string + protected function provideConfigFileInfo(): ?SmartFileInfo { - return RemoveUnusedPublicMethodRector::class; + return new SmartFileInfo(__DIR__ . '/config/projet_open_source.php'); } } diff --git a/rules/dead-code/tests/Rector/ClassMethod/RemoveUnusedPublicMethodRector/config/projet_open_source.php b/rules/dead-code/tests/Rector/ClassMethod/RemoveUnusedPublicMethodRector/config/projet_open_source.php new file mode 100644 index 000000000000..10e314d7b9c5 --- /dev/null +++ b/rules/dead-code/tests/Rector/ClassMethod/RemoveUnusedPublicMethodRector/config/projet_open_source.php @@ -0,0 +1,16 @@ +parameters(); + $parameters->set(Option::PROJECT_TYPE, ProjectType::OPEN_SOURCE); + + $services = $containerConfigurator->services(); + $services->set(RemoveUnusedPublicMethodRector::class); +}; diff --git a/rules/generic/tests/Rector/Property/InjectAnnotationClassRector/InjectAnnotationClassRectorTest.php b/rules/generic/tests/Rector/Property/InjectAnnotationClassRector/InjectAnnotationClassRectorTest.php index 47c09b84f6f5..66488e150859 100644 --- a/rules/generic/tests/Rector/Property/InjectAnnotationClassRector/InjectAnnotationClassRectorTest.php +++ b/rules/generic/tests/Rector/Property/InjectAnnotationClassRector/InjectAnnotationClassRectorTest.php @@ -5,7 +5,6 @@ namespace Rector\Generic\Tests\Rector\Property\InjectAnnotationClassRector; use Iterator; -use Rector\Core\Configuration\Option; use Rector\Testing\PHPUnit\AbstractRectorTestCase; use Symplify\SmartFileSystem\SmartFileInfo; @@ -16,11 +15,6 @@ final class InjectAnnotationClassRectorTest extends AbstractRectorTestCase */ public function test(SmartFileInfo $fileInfo): void { - $this->setParameter( - Option::SYMFONY_CONTAINER_XML_PATH_PARAMETER, - __DIR__ . '/../../../../../symfony/tests/Rector/MethodCall/GetToConstructorInjectionRector/xml/services.xml' - ); - $this->doTestFileInfo($fileInfo); } diff --git a/rules/generic/tests/Rector/Property/InjectAnnotationClassRector/config/configured_rule.php b/rules/generic/tests/Rector/Property/InjectAnnotationClassRector/config/configured_rule.php index f8a076da9ed6..fe92bacf6042 100644 --- a/rules/generic/tests/Rector/Property/InjectAnnotationClassRector/config/configured_rule.php +++ b/rules/generic/tests/Rector/Property/InjectAnnotationClassRector/config/configured_rule.php @@ -1,12 +1,20 @@ parameters(); + $parameters->set( + Option::SYMFONY_CONTAINER_XML_PATH_PARAMETER, + __DIR__ . '/../../../../../../symfony/tests/Rector/MethodCall/GetToConstructorInjectionRector/xml/services.xml' + ); + $services = $containerConfigurator->services(); - $services->set(InjectAnnotationClassRector::class)->call('configure', [[ - InjectAnnotationClassRector::ANNOTATION_CLASSES => [Inject::class, \DI\Annotation\Inject::class], - ]]); + $services->set(InjectAnnotationClassRector::class) + ->call('configure', [[ + InjectAnnotationClassRector::ANNOTATION_CLASSES => [Inject::class, \DI\Annotation\Inject::class], + ]]); }; diff --git a/rules/nette-code-quality/tests/Rector/Assign/MakeGetComponentAssignAnnotatedRector/AutoImportTest.php b/rules/nette-code-quality/tests/Rector/Assign/MakeGetComponentAssignAnnotatedRector/AutoImportTest.php index d74fc5cf22e8..472258dd6442 100644 --- a/rules/nette-code-quality/tests/Rector/Assign/MakeGetComponentAssignAnnotatedRector/AutoImportTest.php +++ b/rules/nette-code-quality/tests/Rector/Assign/MakeGetComponentAssignAnnotatedRector/AutoImportTest.php @@ -5,8 +5,6 @@ namespace Rector\NetteCodeQuality\Tests\Rector\Assign\MakeGetComponentAssignAnnotatedRector; use Iterator; -use Rector\Core\Configuration\Option; -use Rector\NetteCodeQuality\Rector\Assign\MakeGetComponentAssignAnnotatedRector; use Rector\Testing\PHPUnit\AbstractRectorTestCase; use Symplify\SmartFileSystem\SmartFileInfo; @@ -17,8 +15,6 @@ final class AutoImportTest extends AbstractRectorTestCase */ public function test(SmartFileInfo $fileInfo): void { - $this->setParameter(Option::AUTO_IMPORT_NAMES, true); - $this->setParameter(Option::IMPORT_DOC_BLOCKS, true); $this->doTestFileInfo($fileInfo); } @@ -27,8 +23,8 @@ public function provideData(): Iterator return $this->yieldFilesFromDirectory(__DIR__ . '/FixtureAutoImport'); } - protected function getRectorClass(): string + protected function provideConfigFileInfo(): ?SmartFileInfo { - return MakeGetComponentAssignAnnotatedRector::class; + return new SmartFileInfo(__DIR__ . '/config/auto_import.php'); } } diff --git a/rules/nette-code-quality/tests/Rector/Assign/MakeGetComponentAssignAnnotatedRector/config/auto_import.php b/rules/nette-code-quality/tests/Rector/Assign/MakeGetComponentAssignAnnotatedRector/config/auto_import.php new file mode 100644 index 000000000000..5fdc1b82340d --- /dev/null +++ b/rules/nette-code-quality/tests/Rector/Assign/MakeGetComponentAssignAnnotatedRector/config/auto_import.php @@ -0,0 +1,16 @@ +parameters(); + $parameters->set(Option::AUTO_IMPORT_NAMES, true); + $parameters->set(Option::IMPORT_DOC_BLOCKS, true); + + $services = $containerConfigurator->services(); + $services->set(MakeGetComponentAssignAnnotatedRector::class); +}; diff --git a/rules/php55/tests/Rector/String_/StringClassNameToClassConstantRector/ImportClassNameRectorTest.php b/rules/php55/tests/Rector/String_/StringClassNameToClassConstantRector/ImportClassNameRectorTest.php index a99c1423e0c7..27e8633b44eb 100644 --- a/rules/php55/tests/Rector/String_/StringClassNameToClassConstantRector/ImportClassNameRectorTest.php +++ b/rules/php55/tests/Rector/String_/StringClassNameToClassConstantRector/ImportClassNameRectorTest.php @@ -5,8 +5,6 @@ namespace Rector\Php55\Tests\Rector\String_\StringClassNameToClassConstantRector; use Iterator; -use Rector\Core\Configuration\Option; -use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector; use Rector\Testing\PHPUnit\AbstractRectorTestCase; use Symplify\SmartFileSystem\SmartFileInfo; @@ -17,8 +15,6 @@ final class ImportClassNameRectorTest extends AbstractRectorTestCase */ public function test(SmartFileInfo $fileInfo): void { - $this->setParameter(Option::AUTO_IMPORT_NAMES, true); - $this->doTestFileInfo($fileInfo); } @@ -27,8 +23,8 @@ public function provideData(): Iterator return $this->yieldFilesFromDirectory(__DIR__ . '/FixtureImport'); } - protected function getRectorClass(): string + protected function provideConfigFileInfo(): ?SmartFileInfo { - return StringClassNameToClassConstantRector::class; + return new SmartFileInfo(__DIR__ . '/config/import_config.php'); } } diff --git a/rules/php55/tests/Rector/String_/StringClassNameToClassConstantRector/config/import_config.php b/rules/php55/tests/Rector/String_/StringClassNameToClassConstantRector/config/import_config.php new file mode 100644 index 000000000000..13607493f0d3 --- /dev/null +++ b/rules/php55/tests/Rector/String_/StringClassNameToClassConstantRector/config/import_config.php @@ -0,0 +1,15 @@ +parameters(); + $parameters->set(Option::AUTO_IMPORT_NAMES, true); + + $services = $containerConfigurator->services(); + $services->set(StringClassNameToClassConstantRector::class); +}; diff --git a/rules/php72/tests/Rector/FuncCall/GetClassOnNullRector/PostImportTest.php b/rules/php72/tests/Rector/FuncCall/GetClassOnNullRector/PostImportTest.php index bccf2d7ad39b..7154cec28073 100644 --- a/rules/php72/tests/Rector/FuncCall/GetClassOnNullRector/PostImportTest.php +++ b/rules/php72/tests/Rector/FuncCall/GetClassOnNullRector/PostImportTest.php @@ -5,8 +5,6 @@ namespace Rector\Php72\Tests\Rector\FuncCall\GetClassOnNullRector; use Iterator; -use Rector\Core\Configuration\Option; -use Rector\Php72\Rector\FuncCall\GetClassOnNullRector; use Rector\Testing\PHPUnit\AbstractRectorTestCase; use Symplify\SmartFileSystem\SmartFileInfo; @@ -17,7 +15,6 @@ final class PostImportTest extends AbstractRectorTestCase */ public function test(SmartFileInfo $fileInfo): void { - $this->setParameter(Option::AUTO_IMPORT_NAMES, true); $this->doTestFileInfo($fileInfo); } @@ -26,8 +23,8 @@ public function provideData(): Iterator return $this->yieldFilesFromDirectory(__DIR__ . '/FixturePostImport'); } - protected function getRectorClass(): string + protected function provideConfigFileInfo(): ?SmartFileInfo { - return GetClassOnNullRector::class; + return new SmartFileInfo(__DIR__ . '/config/auto_import.php'); } } diff --git a/rules/php72/tests/Rector/FuncCall/GetClassOnNullRector/config/auto_import.php b/rules/php72/tests/Rector/FuncCall/GetClassOnNullRector/config/auto_import.php new file mode 100644 index 000000000000..c22bb6872366 --- /dev/null +++ b/rules/php72/tests/Rector/FuncCall/GetClassOnNullRector/config/auto_import.php @@ -0,0 +1,14 @@ +parameters(); + $parameters->set(Option::AUTO_IMPORT_NAMES, true); + + $services = $containerConfigurator->services(); + $services->set(\Rector\Php72\Rector\FuncCall\GetClassOnNullRector::class); +}; diff --git a/rules/php74/tests/Rector/Property/TypedPropertyRector/ImportedTest.php b/rules/php74/tests/Rector/Property/TypedPropertyRector/ImportedTest.php index c7835f271045..c87a4b85411d 100644 --- a/rules/php74/tests/Rector/Property/TypedPropertyRector/ImportedTest.php +++ b/rules/php74/tests/Rector/Property/TypedPropertyRector/ImportedTest.php @@ -5,8 +5,6 @@ namespace Rector\Php74\Tests\Rector\Property\TypedPropertyRector; use Iterator; -use Rector\Core\Configuration\Option; -use Rector\Php74\Rector\Property\TypedPropertyRector; use Rector\Testing\PHPUnit\AbstractRectorTestCase; use Symplify\SmartFileSystem\SmartFileInfo; @@ -17,7 +15,6 @@ final class ImportedTest extends AbstractRectorTestCase */ public function test(SmartFileInfo $fileInfo): void { - $this->setParameter(Option::AUTO_IMPORT_NAMES, true); $this->doTestFileInfo($fileInfo); } @@ -26,8 +23,8 @@ public function provideData(): Iterator return $this->yieldFilesFromDirectory(__DIR__ . '/FixtureImported'); } - protected function getRectorClass(): string + protected function provideConfigFileInfo(): ?SmartFileInfo { - return TypedPropertyRector::class; + return new SmartFileInfo(__DIR__ . '/config/imported_type.php'); } } diff --git a/rules/php74/tests/Rector/Property/TypedPropertyRector/config/imported_type.php b/rules/php74/tests/Rector/Property/TypedPropertyRector/config/imported_type.php new file mode 100644 index 000000000000..928da90c566e --- /dev/null +++ b/rules/php74/tests/Rector/Property/TypedPropertyRector/config/imported_type.php @@ -0,0 +1,18 @@ +parameters(); + $parameters->set(Option::AUTO_IMPORT_NAMES, true); + + $services = $containerConfigurator->services(); + $services->set(TypedPropertyRector::class) + ->call('configure', [[ + TypedPropertyRector::CLASS_LIKE_TYPE_ONLY => true, + ]]); +}; diff --git a/rules/php80/tests/Rector/Class_/AnnotationToAttributeRector/AutoImportedAnnotationToAttributeRectorTest.php b/rules/php80/tests/Rector/Class_/AnnotationToAttributeRector/AutoImportedAnnotationToAttributeRectorTest.php index 040e2089a20b..a8394b43fbbb 100644 --- a/rules/php80/tests/Rector/Class_/AnnotationToAttributeRector/AutoImportedAnnotationToAttributeRectorTest.php +++ b/rules/php80/tests/Rector/Class_/AnnotationToAttributeRector/AutoImportedAnnotationToAttributeRectorTest.php @@ -5,8 +5,6 @@ namespace Rector\Php80\Tests\Rector\Class_\AnnotationToAttributeRector; use Iterator; -use Rector\Core\Configuration\Option; -use Rector\Php80\Rector\Class_\AnnotationToAttributeRector; use Rector\Testing\PHPUnit\AbstractRectorTestCase; use Symplify\SmartFileSystem\SmartFileInfo; @@ -17,7 +15,6 @@ final class AutoImportedAnnotationToAttributeRectorTest extends AbstractRectorTe */ public function test(SmartFileInfo $fileInfo): void { - $this->setParameter(Option::AUTO_IMPORT_NAMES, true); $this->doTestFileInfo($fileInfo); } @@ -26,8 +23,8 @@ public function provideData(): Iterator return $this->yieldFilesFromDirectory(__DIR__ . '/FixtureAutoImported'); } - protected function getRectorClass(): string + protected function provideConfigFileInfo(): ?SmartFileInfo { - return AnnotationToAttributeRector::class; + return new SmartFileInfo(__DIR__ . '/config/auto_import.php'); } } diff --git a/rules/php80/tests/Rector/Class_/AnnotationToAttributeRector/config/auto_import.php b/rules/php80/tests/Rector/Class_/AnnotationToAttributeRector/config/auto_import.php new file mode 100644 index 000000000000..0fe7ae535838 --- /dev/null +++ b/rules/php80/tests/Rector/Class_/AnnotationToAttributeRector/config/auto_import.php @@ -0,0 +1,15 @@ +parameters(); + $parameters->set(Option::AUTO_IMPORT_NAMES, true); + + $services = $containerConfigurator->services(); + $services->set(AnnotationToAttributeRector::class); +}; diff --git a/rules/renaming/tests/Rector/Name/RenameClassRector/FixtureAutoImportNamesFunction/double_funciton_import.php.inc b/rules/renaming/tests/Rector/Name/RenameClassRector/FixtureAutoImportNamesFunction/double_funciton_import.php.inc deleted file mode 100644 index 313e65e51fcd..000000000000 --- a/rules/renaming/tests/Rector/Name/RenameClassRector/FixtureAutoImportNamesFunction/double_funciton_import.php.inc +++ /dev/null @@ -1,38 +0,0 @@ - ------ - diff --git a/rules/renaming/tests/Rector/Name/RenameClassRector/FunctionAutoImportNamesParameterTest.php b/rules/renaming/tests/Rector/Name/RenameClassRector/FunctionAutoImportNamesParameterTest.php deleted file mode 100644 index 95130c1de740..000000000000 --- a/rules/renaming/tests/Rector/Name/RenameClassRector/FunctionAutoImportNamesParameterTest.php +++ /dev/null @@ -1,36 +0,0 @@ -setParameter(Option::AUTO_IMPORT_NAMES, true); - - $this->doTestFileInfo($fileInfo); - } - - public function provideData(): Iterator - { - return $this->yieldFilesFromDirectory(__DIR__ . '/FixtureAutoImportNamesFunction'); - } - - protected function provideConfigFileInfo(): ?SmartFileInfo - { - return new SmartFileInfo(__DIR__ . '/config/configured_rule.php'); - } -} diff --git a/rules/renaming/tests/Rector/Name/RenameClassRector/config/auto_import_names.php b/rules/renaming/tests/Rector/Name/RenameClassRector/config/auto_import_names.php index 70cd044223ac..cbda9d1c48ba 100644 --- a/rules/renaming/tests/Rector/Name/RenameClassRector/config/auto_import_names.php +++ b/rules/renaming/tests/Rector/Name/RenameClassRector/config/auto_import_names.php @@ -15,7 +15,6 @@ $parameters->set(Option::AUTO_IMPORT_NAMES, true); $services = $containerConfigurator->services(); - $services->set(SimplifyEmptyArrayCheckRector::class); $services->set(RenameClassRector::class) diff --git a/rules/restoration/src/Rector/ClassMethod/InferParamFromClassMethodReturnRector.php b/rules/restoration/src/Rector/ClassMethod/InferParamFromClassMethodReturnRector.php index f4b012ba786c..2dbd4a0045aa 100644 --- a/rules/restoration/src/Rector/ClassMethod/InferParamFromClassMethodReturnRector.php +++ b/rules/restoration/src/Rector/ClassMethod/InferParamFromClassMethodReturnRector.php @@ -31,7 +31,7 @@ final class InferParamFromClassMethodReturnRector extends AbstractRector impleme /** * @var string */ - public const INFER_PARAMS_FROM_CLASS_METHOD_RETURNS = 'infer_params_from_class_method_returns'; + public const PARAM_FROM_CLASS_METHOD_RETURNS = 'param_from_class_method_returns'; /** * @var InferParamFromClassMethodReturn[] @@ -99,7 +99,7 @@ public function process(Node $node) CODE_SAMPLE , [ - self::INFER_PARAMS_FROM_CLASS_METHOD_RETURNS => [ + self::PARAM_FROM_CLASS_METHOD_RETURNS => [ new InferParamFromClassMethodReturn('SomeClass', 'process', 'getNodeTypes'), ], ] @@ -160,7 +160,7 @@ public function refactor(Node $node): ?Node */ public function configure(array $configuration): void { - $inferParamsFromClassMethodReturns = $configuration[self::INFER_PARAMS_FROM_CLASS_METHOD_RETURNS] ?? []; + $inferParamsFromClassMethodReturns = $configuration[self::PARAM_FROM_CLASS_METHOD_RETURNS] ?? []; Assert::allIsInstanceOf($inferParamsFromClassMethodReturns, InferParamFromClassMethodReturn::class); $this->inferParamFromClassMethodReturn = $inferParamsFromClassMethodReturns; diff --git a/rules/restoration/tests/Rector/ClassMethod/InferParamFromClassMethodReturnRector/config/configured_rule.php b/rules/restoration/tests/Rector/ClassMethod/InferParamFromClassMethodReturnRector/config/configured_rule.php index 2c3ab2362baa..d1f3c39f6ae2 100644 --- a/rules/restoration/tests/Rector/ClassMethod/InferParamFromClassMethodReturnRector/config/configured_rule.php +++ b/rules/restoration/tests/Rector/ClassMethod/InferParamFromClassMethodReturnRector/config/configured_rule.php @@ -13,10 +13,8 @@ $services->set(InferParamFromClassMethodReturnRector::class) ->call('configure', [[ - InferParamFromClassMethodReturnRector::INFER_PARAMS_FROM_CLASS_METHOD_RETURNS => ValueObjectInliner::inline([ - + InferParamFromClassMethodReturnRector::PARAM_FROM_CLASS_METHOD_RETURNS => ValueObjectInliner::inline([ new InferParamFromClassMethodReturn(SomeType::class, 'process', 'getNodeTypes'), - ]), ]]); }; diff --git a/rules/symfony-code-quality/tests/Rector/Class_/EventListenerToEventSubscriberRector/EventListenerToEventSubscriberRectorTest.php b/rules/symfony-code-quality/tests/Rector/Class_/EventListenerToEventSubscriberRector/EventListenerToEventSubscriberRectorTest.php index 6aa48ba77e34..3f197b713aed 100644 --- a/rules/symfony-code-quality/tests/Rector/Class_/EventListenerToEventSubscriberRector/EventListenerToEventSubscriberRectorTest.php +++ b/rules/symfony-code-quality/tests/Rector/Class_/EventListenerToEventSubscriberRector/EventListenerToEventSubscriberRectorTest.php @@ -5,8 +5,6 @@ namespace Rector\SymfonyCodeQuality\Tests\Rector\Class_\EventListenerToEventSubscriberRector; use Iterator; -use Rector\Core\Configuration\Option; -use Rector\SymfonyCodeQuality\Rector\Class_\EventListenerToEventSubscriberRector; use Rector\Testing\PHPUnit\AbstractRectorTestCase; use Symplify\SmartFileSystem\SmartFileInfo; @@ -17,9 +15,6 @@ final class EventListenerToEventSubscriberRectorTest extends AbstractRectorTestC */ public function test(SmartFileInfo $fileInfo): void { - // wtf: all test have to be in single file due to autoloading race-condigition and container creating issue of fixture - $this->setParameter(Option::SYMFONY_CONTAINER_XML_PATH_PARAMETER, __DIR__ . '/config/listener_services.xml'); - $this->doTestFileInfo($fileInfo); } @@ -28,8 +23,8 @@ public function provideData(): Iterator return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); } - protected function getRectorClass(): string + protected function provideConfigFileInfo(): ?SmartFileInfo { - return EventListenerToEventSubscriberRector::class; + return new SmartFileInfo(__DIR__ . '/config/config_with_parameter.php'); } } diff --git a/rules/symfony-code-quality/tests/Rector/Class_/EventListenerToEventSubscriberRector/config/config_with_parameter.php b/rules/symfony-code-quality/tests/Rector/Class_/EventListenerToEventSubscriberRector/config/config_with_parameter.php new file mode 100644 index 000000000000..eceaa7d85107 --- /dev/null +++ b/rules/symfony-code-quality/tests/Rector/Class_/EventListenerToEventSubscriberRector/config/config_with_parameter.php @@ -0,0 +1,16 @@ +parameters(); + // wtf: all test have to be in single file due to autoloading race-condigition and container creating issue of fixture + $parameters->set(Option::SYMFONY_CONTAINER_XML_PATH_PARAMETER, __DIR__ . '/listener_services.xml'); + + $services = $containerConfigurator->services(); + $services->set(EventListenerToEventSubscriberRector::class); +}; diff --git a/rules/symfony3/tests/Rector/MethodCall/StringFormTypeToClassRector/WithContainerTest.php b/rules/symfony3/tests/Rector/MethodCall/StringFormTypeToClassRector/WithContainerTest.php index 280c483c6631..58aa26174a9c 100644 --- a/rules/symfony3/tests/Rector/MethodCall/StringFormTypeToClassRector/WithContainerTest.php +++ b/rules/symfony3/tests/Rector/MethodCall/StringFormTypeToClassRector/WithContainerTest.php @@ -5,8 +5,6 @@ namespace Rector\Symfony3\Tests\Rector\MethodCall\StringFormTypeToClassRector; use Iterator; -use Rector\Core\Configuration\Option; -use Rector\Symfony3\Rector\MethodCall\StringFormTypeToClassRector; use Rector\Testing\PHPUnit\AbstractRectorTestCase; use Symplify\SmartFileSystem\SmartFileInfo; @@ -25,13 +23,8 @@ public function provideData(): Iterator return $this->yieldFilesFromDirectory(__DIR__ . '/FixtureWithContainer'); } - protected function setParameter(string $name, $value): void + protected function provideConfigFileInfo(): ?SmartFileInfo { - parent::setParameter(Option::SYMFONY_CONTAINER_XML_PATH_PARAMETER, __DIR__ . '/Source/custom_container.xml'); - } - - protected function getRectorClass(): string - { - return StringFormTypeToClassRector::class; + return new SmartFileInfo(__DIR__ . '/config/xml_path_config.php'); } } diff --git a/rules/symfony3/tests/Rector/MethodCall/StringFormTypeToClassRector/config/xml_path_config.php b/rules/symfony3/tests/Rector/MethodCall/StringFormTypeToClassRector/config/xml_path_config.php new file mode 100644 index 000000000000..2b8da061bd55 --- /dev/null +++ b/rules/symfony3/tests/Rector/MethodCall/StringFormTypeToClassRector/config/xml_path_config.php @@ -0,0 +1,15 @@ +parameters(); + $parameters->set(Option::SYMFONY_CONTAINER_XML_PATH_PARAMETER, __DIR__ . '/../Source/custom_container.xml'); + + $services = $containerConfigurator->services(); + $services->set(StringFormTypeToClassRector::class); +}; diff --git a/rules/transform/tests/Rector/MethodCall/MethodCallToAnotherMethodCallWithArgumentsRector/config/configured_rule.php b/rules/transform/tests/Rector/MethodCall/MethodCallToAnotherMethodCallWithArgumentsRector/config/configured_rule.php index ca0e74458013..62b9a202340d 100644 --- a/rules/transform/tests/Rector/MethodCall/MethodCallToAnotherMethodCallWithArgumentsRector/config/configured_rule.php +++ b/rules/transform/tests/Rector/MethodCall/MethodCallToAnotherMethodCallWithArgumentsRector/config/configured_rule.php @@ -1,5 +1,7 @@ services(); - $services->set(MethodCallToAnotherMethodCallWithArgumentsRector::class)->call( - 'configure', - [[ + + $services->set(MethodCallToAnotherMethodCallWithArgumentsRector::class) + ->call('configure', [[ MethodCallToAnotherMethodCallWithArgumentsRector::METHOD_CALL_RENAMES_WITH_ADDED_ARGUMENTS => ValueObjectInliner::inline([ @@ -19,8 +21,8 @@ 'setInject', 'addTag', ['inject']), - ] - ), - ]] - ); + + + ]), + ]]); }; diff --git a/rules/transform/tests/Rector/MethodCall/VariableMethodCallToServiceCallRector/config/configured_rule.php b/rules/transform/tests/Rector/MethodCall/VariableMethodCallToServiceCallRector/config/configured_rule.php index 2b3bb176448c..178f847ae5d4 100644 --- a/rules/transform/tests/Rector/MethodCall/VariableMethodCallToServiceCallRector/config/configured_rule.php +++ b/rules/transform/tests/Rector/MethodCall/VariableMethodCallToServiceCallRector/config/configured_rule.php @@ -1,5 +1,7 @@ services(); - $services->set(VariableMethodCallToServiceCallRector::class)->call( - 'configure', - [[ - VariableMethodCallToServiceCallRector::VARIABLE_METHOD_CALLS_TO_SERVICE_CALLS => ValueObjectInliner::inline([ - - new VariableMethodCallToServiceCall( - 'PhpParser\Node', - 'getAttribute', - 'php_doc_info', - 'Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory', - 'createFromNodeOrEmpty' - ), + $configuration = ValueObjectInliner::inline([ + new VariableMethodCallToServiceCall( + 'PhpParser\Node', + 'getAttribute', + 'php_doc_info', + 'Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory', + 'createFromNodeOrEmpty' + ), + ]); - - ]), + $services->set(VariableMethodCallToServiceCallRector::class) + ->call('configure', [[ + VariableMethodCallToServiceCallRector::VARIABLE_METHOD_CALLS_TO_SERVICE_CALLS => $configuration, ]] ); };