[Tests] remove getPhpVersion() helped method, use configs instead (#5477)

This commit is contained in:
Tomas Votruba 2021-02-09 18:25:16 +01:00 committed by GitHub
parent e822db8625
commit ecbef2bcaa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
198 changed files with 777 additions and 3163 deletions

View File

@ -49,7 +49,7 @@ jobs:
-
name: 'PHP Linter'
run: vendor/bin/parallel-lint src bin/rector config tests packages rules --colors --exclude packages/rector-generator/templates --exclude rules/psr4/tests/Rector/Namespace_/MultipleClassFileToPsr4ClassesRector/Source --exclude rules/autodiscovery/tests/Rector/FileNode/MoveInterfacesToContractNamespaceDirectoryRector/Expected --exclude packages/node-type-resolver/tests/PerNodeTypeResolver/PropertyFetchTypeResolver/Source/ClassWithNativeProps.php --exclude packages/node-type-resolver/tests/PerNodeTypeResolver/PropertyFetchTypeResolver/Source/ClassWithNativePropsPhp80.php --exclude packages/node-type-resolver/tests/PerNodeTypeResolver/PropertyFetchTypeResolver/Source/ClassWithTypedPropertyTypes.php
run: vendor/bin/parallel-lint src bin/rector config tests packages rules --colors --exclude packages/rector-generator/templates --exclude rules/psr4/tests/Rector/Namespace_/MultipleClassFileToPsr4ClassesRector/Source --exclude rules/autodiscovery/tests/Rector/FileNode/MoveInterfacesToContractNamespaceDirectoryRector/Expected --exclude packages/node-type-resolver/tests/PerNodeTypeResolver/PropertyFetchTypeResolver/Source/ClassWithNativeProps.php --exclude packages/node-type-resolver/tests/PerNodeTypeResolver/PropertyFetchTypeResolver/Source/ClassWithNativePropsPhp80.php --exclude packages/node-type-resolver/tests/PerNodeTypeResolver/PropertyFetchTypeResolver/Source/ClassWithTypedPropertyTypes.php --exclude rules/nette-kdyby/tests/Rector/MethodCall/ReplaceEventManagerWithEventSubscriberRector/Source/ExpectedSomeClassCopyEvent.php --exclude rules/nette-kdyby/tests/Rector/MethodCall/ReplaceMagicPropertyEventWithEventClassRector/Source/ExpectedFileManagerUploadEvent.php --exclude rules/nette-kdyby/tests/Rector/MethodCall/ReplaceMagicPropertyEventWithEventClassRector/Source/ExpectedDuplicatedEventParamsUploadEvent.php
name: ${{ matrix.actions.name }}
runs-on: ubuntu-latest

View File

@ -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'),
]),
]]);

View File

@ -25,8 +25,6 @@ final class ChangedFilesDetectorTest extends AbstractRectorTestCase
protected function tearDown(): void
{
parent::tearDown();
$this->changedFilesDetector->clear();
}
@ -35,11 +33,9 @@ final class ChangedFilesDetectorTest extends AbstractRectorTestCase
$smartFileInfo = new SmartFileInfo(__DIR__ . '/Source/file.php');
$this->assertTrue($this->changedFilesDetector->hasFileChanged($smartFileInfo));
$this->changedFilesDetector->addFileWithDependencies($smartFileInfo, []);
$this->assertFalse($this->changedFilesDetector->hasFileChanged($smartFileInfo));
$this->changedFilesDetector->invalidateFile($smartFileInfo);
$this->assertTrue($this->changedFilesDetector->hasFileChanged($smartFileInfo));

View File

@ -18,7 +18,6 @@ use Rector\Core\HttpKernel\RectorKernel;
use Rector\Core\NonPhpFile\NonPhpFileProcessor;
use Rector\Core\PhpParser\Printer\BetterStandardPrinter;
use Rector\Core\Stubs\StubLoader;
use Rector\Core\ValueObject\PhpVersion;
use Rector\Core\ValueObject\StaticNonPhpFileSuffixes;
use Rector\Testing\Application\EnabledRectorsProvider;
use Rector\Testing\Contract\RunnableInterface;
@ -26,7 +25,6 @@ use Rector\Testing\Finder\RectorsFinder;
use Rector\Testing\Guard\FixtureGuard;
use Rector\Testing\PhpConfigPrinter\PhpConfigPrinterFactory;
use Rector\Testing\PHPUnit\Behavior\MovingFilesTrait;
use Rector\Testing\PHPUnit\Behavior\RunnableTestTrait;
use Rector\Testing\ValueObject\InputFilePathWithExpectedFile;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
@ -41,12 +39,6 @@ use Symplify\SmartFileSystem\SmartFileSystem;
abstract class AbstractRectorTestCase extends AbstractKernelTestCase
{
use MovingFilesTrait;
use RunnableTestTrait;
/**
* @var int
*/
private const PHP_VERSION_UNDEFINED = 0;
/**
* @var FileProcessor
@ -73,11 +65,6 @@ abstract class AbstractRectorTestCase extends AbstractKernelTestCase
*/
protected $runnableRectorFactory;
/**
* @var NodeScopeResolver
*/
protected $nodeScopeResolver;
/**
* @var FixtureGuard
*/
@ -103,11 +90,6 @@ abstract class AbstractRectorTestCase extends AbstractKernelTestCase
*/
private $autoloadTestFixture = true;
/**
* @var mixed[]
*/
private $oldParameterValues = [];
/**
* @var BetterStandardPrinter
*/
@ -164,23 +146,6 @@ abstract class AbstractRectorTestCase extends AbstractKernelTestCase
$this->betterStandardPrinter = $this->getService(BetterStandardPrinter::class);
$this->removedAndAddedFilesCollector = $this->getService(RemovedAndAddedFilesCollector::class);
$this->removedAndAddedFilesCollector->reset();
// needed for PHPStan, because the analyzed file is just create in /temp
$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
@ -213,27 +178,6 @@ abstract class AbstractRectorTestCase extends AbstractKernelTestCase
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;
}
protected function doTestFileInfoWithoutAutoload(SmartFileInfo $fileInfo): void
{
$this->autoloadTestFixture = false;
@ -254,7 +198,11 @@ abstract class AbstractRectorTestCase extends AbstractKernelTestCase
);
$inputFileInfo = $inputFileInfoAndExpectedFileInfo->getInputFileInfo();
$this->nodeScopeResolver->setAnalysedFiles([$inputFileInfo->getRealPath()]);
// needed for PHPStan, because the analyzed file is just create in /temp
/** @var NodeScopeResolver $nodeScopeResolver */
$nodeScopeResolver = $this->getService(NodeScopeResolver::class);
$nodeScopeResolver->setAnalysedFiles([$inputFileInfo->getRealPath()]);
$expectedFileInfo = $inputFileInfoAndExpectedFileInfo->getExpectedFileInfo();
@ -319,6 +267,19 @@ abstract class AbstractRectorTestCase extends AbstractKernelTestCase
return sys_get_temp_dir() . '/_temp_fixture_easy_testing';
}
protected function assertOriginalAndFixedFileResultEquals(
SmartFileInfo $originalFileInfo,
SmartFileInfo $expectedFileInfo
): void {
$runnable = $this->runnableRectorFactory->createRunnableClass($originalFileInfo);
$expectedInstance = $this->runnableRectorFactory->createRunnableClass($expectedFileInfo);
$actualResult = $runnable->run();
$expectedResult = $expectedInstance->run();
$this->assertSame($expectedResult, $actualResult);
}
/**
* @return SmartFileInfo[]
*/
@ -362,28 +323,6 @@ abstract class AbstractRectorTestCase extends AbstractKernelTestCase
}
}
private function configurePhpVersionFeatures(): void
{
if ($this->getPhpVersion() === self::PHP_VERSION_UNDEFINED) {
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);
}
}
private function ensureRectorClassIsValid(string $rectorClass, string $methodName): void
{
if (is_a($rectorClass, PhpRectorInterface::class, true)) {
@ -407,7 +346,7 @@ abstract class AbstractRectorTestCase extends AbstractKernelTestCase
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(),

View File

@ -1,26 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\Testing\PHPUnit\Behavior;
use Rector\Testing\PHPUnit\RunnableRectorFactory;
use Symplify\SmartFileSystem\SmartFileInfo;
/**
* @property-read RunnableRectorFactory $runnableRectorFactory
*/
trait RunnableTestTrait
{
protected function assertOriginalAndFixedFileResultEquals(
SmartFileInfo $originalFileInfo,
SmartFileInfo $expectedFileInfo
): void {
$runnable = $this->runnableRectorFactory->createRunnableClass($originalFileInfo);
$expectedInstance = $this->runnableRectorFactory->createRunnableClass($expectedFileInfo);
$actualResult = $runnable->run();
$expectedResult = $expectedInstance->run();
$this->assertSame($expectedResult, $actualResult);
}
}

View File

@ -25,7 +25,7 @@ return static function (ContainerConfigurator $containerConfigurator): void {
]);
$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)

View File

@ -6,7 +6,6 @@ namespace Rector\Autodiscovery\Tests\Rector\FileNode\MoveEntitiesToEntityDirecto
use Iterator;
use Rector\Autodiscovery\Rector\FileNode\MoveEntitiesToEntityDirectoryRector;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\FileSystemRector\ValueObject\AddedFileWithContent;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;
@ -42,9 +41,4 @@ final class MoveEntitiesToEntityDirectoryRectorTest extends AbstractRectorTestCa
{
return MoveEntitiesToEntityDirectoryRector::class;
}
protected function getPhpVersion(): int
{
return PhpVersionFeature::TYPED_PROPERTIES - 1;
}
}

View File

@ -5,8 +5,6 @@ declare(strict_types=1);
namespace Rector\Autodiscovery\Tests\Rector\FileNode\MoveInterfacesToContractNamespaceDirectoryRector;
use Iterator;
use Rector\Autodiscovery\Rector\FileNode\MoveInterfacesToContractNamespaceDirectoryRector;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\FileSystemRector\ValueObject\AddedFileWithContent;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Rector\Testing\ValueObject\InputFilePathWithExpectedFile;
@ -108,13 +106,8 @@ final class MoveInterfacesToContractNamespaceDirectoryRectorTest extends Abstrac
yield [new SmartFileInfo(__DIR__ . '/Source/Contract/Foo/KeepThisSomeInterface.php'), null];
}
protected function getRectorClass(): string
protected function provideConfigFileInfo(): ?SmartFileInfo
{
return MoveInterfacesToContractNamespaceDirectoryRector::class;
}
protected function getPhpVersion(): int
{
return PhpVersionFeature::TYPED_PROPERTIES - 1;
return new SmartFileInfo(__DIR__ . '/config/some_config.php');
}
}

View File

@ -0,0 +1,16 @@
<?php
declare(strict_types=1);
use Rector\Autodiscovery\Rector\FileNode\MoveInterfacesToContractNamespaceDirectoryRector;
use Rector\Core\Configuration\Option;
use Rector\Core\ValueObject\PhpVersionFeature;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::PHP_VERSION_FEATURES, PhpVersionFeature::TYPED_PROPERTIES - 1);
$services = $containerConfigurator->services();
$services->set(MoveInterfacesToContractNamespaceDirectoryRector::class);
};

View File

@ -1,33 +1,18 @@
<?php
declare(strict_types=1);
use Rector\Autodiscovery\Rector\FileNode\MoveValueObjectsToValueObjectDirectoryRector;
use Rector\Autodiscovery\Tests\Rector\FileNode\MoveValueObjectsToValueObjectDirectoryRector\Source\ObviousValueObjectInterface;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$services->set(MoveValueObjectsToValueObjectDirectoryRector::class)->call(
'configure',
[[
$services->set(MoveValueObjectsToValueObjectDirectoryRector::class)
->call('configure', [[
MoveValueObjectsToValueObjectDirectoryRector::TYPES => [ObviousValueObjectInterface::class],
]]
);
$services->set(MoveValueObjectsToValueObjectDirectoryRector::class)->call(
'configure',
[[
MoveValueObjectsToValueObjectDirectoryRector::TYPES => [ObviousValueObjectInterface::class],
]]
)->call('configure', [[
MoveValueObjectsToValueObjectDirectoryRector::SUFFIXES => ['Search'],
]]);
$services->set(MoveValueObjectsToValueObjectDirectoryRector::class)->call(
'configure',
[[
MoveValueObjectsToValueObjectDirectoryRector::TYPES => [ObviousValueObjectInterface::class],
]]
)->call('configure', [[
MoveValueObjectsToValueObjectDirectoryRector::SUFFIXES => ['Search'],
]])->call('configure', [[
MoveValueObjectsToValueObjectDirectoryRector::ENABLE_VALUE_OBJECT_GUESSING => true,
]]);
MoveValueObjectsToValueObjectDirectoryRector::SUFFIXES => ['Search'],
MoveValueObjectsToValueObjectDirectoryRector::ENABLE_VALUE_OBJECT_GUESSING => true,
]]);
};

View File

@ -5,8 +5,6 @@ declare(strict_types=1);
namespace Rector\CodeQuality\Tests\Rector\Class_\CompleteDynamicPropertiesRector;
use Iterator;
use Rector\CodeQuality\Rector\Class_\CompleteDynamicPropertiesRector;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;
@ -25,13 +23,8 @@ final class CompleteDynamicPropertiesRectorTest extends AbstractRectorTestCase
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
}
protected function getRectorClass(): string
protected function provideConfigFileInfo(): ?SmartFileInfo
{
return CompleteDynamicPropertiesRector::class;
}
protected function getPhpVersion(): int
{
return PhpVersionFeature::UNION_TYPES - 1;
return new SmartFileInfo(__DIR__ . '/config/pre_union_types.php');
}
}

View File

@ -1,33 +0,0 @@
<?php
namespace Rector\CodeQuality\Tests\Rector\Class_\CompleteDynamicPropertiesRector\FixtureTypedProperty;
class MixedAnotherType
{
public function run()
{
$this->output = $output;
//@anything
}
}
?>
-----
<?php
namespace Rector\CodeQuality\Tests\Rector\Class_\CompleteDynamicPropertiesRector\FixtureTypedProperty;
class MixedAnotherType
{
/**
* @var mixed
*/
public $output;
public function run()
{
$this->output = $output;
//@anything
}
}
?>

View File

@ -1,37 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\CodeQuality\Tests\Rector\Class_\CompleteDynamicPropertiesRector;
use Iterator;
use Rector\CodeQuality\Rector\Class_\CompleteDynamicPropertiesRector;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;
final class TypedPropertyCompleteDynamicPropertiesRectorTest extends AbstractRectorTestCase
{
/**
* @dataProvider provideData()
*/
public function test(SmartFileInfo $fileInfo): void
{
$this->doTestFileInfo($fileInfo);
}
public function provideData(): Iterator
{
return $this->yieldFilesFromDirectory(__DIR__ . '/FixtureTypedProperty');
}
protected function getRectorClass(): string
{
return CompleteDynamicPropertiesRector::class;
}
protected function getPhpVersion(): int
{
return PhpVersionFeature::TYPED_PROPERTIES;
}
}

View File

@ -0,0 +1,16 @@
<?php
declare(strict_types=1);
use Rector\CodeQuality\Rector\Class_\CompleteDynamicPropertiesRector;
use Rector\Core\Configuration\Option;
use Rector\Core\ValueObject\PhpVersionFeature;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::PHP_VERSION_FEATURES, PhpVersionFeature::UNION_TYPES - 1);
$services = $containerConfigurator->services();
$services->set(CompleteDynamicPropertiesRector::class);
};

View File

@ -6,7 +6,6 @@ namespace Rector\CodeQuality\Tests\Rector\Return_\SimplifyUselessVariableRector;
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);
}

View File

@ -5,8 +5,6 @@ declare(strict_types=1);
namespace Rector\CodingStyle\Tests\Rector\ClassMethod\MakeInheritedMethodVisibilitySameAsParentRector;
use Iterator;
use Rector\CodingStyle\Rector\ClassMethod\MakeInheritedMethodVisibilitySameAsParentRector;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;
@ -28,13 +26,8 @@ final class SkipParentConstructOverrideInPHP72Test extends AbstractRectorTestCas
return $this->yieldFilesFromDirectory(__DIR__ . '/FixtureForPhp72');
}
protected function getRectorClass(): string
protected function provideConfigFileInfo(): ?SmartFileInfo
{
return MakeInheritedMethodVisibilitySameAsParentRector::class;
}
protected function getPhpVersion(): int
{
return PhpVersionFeature::PARENT_VISIBILITY_OVERRIDE;
return new SmartFileInfo(__DIR__ . '/config/php_72.php');
}
}

View File

@ -0,0 +1,16 @@
<?php
declare(strict_types=1);
use Rector\CodingStyle\Rector\ClassMethod\MakeInheritedMethodVisibilitySameAsParentRector;
use Rector\Core\Configuration\Option;
use Rector\Core\ValueObject\PhpVersionFeature;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::PHP_VERSION_FEATURES, PhpVersionFeature::PARENT_VISIBILITY_OVERRIDE);
$services = $containerConfigurator->services();
$services->set(MakeInheritedMethodVisibilitySameAsParentRector::class);
};

View File

@ -5,8 +5,6 @@ declare(strict_types=1);
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 @@ final class AutoImportTest extends AbstractRectorTestCase
return $this->yieldFilesFromDirectory(__DIR__ . '/FixtureAutoImport');
}
protected function getRectorClass(): string
protected function provideConfigFileInfo(): ?SmartFileInfo
{
return PreslashSimpleFunctionRector::class;
return new SmartFileInfo(__DIR__ . '/config/auto_import.php');
}
}

View File

@ -0,0 +1,15 @@
<?php
declare(strict_types=1);
use Rector\CodingStyle\Rector\FuncCall\PreslashSimpleFunctionRector;
use Rector\Core\Configuration\Option;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::AUTO_IMPORT_NAMES, true);
$services = $containerConfigurator->services();
$services->set(PreslashSimpleFunctionRector::class);
};

View File

@ -5,8 +5,6 @@ declare(strict_types=1);
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 @@ final class DocBlockRectorTest extends AbstractRectorTestCase
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');
}
}

View File

@ -5,8 +5,6 @@ declare(strict_types=1);
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;
@ -22,8 +20,6 @@ final class ImportFullyQualifiedNamesRectorTest extends AbstractRectorTestCase
*/
public function test(SmartFileInfo $fileInfo): void
{
$this->setParameter(Option::AUTO_IMPORT_NAMES, true);
$this->doTestFileInfo($fileInfo);
}
@ -42,8 +38,8 @@ final class ImportFullyQualifiedNamesRectorTest extends AbstractRectorTestCase
return $this->yieldFilesFromDirectory(__DIR__ . '/FixtureGeneric');
}
protected function getRectorClass(): string
protected function provideConfigFileInfo(): ?SmartFileInfo
{
return RenameClassRector::class;
return new SmartFileInfo(__DIR__ . '/config/import_config.php');
}
}

View File

@ -5,8 +5,6 @@ declare(strict_types=1);
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 @@ final class ImportRootNamespaceClassesDisabledTest extends AbstractRectorTestCas
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');
}
}

View File

@ -5,8 +5,6 @@ declare(strict_types=1);
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,8 +18,6 @@ final class NonNamespacedTest extends AbstractRectorTestCase
*/
public function test(SmartFileInfo $fileInfo): void
{
$this->setParameter(Option::AUTO_IMPORT_NAMES, true);
$this->doTestFileInfo($fileInfo);
}
@ -30,8 +26,8 @@ final class NonNamespacedTest extends AbstractRectorTestCase
return $this->yieldFilesFromDirectory(__DIR__ . '/FixtureNonNamespaced');
}
protected function getRectorClass(): string
protected function provideConfigFileInfo(): ?SmartFileInfo
{
return RenameClassRector::class;
return new SmartFileInfo(__DIR__ . '/config/import_config.php');
}
}

View File

@ -5,8 +5,6 @@ declare(strict_types=1);
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;
@ -21,8 +19,6 @@ final class Php80Test extends AbstractRectorTestCase
*/
public function test(SmartFileInfo $fileInfo): void
{
$this->setParameter(Option::AUTO_IMPORT_NAMES, true);
$this->doTestFileInfo($fileInfo);
}
@ -31,8 +27,8 @@ final class Php80Test extends AbstractRectorTestCase
return $this->yieldFilesFromDirectory(__DIR__ . '/FixtureAttributes');
}
protected function getRectorClass(): string
protected function provideConfigFileInfo(): ?SmartFileInfo
{
return RenameClassRector::class;
return new SmartFileInfo(__DIR__ . '/config/import_config.php');
}
}

View File

@ -0,0 +1,15 @@
<?php
declare(strict_types=1);
use Rector\Core\Configuration\Option;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::AUTO_IMPORT_NAMES, true);
$services = $containerConfigurator->services();
$services->set(RenameClassRector::class);
};

View File

@ -0,0 +1,16 @@
<?php
declare(strict_types=1);
use Rector\Core\Configuration\Option;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::AUTO_IMPORT_NAMES, true);
$parameters->set(Option::IMPORT_DOC_BLOCKS, true);
$services = $containerConfigurator->services();
$services->set(RenameClassRector::class);
};

View File

@ -0,0 +1,16 @@
<?php
declare(strict_types=1);
use Rector\Core\Configuration\Option;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::AUTO_IMPORT_NAMES, true);
$parameters->set(Option::IMPORT_SHORT_CLASSES, false);
$services = $containerConfigurator->services();
$services->set(RenameClassRector::class);
};

View File

@ -77,8 +77,10 @@ CODE_SAMPLE
if ($node->stmts === null) {
return null;
}
$stmtValues = array_values($node->stmts);
$lastStmt = end($stmtValues);
if (! $lastStmt instanceof Return_) {
return null;
}

View File

@ -5,9 +5,6 @@ declare(strict_types=1);
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 @@ final class OpenSourceRectorTest extends AbstractRectorTestCase
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');
}
}

View File

@ -0,0 +1,16 @@
<?php
declare(strict_types=1);
use Rector\Core\Configuration\Option;
use Rector\Core\ValueObject\ProjectType;
use Rector\DeadCode\Rector\ClassConst\RemoveUnusedClassConstantRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::PROJECT_TYPE, ProjectType::OPEN_SOURCE);
$services = $containerConfigurator->services();
$services->set(RemoveUnusedClassConstantRector::class);
};

View File

@ -5,8 +5,6 @@ declare(strict_types=1);
namespace Rector\DeadCode\Tests\Rector\ClassMethod\RemoveDeadConstructorRector;
use Iterator;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\DeadCode\Rector\ClassMethod\RemoveDeadConstructorRector;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;
@ -26,13 +24,8 @@ final class Php80Test extends AbstractRectorTestCase
return $this->yieldFilesFromDirectory(__DIR__ . '/FixturePhp80');
}
protected function getRectorClass(): string
protected function provideConfigFileInfo(): ?SmartFileInfo
{
return RemoveDeadConstructorRector::class;
}
protected function getPhpVersion(): int
{
return PhpVersionFeature::PROPERTY_PROMOTION;
return new SmartFileInfo(__DIR__ . '/config/property_promotion.php');
}
}

View File

@ -0,0 +1,16 @@
<?php
declare(strict_types=1);
use Rector\Core\Configuration\Option;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\DeadCode\Rector\ClassMethod\RemoveDeadConstructorRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::PHP_VERSION_FEATURES, PhpVersionFeature::PROPERTY_PROMOTION);
$services = $containerConfigurator->services();
$services->set(RemoveDeadConstructorRector::class);
};

View File

@ -5,7 +5,6 @@ declare(strict_types=1);
namespace Rector\DeadCode\Tests\Rector\ClassMethod\RemoveEmptyClassMethodRector;
use Iterator;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\DeadCode\Rector\ClassMethod\RemoveEmptyClassMethodRector;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;
@ -30,9 +29,4 @@ final class Php80Test extends AbstractRectorTestCase
{
return RemoveEmptyClassMethodRector::class;
}
protected function getPhpVersion(): int
{
return PhpVersionFeature::PROPERTY_PROMOTION;
}
}

View File

@ -5,9 +5,6 @@ declare(strict_types=1);
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 @@ final class OpenSourceRectorTest extends AbstractRectorTestCase
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');
}
}

View File

@ -5,7 +5,6 @@ declare(strict_types=1);
namespace Rector\DeadCode\Tests\Rector\ClassMethod\RemoveUnusedParameterRector;
use Iterator;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedParameterRector;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;
@ -26,11 +25,6 @@ final class Php80Test extends AbstractRectorTestCase
return $this->yieldFilesFromDirectory(__DIR__ . '/FixturePhp80');
}
protected function getPhpVersion(): int
{
return PhpVersionFeature::PROPERTY_PROMOTION;
}
protected function getRectorClass(): string
{
return RemoveUnusedParameterRector::class;

View File

@ -0,0 +1,16 @@
<?php
declare(strict_types=1);
use Rector\Core\Configuration\Option;
use Rector\Core\ValueObject\ProjectType;
use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedParameterRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::PROJECT_TYPE, ProjectType::OPEN_SOURCE);
$services = $containerConfigurator->services();
$services->set(RemoveUnusedParameterRector::class);
};

View File

@ -5,9 +5,6 @@ declare(strict_types=1);
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 @@ final class OpenSourceRectorTest extends AbstractRectorTestCase
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');
}
}

View File

@ -0,0 +1,16 @@
<?php
declare(strict_types=1);
use Rector\Core\Configuration\Option;
use Rector\Core\ValueObject\ProjectType;
use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPublicMethodRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::PROJECT_TYPE, ProjectType::OPEN_SOURCE);
$services = $containerConfigurator->services();
$services->set(RemoveUnusedPublicMethodRector::class);
};

View File

@ -1,14 +0,0 @@
<?php
namespace Rector\DeadCode\Tests\Rector\FunctionLike\RemoveDeadReturnRector\FixturePhp74;
use Nette\Utils\Strings;
use stdClass;
class SkipArrowFunction
{
private function filterPostTweets(array $tweets): array
{
return array_filter($tweets, fn(stdClass $publishedTweet) => Strings::match($publishedTweet->getText(), '#New post on#i'));
}
}

View File

@ -1,40 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\DeadCode\Tests\Rector\FunctionLike\RemoveDeadReturnRector;
use Iterator;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\DeadCode\Rector\FunctionLike\RemoveDeadReturnRector;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;
/**
* @requires PHP 7.4
*/
final class Php74Test extends AbstractRectorTestCase
{
/**
* @dataProvider provideData()
*/
public function test(SmartFileInfo $fileInfo): void
{
$this->doTestFileInfo($fileInfo);
}
public function provideData(): Iterator
{
return $this->yieldFilesFromDirectory(__DIR__ . '/FixturePhp74');
}
protected function getPhpVersion(): int
{
return PhpVersionFeature::ARROW_FUNCTION;
}
protected function getRectorClass(): string
{
return RemoveDeadReturnRector::class;
}
}

View File

@ -5,8 +5,6 @@ declare(strict_types=1);
namespace Rector\DeadCode\Tests\Rector\PropertyProperty\RemoveNullPropertyInitializationRector;
use Iterator;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\DeadCode\Rector\PropertyProperty\RemoveNullPropertyInitializationRector;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;
@ -26,13 +24,8 @@ final class TypedPropertiesRemoveNullPropertyInitializationRectorTest extends Ab
return $this->yieldFilesFromDirectory(__DIR__ . '/FixtureTypedProperties');
}
protected function getRectorClass(): string
protected function provideConfigFileInfo(): ?SmartFileInfo
{
return RemoveNullPropertyInitializationRector::class;
}
protected function getPhpVersion(): int
{
return PhpVersionFeature::TYPED_PROPERTIES;
return new SmartFileInfo(__DIR__ . '/config/typed_properties.php');
}
}

View File

@ -0,0 +1,16 @@
<?php
declare(strict_types=1);
use Rector\Core\Configuration\Option;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\DeadCode\Rector\PropertyProperty\RemoveNullPropertyInitializationRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::PHP_VERSION_FEATURES, PhpVersionFeature::TYPED_PROPERTIES);
$services = $containerConfigurator->services();
$services->set(RemoveNullPropertyInitializationRector::class);
};

View File

@ -5,8 +5,6 @@ declare(strict_types=1);
namespace Rector\DowngradePhp70\Tests\Rector\FunctionLike\DowngradeTypeParamDeclarationRector;
use Iterator;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\DowngradePhp70\Rector\FunctionLike\DowngradeTypeParamDeclarationRector;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;
@ -25,13 +23,8 @@ final class DowngradeTypeParamDeclarationRectorTest extends AbstractRectorTestCa
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
}
protected function getRectorClass(): string
protected function provideConfigFileInfo(): ?SmartFileInfo
{
return DowngradeTypeParamDeclarationRector::class;
}
protected function getPhpVersion(): int
{
return PhpVersionFeature::NULLABLE_TYPE - 1;
return new SmartFileInfo(__DIR__ . '/config/php_70.php');
}
}

View File

@ -0,0 +1,16 @@
<?php
declare(strict_types=1);
use Rector\Core\Configuration\Option;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\DowngradePhp70\Rector\FunctionLike\DowngradeTypeParamDeclarationRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::PHP_VERSION_FEATURES, PhpVersionFeature::NULLABLE_TYPE - 1);
$services = $containerConfigurator->services();
$services->set(DowngradeTypeParamDeclarationRector::class);
};

View File

@ -5,14 +5,13 @@ declare(strict_types=1);
namespace Rector\DowngradePhp70\Tests\Rector\FunctionLike\DowngradeTypeReturnDeclarationRector;
use Iterator;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\DowngradePhp70\Rector\FunctionLike\DowngradeTypeReturnDeclarationRector;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;
final class DowngradeTypeReturnDeclarationRectorTest extends AbstractRectorTestCase
{
/**
* @requires PHP 7.0
* @dataProvider provideData()
*/
public function test(SmartFileInfo $fileInfo): void
@ -25,13 +24,8 @@ final class DowngradeTypeReturnDeclarationRectorTest extends AbstractRectorTestC
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
}
protected function getRectorClass(): string
protected function provideConfigFileInfo(): ?SmartFileInfo
{
return DowngradeTypeReturnDeclarationRector::class;
}
protected function getPhpVersion(): int
{
return PhpVersionFeature::NULLABLE_TYPE - 1;
return new SmartFileInfo(__DIR__ . '/config/php_70.php');
}
}

View File

@ -0,0 +1,16 @@
<?php
declare(strict_types=1);
use Rector\Core\Configuration\Option;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\DowngradePhp70\Rector\FunctionLike\DowngradeTypeReturnDeclarationRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::PHP_VERSION_FEATURES, PhpVersionFeature::NULLABLE_TYPE - 1);
$services = $containerConfigurator->services();
$services->set(DowngradeTypeReturnDeclarationRector::class);
};

View File

@ -5,8 +5,6 @@ declare(strict_types=1);
namespace Rector\DowngradePhp71\Tests\Rector\TryCatch\DowngradePipeToMultiCatchExceptionRector;
use Iterator;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\DowngradePhp71\Rector\TryCatch\DowngradePipeToMultiCatchExceptionRector;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;
@ -26,13 +24,8 @@ final class DowngradePipeToMultiCatchExceptionRectorTest extends AbstractRectorT
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
}
protected function getRectorClass(): string
protected function provideConfigFileInfo(): ?SmartFileInfo
{
return DowngradePipeToMultiCatchExceptionRector::class;
}
protected function getPhpVersion(): int
{
return PhpVersionFeature::MULTI_EXCEPTION_CATCH - 1;
return new SmartFileInfo(__DIR__ . '/config/configured_rule.php');
}
}

View File

@ -0,0 +1,16 @@
<?php
declare(strict_types=1);
use Rector\Core\Configuration\Option;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\DowngradePhp71\Rector\TryCatch\DowngradePipeToMultiCatchExceptionRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::PHP_VERSION_FEATURES, PhpVersionFeature::MULTI_EXCEPTION_CATCH - 1);
$services = $containerConfigurator->services();
$services->set(DowngradePipeToMultiCatchExceptionRector::class);
};

View File

@ -22,10 +22,8 @@ use stdClass;
class TypedProperty
{
private stdClass $property;
public function __construct(\stdClass $property)
public function __construct(private \stdClass $property)
{
$this->property = $property;
}
}

View File

@ -5,7 +5,6 @@ declare(strict_types=1);
namespace Rector\Generic\Tests\Rector\Property\AnnotatedPropertyInjectToConstructorInjectionRector;
use Iterator;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\Generic\Rector\Property\AnnotatedPropertyInjectToConstructorInjectionRector;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;
@ -26,11 +25,6 @@ final class Php74Test extends AbstractRectorTestCase
return $this->yieldFilesFromDirectory(__DIR__ . '/FixturePhp74');
}
protected function getPhpVersion(): int
{
return PhpVersionFeature::TYPED_PROPERTIES;
}
protected function getRectorClass(): string
{
return AnnotatedPropertyInjectToConstructorInjectionRector::class;

View File

@ -5,7 +5,6 @@ declare(strict_types=1);
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);
}

View File

@ -1,12 +1,20 @@
<?php
use JMS\DiExtraBundle\Annotation\Inject;
use Rector\Core\Configuration\Option;
use Rector\Generic\Rector\Property\InjectAnnotationClassRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->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],
]]);
};

View File

@ -5,7 +5,6 @@ declare(strict_types=1);
namespace Rector\Naming\Tests\Rector\ClassMethod\RenameParamToMatchTypeRector;
use Iterator;
use Rector\Core\ValueObject\PhpVersion;
use Rector\Naming\Rector\ClassMethod\RenameParamToMatchTypeRector;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;
@ -32,9 +31,4 @@ final class Php80Test extends AbstractRectorTestCase
{
return RenameParamToMatchTypeRector::class;
}
protected function getPhpVersion(): int
{
return PhpVersion::PHP_80;
}
}

View File

@ -4,7 +4,7 @@ namespace Rector\Naming\Tests\Rector\Class_\RenamePropertyToMatchTypeRector\Fixt
use Rector\Naming\Tests\Rector\ClassMethod\RenameParamToMatchTypeRector\Source\EliteManager;
class PromotedPropertyRenameFetch
final class PromotedPropertyRenameFetch
{
public function __construct(
private EliteManager $eventManager
@ -26,7 +26,7 @@ namespace Rector\Naming\Tests\Rector\Class_\RenamePropertyToMatchTypeRector\Fixt
use Rector\Naming\Tests\Rector\ClassMethod\RenameParamToMatchTypeRector\Source\EliteManager;
class PromotedPropertyRenameFetch
final class PromotedPropertyRenameFetch
{
public function __construct(
private EliteManager $eliteManager

View File

@ -5,8 +5,6 @@ declare(strict_types=1);
namespace Rector\Naming\Tests\Rector\Class_\RenamePropertyToMatchTypeRector;
use Iterator;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\Naming\Rector\Class_\RenamePropertyToMatchTypeRector;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;
@ -28,13 +26,8 @@ final class Php80Test extends AbstractRectorTestCase
return $this->yieldFilesFromDirectory(__DIR__ . '/FixturePhp80');
}
protected function getRectorClass(): string
protected function provideConfigFileInfo(): ?SmartFileInfo
{
return RenamePropertyToMatchTypeRector::class;
}
protected function getPhpVersion(): int
{
return PhpVersionFeature::PROPERTY_PROMOTION;
return new SmartFileInfo(__DIR__ . '/config/property_promotion.php');
}
}

View File

@ -0,0 +1,16 @@
<?php
declare(strict_types=1);
use Rector\Core\Configuration\Option;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\Naming\Rector\Class_\RenamePropertyToMatchTypeRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::PHP_VERSION_FEATURES, PhpVersionFeature::PROPERTY_PROMOTION);
$services = $containerConfigurator->services();
$services->set(RenamePropertyToMatchTypeRector::class);
};

View File

@ -1,31 +0,0 @@
<?php
namespace Rector\Naming\Tests\Rector\Property\MakeBoolPropertyRespectIsHasWasMethodNamingRector\FixturePhp74;
class SomeClass
{
private bool $full;
public function isFull()
{
return $this->full;
}
}
?>
-----
<?php
namespace Rector\Naming\Tests\Rector\Property\MakeBoolPropertyRespectIsHasWasMethodNamingRector\FixturePhp74;
class SomeClass
{
private bool $isFull;
public function isFull()
{
return $this->isFull;
}
}
?>

View File

@ -1,40 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\Naming\Tests\Rector\Property\MakeBoolPropertyRespectIsHasWasMethodNamingRector;
use Iterator;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\Naming\Rector\Property\MakeBoolPropertyRespectIsHasWasMethodNamingRector;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;
/**
* @requires PHP 7.4
*/
final class Php74Test extends AbstractRectorTestCase
{
/**
* @dataProvider provideData()
*/
public function test(SmartFileInfo $fileInfo): void
{
$this->doTestFileInfo($fileInfo);
}
public function provideData(): Iterator
{
return $this->yieldFilesFromDirectory(__DIR__ . '/FixturePhp74');
}
protected function getPhpVersion(): int
{
return PhpVersionFeature::TYPED_PROPERTIES;
}
protected function getRectorClass(): string
{
return MakeBoolPropertyRespectIsHasWasMethodNamingRector::class;
}
}

View File

@ -5,8 +5,6 @@ declare(strict_types=1);
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 @@ final class AutoImportTest extends AbstractRectorTestCase
return $this->yieldFilesFromDirectory(__DIR__ . '/FixtureAutoImport');
}
protected function getRectorClass(): string
protected function provideConfigFileInfo(): ?SmartFileInfo
{
return MakeGetComponentAssignAnnotatedRector::class;
return new SmartFileInfo(__DIR__ . '/config/auto_import.php');
}
}

View File

@ -0,0 +1,16 @@
<?php
declare(strict_types=1);
use Rector\Core\Configuration\Option;
use Rector\NetteCodeQuality\Rector\Assign\MakeGetComponentAssignAnnotatedRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::AUTO_IMPORT_NAMES, true);
$parameters->set(Option::IMPORT_DOC_BLOCKS, true);
$services = $containerConfigurator->services();
$services->set(MakeGetComponentAssignAnnotatedRector::class);
};

View File

@ -4,7 +4,6 @@ declare(strict_types=1);
namespace Rector\NetteKdyby\Tests\Rector\MethodCall\ReplaceEventManagerWithEventSubscriberRector;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\NetteKdyby\Rector\MethodCall\ReplaceEventManagerWithEventSubscriberRector;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;
@ -22,9 +21,4 @@ final class ReplaceEventManagerWithEventSubscriberRectorTest extends AbstractRec
{
return ReplaceEventManagerWithEventSubscriberRector::class;
}
protected function getPhpVersion(): int
{
return PhpVersionFeature::TYPED_PROPERTIES - 1;
}
}

View File

@ -4,14 +4,8 @@ namespace Rector\NetteKdyby\Tests\Rector\MethodCall\ReplaceEventManagerWithEvent
final class SomeClassCopyEvent extends \Symfony\Contracts\EventDispatcher\Event
{
/**
* @var \Rector\NetteKdyby\Tests\Rector\MethodCall\ReplaceEventManagerWithEventSubscriberRector\Fixture\SomeClass
*/
private $someClass;
/**
* @var string
*/
private $key;
private \Rector\NetteKdyby\Tests\Rector\MethodCall\ReplaceEventManagerWithEventSubscriberRector\Fixture\SomeClass $someClass;
private string $key;
public function __construct(\Rector\NetteKdyby\Tests\Rector\MethodCall\ReplaceEventManagerWithEventSubscriberRector\Fixture\SomeClass $someClass, string $key)
{
$this->someClass = $someClass;

View File

@ -24,14 +24,10 @@ use Rector\NetteKdyby\Tests\Rector\MethodCall\ReplaceMagicPropertyEventWithEvent
final class DuplicatedEventParams
{
/**
* @var \Symfony\Contracts\EventDispatcher\EventDispatcherInterface
*/
private $eventDispatcher;
public function __construct(\Symfony\Contracts\EventDispatcher\EventDispatcherInterface $eventDispatcher)
public function __construct(private \Symfony\Contracts\EventDispatcher\EventDispatcherInterface $eventDispatcher)
{
$this->eventDispatcher = $eventDispatcher;
}
public function run(SomeUser $user, string $some_underscore)
{
$duplicatedEventParamsUploadEvent = new \Rector\NetteKdyby\Tests\Rector\MethodCall\ReplaceMagicPropertyEventWithEventClassRector\Fixture\Event\DuplicatedEventParamsUploadEvent($user['owner_id'], $user->name_value, $some_underscore);

View File

@ -24,14 +24,10 @@ use Rector\NetteKdyby\Tests\Rector\MethodCall\ReplaceMagicPropertyEventWithEvent
final class FileManager
{
/**
* @var \Symfony\Contracts\EventDispatcher\EventDispatcherInterface
*/
private $eventDispatcher;
public function __construct(\Symfony\Contracts\EventDispatcher\EventDispatcherInterface $eventDispatcher)
public function __construct(private \Symfony\Contracts\EventDispatcher\EventDispatcherInterface $eventDispatcher)
{
$this->eventDispatcher = $eventDispatcher;
}
public function run(SomeUser $user)
{
$fileManagerUploadEvent = new \Rector\NetteKdyby\Tests\Rector\MethodCall\ReplaceMagicPropertyEventWithEventClassRector\Fixture\Event\FileManagerUploadEvent($user);

View File

@ -5,7 +5,6 @@ declare(strict_types=1);
namespace Rector\NetteKdyby\Tests\Rector\MethodCall\ReplaceMagicPropertyEventWithEventClassRector;
use Iterator;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\NetteKdyby\Rector\MethodCall\ReplaceMagicPropertyEventWithEventClassRector;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;
@ -46,11 +45,6 @@ final class ReplaceMagicPropertyEventWithEventClassRectorTest extends AbstractRe
];
}
protected function getPhpVersion(): int
{
return PhpVersionFeature::TYPED_PROPERTIES - 1;
}
protected function getRectorClass(): string
{
return ReplaceMagicPropertyEventWithEventClassRector::class;

View File

@ -12,10 +12,7 @@ final class DuplicatedEventParamsUploadEvent extends \Symfony\Contracts\EventDis
* @var mixed
*/
private $userNameValue;
/**
* @var string
*/
private $someUnderscore;
private string $someUnderscore;
public function __construct($userOwnerId, $userNameValue, string $someUnderscore)
{
$this->userOwnerId = $userOwnerId;

View File

@ -4,10 +4,7 @@ namespace Rector\NetteKdyby\Tests\Rector\MethodCall\ReplaceMagicPropertyEventWit
final class FileManagerUploadEvent extends \Symfony\Contracts\EventDispatcher\Event
{
/**
* @var \Rector\NetteKdyby\Tests\Rector\MethodCall\ReplaceMagicPropertyEventWithEventClassRector\Source\SomeUser
*/
private $user;
private \Rector\NetteKdyby\Tests\Rector\MethodCall\ReplaceMagicPropertyEventWithEventClassRector\Source\SomeUser $user;
public function __construct(\Rector\NetteKdyby\Tests\Rector\MethodCall\ReplaceMagicPropertyEventWithEventClassRector\Source\SomeUser $user)
{
$this->user = $user;

View File

@ -58,14 +58,8 @@ class SomeClass
*/
private $context;
/**
* @var SomeTypeToInject
*/
private $someTypeToInject;
public function __construct(SomeTypeToInject $someTypeToInject)
public function __construct(private SomeTypeToInject $someTypeToInject)
{
$this->someTypeToInject = $someTypeToInject;
}
public function run()

View File

@ -5,7 +5,6 @@ declare(strict_types=1);
namespace Rector\Nette\Tests\Rector\MethodCall\ContextGetByTypeToConstructorInjectionRector;
use Iterator;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\Nette\Rector\MethodCall\ContextGetByTypeToConstructorInjectionRector;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;
@ -25,11 +24,6 @@ final class ContextGetByTypeToConstructorInjectionRectorTest extends AbstractRec
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
}
protected function getPhpVersion(): int
{
return PhpVersionFeature::TYPED_PROPERTIES - 1;
}
protected function getRectorClass(): string
{
return ContextGetByTypeToConstructorInjectionRector::class;

View File

@ -31,13 +31,8 @@ class SomeClass
* @var \Nette\DI\Container
*/
private $context;
/**
* @var \Rector\Nette\Tests\Rector\MethodCall\ContextGetByTypeToConstructorInjectionRector\Source\SomeTypeToInject
*/
private $someTypeToInject;
public function __construct(\Rector\Nette\Tests\Rector\MethodCall\ContextGetByTypeToConstructorInjectionRector\Source\SomeTypeToInject $someTypeToInject)
public function __construct(private \Rector\Nette\Tests\Rector\MethodCall\ContextGetByTypeToConstructorInjectionRector\Source\SomeTypeToInject $someTypeToInject)
{
$this->someTypeToInject = $someTypeToInject;
}
public function run()

View File

@ -31,13 +31,8 @@ class InterfaceName
* @var \Nette\DI\Container
*/
private $context;
/**
* @var \Rector\Nette\Tests\Rector\MethodCall\ContextGetByTypeToConstructorInjectionRector\Source\ISomeInterfaceToInject
*/
private $someInterfaceToInject;
public function __construct(\Rector\Nette\Tests\Rector\MethodCall\ContextGetByTypeToConstructorInjectionRector\Source\ISomeInterfaceToInject $someInterfaceToInject)
public function __construct(private \Rector\Nette\Tests\Rector\MethodCall\ContextGetByTypeToConstructorInjectionRector\Source\ISomeInterfaceToInject $someInterfaceToInject)
{
$this->someInterfaceToInject = $someInterfaceToInject;
}
public function run()

View File

@ -38,15 +38,11 @@ final class RespectInjectParentConstructPreferLocalConstructorPresenter extends
* @var \Nette\DI\Container
*/
private $context;
/**
* @var \Rector\Nette\Tests\Rector\MethodCall\ContextGetByTypeToConstructorInjectionRector\Source\ISomeInterfaceToInject
*/
private $someInterfaceToInject;
public function __construct(\Rector\Nette\Tests\Rector\MethodCall\ContextGetByTypeToConstructorInjectionRector\Source\ISomeInterfaceToInject $someInterfaceToInject)
public function __construct(private \Rector\Nette\Tests\Rector\MethodCall\ContextGetByTypeToConstructorInjectionRector\Source\ISomeInterfaceToInject $someInterfaceToInject)
{
$some = 100;
$this->someInterfaceToInject = $someInterfaceToInject;
parent::__construct();
}
public function go()

View File

@ -34,10 +34,9 @@ final class RespectInjectParentConstructPresenter extends ConstructorInjectionPa
*/
private $context;
/**
* @var \Rector\Nette\Tests\Rector\MethodCall\ContextGetByTypeToConstructorInjectionRector\Source\ISomeInterfaceToInject
* @inject
*/
public $someInterfaceToInject;
public \Rector\Nette\Tests\Rector\MethodCall\ContextGetByTypeToConstructorInjectionRector\Source\ISomeInterfaceToInject $someInterfaceToInject;
public function go()
{

View File

@ -44,10 +44,9 @@ class RespectInjectPresenter
*/
public $otherInjectedService;
/**
* @var \Rector\Nette\Tests\Rector\MethodCall\ContextGetByTypeToConstructorInjectionRector\Source\ISomeInterfaceToInject
* @inject
*/
public $someInterfaceToInject;
public \Rector\Nette\Tests\Rector\MethodCall\ContextGetByTypeToConstructorInjectionRector\Source\ISomeInterfaceToInject $someInterfaceToInject;
public function run()
{

View File

@ -1,43 +0,0 @@
<?php
namespace Rector\Nette\Tests\Rector\MethodCall\ContextGetByTypeToConstructorInjectionRector\Fixture;
use Rector\Nette\Tests\Rector\MethodCall\ContextGetByTypeToConstructorInjectionRector\Source\ParentWithInjectedPropertyPresenter;
use Rector\Nette\Tests\Rector\MethodCall\ContextGetByTypeToConstructorInjectionRector\Source\SomeTypeToInject;
class ReuseParentInjectedPropertyWithSameType extends ParentWithInjectedPropertyPresenter
{
/**
* @var \Nette\DI\Container
*/
private $context;
public function go()
{
$someTypeToInject = $this->context->getByType(SomeTypeToInject::class);
}
}
?>
-----
<?php
namespace Rector\Nette\Tests\Rector\MethodCall\ContextGetByTypeToConstructorInjectionRector\Fixture;
use Rector\Nette\Tests\Rector\MethodCall\ContextGetByTypeToConstructorInjectionRector\Source\ParentWithInjectedPropertyPresenter;
use Rector\Nette\Tests\Rector\MethodCall\ContextGetByTypeToConstructorInjectionRector\Source\SomeTypeToInject;
class ReuseParentInjectedPropertyWithSameType extends ParentWithInjectedPropertyPresenter
{
/**
* @var \Nette\DI\Container
*/
private $context;
public function go()
{
$someTypeToInject = $this->someTypeToInject;
}
}
?>

View File

@ -8,7 +8,7 @@ use Nette\Application\IPresenter;
use Nette\Application\IResponse;
use Nette\Application\Request;
class ConstructorInjectionParentPresenter implements IPresenter
abstract class ConstructorInjectionParentPresenter implements IPresenter
{
/**
* @var SomeTypeToInject

View File

@ -5,8 +5,6 @@ declare(strict_types=1);
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 @@ final class ImportClassNameRectorTest extends AbstractRectorTestCase
return $this->yieldFilesFromDirectory(__DIR__ . '/FixtureImport');
}
protected function getRectorClass(): string
protected function provideConfigFileInfo(): ?SmartFileInfo
{
return StringClassNameToClassConstantRector::class;
return new SmartFileInfo(__DIR__ . '/config/import_config.php');
}
}

View File

@ -0,0 +1,15 @@
<?php
declare(strict_types=1);
use Rector\Core\Configuration\Option;
use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::AUTO_IMPORT_NAMES, true);
$services = $containerConfigurator->services();
$services->set(StringClassNameToClassConstantRector::class);
};

View File

@ -1,37 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\Php71\Tests\Rector\BooleanOr\IsIterableRector;
use Iterator;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\Php71\Rector\BooleanOr\IsIterableRector;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;
final class PolyfillRectorTest extends AbstractRectorTestCase
{
/**
* @dataProvider provideData()
*/
public function test(SmartFileInfo $fileInfo): void
{
$this->doTestFileInfo($fileInfo);
}
public function provideData(): Iterator
{
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
}
protected function getRectorClass(): string
{
return IsIterableRector::class;
}
protected function getPhpVersion(): int
{
return PhpVersionFeature::ITERABLE_TYPE;
}
}

View File

@ -5,8 +5,6 @@ declare(strict_types=1);
namespace Rector\Php71\Tests\Rector\FuncCall\CountOnNullRector;
use Iterator;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\Php71\Rector\FuncCall\CountOnNullRector;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;
@ -25,13 +23,8 @@ final class CountOnNullRectorTest extends AbstractRectorTestCase
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
}
protected function getRectorClass(): string
protected function provideConfigFileInfo(): ?SmartFileInfo
{
return CountOnNullRector::class;
}
protected function getPhpVersion(): int
{
return PhpVersionFeature::COUNT_ON_NULL;
return new SmartFileInfo(__DIR__ . '/config/php_71.php');
}
}

View File

@ -5,8 +5,6 @@ declare(strict_types=1);
namespace Rector\Php71\Tests\Rector\FuncCall\CountOnNullRector;
use Iterator;
use Rector\Core\ValueObject\PhpVersion;
use Rector\Php71\Rector\FuncCall\CountOnNullRector;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;
@ -25,13 +23,8 @@ final class CountOnNullRectorWithPHP73Test extends AbstractRectorTestCase
return $this->yieldFilesFromDirectory(__DIR__ . '/FixtureForPhp73');
}
protected function getRectorClass(): string
protected function provideConfigFileInfo(): ?SmartFileInfo
{
return CountOnNullRector::class;
}
protected function getPhpVersion(): int
{
return PhpVersion::PHP_73;
return new SmartFileInfo(__DIR__ . '/config/is_countable.php');
}
}

View File

@ -0,0 +1,16 @@
<?php
declare(strict_types=1);
use Rector\Core\Configuration\Option;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\Php71\Rector\FuncCall\CountOnNullRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::PHP_VERSION_FEATURES, PhpVersionFeature::IS_COUNTABLE);
$services = $containerConfigurator->services();
$services->set(CountOnNullRector::class);
};

View File

@ -0,0 +1,16 @@
<?php
declare(strict_types=1);
use Rector\Core\Configuration\Option;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\Php71\Rector\FuncCall\CountOnNullRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::PHP_VERSION_FEATURES, PhpVersionFeature::COUNT_ON_NULL);
$services = $containerConfigurator->services();
$services->set(CountOnNullRector::class);
};

View File

@ -5,8 +5,6 @@ declare(strict_types=1);
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 @@ final class PostImportTest extends AbstractRectorTestCase
return $this->yieldFilesFromDirectory(__DIR__ . '/FixturePostImport');
}
protected function getRectorClass(): string
protected function provideConfigFileInfo(): ?SmartFileInfo
{
return GetClassOnNullRector::class;
return new SmartFileInfo(__DIR__ . '/config/auto_import.php');
}
}

View File

@ -0,0 +1,15 @@
<?php
declare(strict_types=1);
use Rector\Core\Configuration\Option;
use Rector\Php72\Rector\FuncCall\GetClassOnNullRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::AUTO_IMPORT_NAMES, true);
$services = $containerConfigurator->services();
$services->set(GetClassOnNullRector::class);
};

View File

@ -5,8 +5,6 @@ declare(strict_types=1);
namespace Rector\Php73\Tests\Rector\BinaryOr\IsCountableRector;
use Iterator;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\Php73\Rector\BooleanOr\IsCountableRector;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;
@ -25,13 +23,8 @@ final class PolyfillRectorTest extends AbstractRectorTestCase
return $this->yieldFilesFromDirectory(__DIR__ . '/FixtureWithPolyfill');
}
protected function getPhpVersion(): int
protected function provideConfigFileInfo(): ?SmartFileInfo
{
return PhpVersionFeature::IS_COUNTABLE - 1;
}
protected function getRectorClass(): string
{
return IsCountableRector::class;
return new SmartFileInfo(__DIR__ . '/config/polyfill_config.php');
}
}

View File

@ -0,0 +1,16 @@
<?php
declare(strict_types=1);
use Rector\Core\Configuration\Option;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\Php73\Rector\BooleanOr\IsCountableRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::PHP_VERSION_FEATURES, PhpVersionFeature::IS_COUNTABLE - 1);
$services = $containerConfigurator->services();
$services->set(IsCountableRector::class);
};

View File

@ -39,7 +39,7 @@ final class TypedPropertyRector extends AbstractRector implements ConfigurableRe
/**
* @var string
*/
public const CLASS_LIKE_TYPE_ONLY = '$classLikeTypeOnly';
public const CLASS_LIKE_TYPE_ONLY = 'class_like_type_only';
/**
* Useful for refactoring of huge applications. Taking types first narrows scope

View File

@ -5,7 +5,6 @@ declare(strict_types=1);
namespace Rector\Php74\Tests\Rector\Property\TypedPropertyRector;
use Iterator;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;
@ -28,9 +27,4 @@ final class DoctrineTypedPropertyRectorTest extends AbstractRectorTestCase
{
return new SmartFileInfo(__DIR__ . '/config/configured_rule.php');
}
protected function getPhpVersion(): int
{
return PhpVersionFeature::UNION_TYPES - 1;
}
}

View File

@ -2,7 +2,7 @@
namespace Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Fixture;
use Rector\TypeDeclaration\Tests\Rector\Property\TypedPropertyRector\Source\AnotherClass;
use Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Source\AnotherClass;
final class ClassWithClassProperty
{
@ -18,11 +18,11 @@ final class ClassWithClassProperty
namespace Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Fixture;
use Rector\TypeDeclaration\Tests\Rector\Property\TypedPropertyRector\Source\AnotherClass;
use Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Source\AnotherClass;
final class ClassWithClassProperty
{
private \Rector\TypeDeclaration\Tests\Rector\Property\TypedPropertyRector\Source\AnotherClass $anotherClass;
private \Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Source\AnotherClass $anotherClass;
}
?>

View File

@ -2,7 +2,7 @@
namespace Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Fixture;
use Rector\TypeDeclaration\Tests\Rector\Property\TypedPropertyRector\Source\AnotherClass;
use Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Source\AnotherClass;
final class InjectProperty extends AbstractParentPresenter
{
@ -24,14 +24,14 @@ abstract class AbstractParentPresenter
namespace Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Fixture;
use Rector\TypeDeclaration\Tests\Rector\Property\TypedPropertyRector\Source\AnotherClass;
use Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Source\AnotherClass;
final class InjectProperty extends AbstractParentPresenter
{
/**
* @inject
*/
private \Rector\TypeDeclaration\Tests\Rector\Property\TypedPropertyRector\Source\AnotherClass $anotherClass;
private \Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Source\AnotherClass $anotherClass;
}
abstract class AbstractParentPresenter

View File

@ -2,7 +2,7 @@
namespace Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Fixture;
use Rector\TypeDeclaration\Tests\Rector\Property\TypedPropertyRector\Source\AnotherClass;
use Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Source\AnotherClass;
final class ClassWithNullableProperty
{
@ -23,13 +23,13 @@ final class ClassWithNullableProperty
namespace Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Fixture;
use Rector\TypeDeclaration\Tests\Rector\Property\TypedPropertyRector\Source\AnotherClass;
use Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Source\AnotherClass;
final class ClassWithNullableProperty
{
private ?\Rector\TypeDeclaration\Tests\Rector\Property\TypedPropertyRector\Source\AnotherClass $nullableClassWithDefaultNull = null;
private ?\Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Source\AnotherClass $nullableClassWithDefaultNull = null;
private ?\Rector\TypeDeclaration\Tests\Rector\Property\TypedPropertyRector\Source\AnotherClass $yetAnotherClass = null;
private ?\Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Source\AnotherClass $yetAnotherClass = null;
}
?>

View File

@ -2,7 +2,7 @@
namespace Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Fixture;
use Rector\TypeDeclaration\Tests\Rector\Property\TypedPropertyRector\Source\AnotherClass;
use Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Source\AnotherClass;
final class ClassWithStaticProperty
{
@ -18,7 +18,7 @@ final class ClassWithStaticProperty
namespace Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Fixture;
use Rector\TypeDeclaration\Tests\Rector\Property\TypedPropertyRector\Source\AnotherClass;
use Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Source\AnotherClass;
final class ClassWithStaticProperty
{

View File

@ -2,7 +2,7 @@
namespace Rector\Php74\Tests\Rector\Property\TypedPropertyRector\FixtureClassLikeTypeOnly;
use Rector\TypeDeclaration\Tests\Rector\Property\TypedPropertyRector\Source\AnotherClass;
use Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Source\AnotherClass;
final class ClassWithClassProperty
{
@ -18,11 +18,11 @@ final class ClassWithClassProperty
namespace Rector\Php74\Tests\Rector\Property\TypedPropertyRector\FixtureClassLikeTypeOnly;
use Rector\TypeDeclaration\Tests\Rector\Property\TypedPropertyRector\Source\AnotherClass;
use Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Source\AnotherClass;
final class ClassWithClassProperty
{
private \Rector\TypeDeclaration\Tests\Rector\Property\TypedPropertyRector\Source\AnotherClass $anotherClass;
private \Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Source\AnotherClass $anotherClass;
}
?>

View File

@ -5,8 +5,6 @@ declare(strict_types=1);
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 @@ final class ImportedTest extends AbstractRectorTestCase
return $this->yieldFilesFromDirectory(__DIR__ . '/FixtureImported');
}
protected function getRectorClass(): string
protected function provideConfigFileInfo(): ?SmartFileInfo
{
return TypedPropertyRector::class;
return new SmartFileInfo(__DIR__ . '/config/imported_type.php');
}
}

View File

@ -0,0 +1,10 @@
<?php
declare(strict_types=1);
namespace Rector\Php74\Tests\Rector\Property\TypedPropertyRector\Source;
final class AnotherClass
{
}

View File

@ -5,7 +5,6 @@ declare(strict_types=1);
namespace Rector\Php74\Tests\Rector\Property\TypedPropertyRector;
use Iterator;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;
@ -24,11 +23,6 @@ final class TypedPropertyRectorTest extends AbstractRectorTestCase
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
}
protected function getPhpVersion(): int
{
return PhpVersionFeature::UNION_TYPES - 1;
}
protected function provideConfigFileInfo(): ?SmartFileInfo
{
return new SmartFileInfo(__DIR__ . '/config/configured_rule.php');

View File

@ -5,7 +5,6 @@ declare(strict_types=1);
namespace Rector\Php74\Tests\Rector\Property\TypedPropertyRector;
use Iterator;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\Php74\Rector\Property\TypedPropertyRector;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;
@ -29,9 +28,4 @@ final class UnionTypedPropertyRectorTest extends AbstractRectorTestCase
{
return TypedPropertyRector::class;
}
protected function getPhpVersion(): int
{
return PhpVersionFeature::UNION_TYPES;
}
}

View File

@ -1,11 +1,17 @@
<?php
use Rector\Core\Configuration\Option;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\Php74\Rector\Property\TypedPropertyRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::PHP_VERSION_FEATURES, PhpVersionFeature::UNION_TYPES - 1);
$services = $containerConfigurator->services();
$services->set(TypedPropertyRector::class)->call('configure', [[
TypedPropertyRector::CLASS_LIKE_TYPE_ONLY => false,
]]);
$services->set(TypedPropertyRector::class)
->call('configure', [[
TypedPropertyRector::CLASS_LIKE_TYPE_ONLY => false,
]]);
};

View File

@ -0,0 +1,18 @@
<?php
declare(strict_types=1);
use Rector\Core\Configuration\Option;
use Rector\Php74\Rector\Property\TypedPropertyRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::AUTO_IMPORT_NAMES, true);
$services = $containerConfigurator->services();
$services->set(TypedPropertyRector::class)
->call('configure', [[
TypedPropertyRector::CLASS_LIKE_TYPE_ONLY => true,
]]);
};

Some files were not shown because too many files have changed in this diff Show More