Skip to content

Commit

Permalink
switch getRulesWithConfiguration() to config first approach
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Feb 9, 2021
1 parent f001ee7 commit 5c0a574
Show file tree
Hide file tree
Showing 240 changed files with 3,496 additions and 2,216 deletions.
3 changes: 3 additions & 0 deletions Abc\FqnizeNamespaced,
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
PHPUnit 9.5.2 by Sebastian Bergmann and contributors.

Cannot open file "FqnizeNamespaced".
Empty file added MyNamespace\MyNewClass,
Empty file.
Empty file added MyNewNamespace\MyNewClass,
Empty file.
Empty file added MyNewNamespace\MyNewInterface,
Empty file.
Empty file added MyNewNamespace\MyNewTrait,
Empty file.
Empty file.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
"Rector\\CodeQuality\\": "rules/code-quality/src",
"Rector\\CodingStyle\\": "rules/coding-style/src",
"Rector\\Composer\\": "rules/composer/src",
"Rector\\Core\\": ["src", "rules/core/src"],
"Rector\\Core\\": "src",
"Rector\\DeadCode\\": "rules/dead-code/src",
"Rector\\DependencyInjection\\": "rules/dependency-injection/src",
"Rector\\EarlyReturn\\": "rules/early-return/src",
Expand Down
1 change: 1 addition & 0 deletions config/set/downgrade-php71.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

// skip classes used in PHP DocBlocks, like in /** @var \Some\Class */ [default: true]
$parameters->set(Option::IMPORT_DOC_BLOCKS, false);

$services->set(DowngradeClassConstantVisibilityRector::class);
$services->set(DowngradePipeToMultiCatchExceptionRector::class);
$services->set(SymmetricArrayDestructuringToListRector::class);
Expand Down
1 change: 1 addition & 0 deletions config/set/downgrade-php72.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@

// skip classes used in PHP DocBlocks, like in /** @var \Some\Class */ [default: true]
$parameters->set(Option::IMPORT_DOC_BLOCKS, false);

$services->set(DowngradeParameterTypeWideningRector::class);
};
1 change: 1 addition & 0 deletions config/set/downgrade-php73.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

// skip classes used in PHP DocBlocks, like in /** @var \Some\Class */ [default: true]
$parameters->set(Option::IMPORT_DOC_BLOCKS, false);

$services->set(DowngradeTrailingCommasInFunctionCallsRector::class);
$services->set(SetCookieOptionsArrayToArgumentsRector::class);
};
1 change: 1 addition & 0 deletions config/set/downgrade-php74.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@

// skip classes used in PHP DocBlocks, like in /** @var \Some\Class */ [default: true]
$parameters->set(Option::IMPORT_DOC_BLOCKS, false);

$services->set(DowngradeFreadFwriteFalsyToNegationRector::class);
$services->set(DowngradeReturnSelfTypeDeclarationRector::class);
};
1 change: 1 addition & 0 deletions config/set/downgrade-php80.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

// skip classes used in PHP DocBlocks, like in /** @var \Some\Class */ [default: true]
$parameters->set(Option::IMPORT_DOC_BLOCKS, false);

$services->set(DowngradePropertyPromotionRector::class);
$services->set(DowngradeNonCapturingCatchesRector::class);
$services->set(DowngradeMatchToSwitchRector::class);
Expand Down
6 changes: 3 additions & 3 deletions config/set/guzzle50.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Rector\Renaming\ValueObject\MethodCallRename;
use Rector\Transform\Rector\FuncCall\FuncCallToMethodCallRector;
use Rector\Transform\Rector\StaticCall\StaticCallToFuncCallRector;
use Rector\Transform\ValueObject\FuncNameToMethodCallName;
use Rector\Transform\ValueObject\FuncCallToMethodCall;
use Rector\Transform\ValueObject\StaticCallToFuncCall;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\SymfonyPhpConfig\ValueObjectInliner;
Expand All @@ -19,8 +19,8 @@
$services->set(FluentChainMethodCallToNormalMethodCallRector::class);

$configuration = [
new FuncNameToMethodCallName('GuzzleHttp\json_decode', 'GuzzleHttp\Utils', 'jsonDecode'),
new FuncNameToMethodCallName('GuzzleHttp\get_path', 'GuzzleHttp\Utils', 'getPath'),
new FuncCallToMethodCall('GuzzleHttp\json_decode', 'GuzzleHttp\Utils', 'jsonDecode'),
new FuncCallToMethodCall('GuzzleHttp\get_path', 'GuzzleHttp\Utils', 'getPath'),
];

$services->set(FuncCallToMethodCallRector::class)
Expand Down
32 changes: 16 additions & 16 deletions docs/rector_rules_overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -9544,17 +9544,17 @@ Move array argument from tests into data provider [configurable]
- class: `Rector\PHPUnit\Rector\Class_\ArrayArgumentInTestToDataProviderRector`

```php
use Rector\PHPUnit\Rector\Class_\ArrayArgumentInTestToDataProviderRector;
use Rector\PHPUnit\Rector\Class_\ArrayArgumentToDataProviderRector;
use Rector\PHPUnit\ValueObject\ArrayArgumentToDataProvider;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\SymfonyPhpConfig\ValueObjectInliner;

return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();

$services->set(ArrayArgumentInTestToDataProviderRector::class)
$services->set(ArrayArgumentToDataProviderRector::class)
->call('configure', [[
ArrayArgumentInTestToDataProviderRector::ARRAY_ARGUMENTS_TO_DATA_PROVIDERS => ValueObjectInliner::inline([
ArrayArgumentToDataProviderRector::ARRAY_ARGUMENTS_TO_DATA_PROVIDERS => ValueObjectInliner::inline([
new ArrayArgumentToDataProvider('PHPUnit\Framework\TestCase', 'doTestMultiple', 'doTestSingle', 'number'),
]),
]]);
Expand Down Expand Up @@ -13868,7 +13868,7 @@ In case you have accidentally removed use imports but code still contains partia

```php
use Rector\Restoration\Rector\Namespace_\CompleteImportForPartialAnnotationRector;
use Rector\Restoration\ValueObject\UseWithAlias;
use Rector\Restoration\ValueObject\CompleteImportForPartialAnnotation;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\SymfonyPhpConfig\ValueObjectInliner;

Expand All @@ -13878,7 +13878,7 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services->set(CompleteImportForPartialAnnotationRector::class)
->call('configure', [[
CompleteImportForPartialAnnotationRector::USE_IMPORTS_TO_RESTORE => ValueObjectInliner::inline([
new UseWithAlias('Doctrine\ORM\Mapping', 'ORM'),
new CompleteImportForPartialAnnotation('Doctrine\ORM\Mapping', 'ORM'),
]),
]]);
};
Expand Down Expand Up @@ -15411,17 +15411,17 @@ Replaces constant by value
- class: `Rector\Transform\Rector\ClassConstFetch\ClassConstFetchToStringRector`

```php
use Rector\Transform\Rector\ClassConstFetch\ClassConstFetchToStringRector;
use Rector\Transform\Rector\ClassConstFetch\ClassConstFetchToValueRector;
use Rector\Transform\ValueObject\ClassConstFetchToValue;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\SymfonyPhpConfig\ValueObjectInliner;

return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();

$services->set(ClassConstFetchToStringRector::class)
$services->set(ClassConstFetchToValueRector::class)
->call('configure', [[
ClassConstFetchToStringRector::CLASS_CONST_FETCHES_TO_VALUES => ValueObjectInliner::inline([
ClassConstFetchToValueRector::CLASS_CONST_FETCHES_TO_VALUES => ValueObjectInliner::inline([
new ClassConstFetchToValue('Nette\Configurator', 'DEVELOPMENT', 'development'),
new ClassConstFetchToValue('Nette\Configurator', 'PRODUCTION', 'production'),
]),
Expand Down Expand Up @@ -15493,7 +15493,7 @@ Turns defined function calls to local method calls.

```php
use Rector\Transform\Rector\FuncCall\FuncCallToMethodCallRector;
use Rector\Transform\ValueObject\FuncNameToMethodCallName;
use Rector\Transform\ValueObject\FuncCallToMethodCall;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\SymfonyPhpConfig\ValueObjectInliner;

Expand All @@ -15503,7 +15503,7 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services->set(FuncCallToMethodCallRector::class)
->call('configure', [[
FuncCallToMethodCallRector::FUNC_CALL_TO_CLASS_METHOD_CALL => ValueObjectInliner::inline([
new FuncNameToMethodCallName('view', 'Namespaced\SomeRenderer', 'render'),
new FuncCallToMethodCall('view', 'Namespaced\SomeRenderer', 'render'),
]),
]]);
};
Expand Down Expand Up @@ -16488,7 +16488,7 @@ Turns defined `__isset`/`__unset` calls to specific method calls.

```php
use Rector\Transform\Rector\Isset_\UnsetAndIssetToMethodCallRector;
use Rector\Transform\ValueObject\IssetUnsetToMethodCall;
use Rector\Transform\ValueObject\UnsetAndIssetToMethodCall;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\SymfonyPhpConfig\ValueObjectInliner;

Expand All @@ -16498,7 +16498,7 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services->set(UnsetAndIssetToMethodCallRector::class)
->call('configure', [[
UnsetAndIssetToMethodCallRector::ISSET_UNSET_TO_METHOD_CALL => ValueObjectInliner::inline([
new IssetUnsetToMethodCall('SomeContainer', 'hasService', 'removeService'),
new UnsetAndIssetToMethodCall('SomeContainer', 'hasService', 'removeService'),
]),
]]);
};
Expand All @@ -16516,7 +16516,7 @@ return static function (ContainerConfigurator $containerConfigurator): void {

```php
use Rector\Transform\Rector\Isset_\UnsetAndIssetToMethodCallRector;
use Rector\Transform\ValueObject\IssetUnsetToMethodCall;
use Rector\Transform\ValueObject\UnsetAndIssetToMethodCall;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\SymfonyPhpConfig\ValueObjectInliner;

Expand All @@ -16526,7 +16526,7 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services->set(UnsetAndIssetToMethodCallRector::class)
->call('configure', [[
UnsetAndIssetToMethodCallRector::ISSET_UNSET_TO_METHOD_CALL => ValueObjectInliner::inline([
new IssetUnsetToMethodCall('SomeContainer', 'hasService', 'removeService'),
new UnsetAndIssetToMethodCall('SomeContainer', 'hasService', 'removeService'),
]),
]]);
};
Expand Down Expand Up @@ -16967,7 +16967,7 @@ Change visibility of constant from parent class.

```php
use Rector\Visibility\Rector\ClassConst\ChangeConstantVisibilityRector;
use Rector\Visibility\ValueObject\ClassConstantVisibilityChange;
use Rector\Visibility\ValueObject\ChangeConstantVisibility;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Symplify\SymfonyPhpConfig\ValueObjectInliner;

Expand All @@ -16977,7 +16977,7 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services->set(ChangeConstantVisibilityRector::class)
->call('configure', [[
ChangeConstantVisibilityRector::CLASS_CONSTANT_VISIBILITY_CHANGES => ValueObjectInliner::inline([
new ClassConstantVisibilityChange('ParentObject', 'SOME_CONSTANT', 2),
new ChangeConstantVisibility('ParentObject', 'SOME_CONSTANT', 2),
]),
]]);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ declare(strict_types=1);
namespace Rector\__Package__\Tests\Rector\__Category__\__Name__;

use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use Symplify\SmartFileSystem\SmartFileInfo;

final class __Name__Test extends AbstractRectorTestCase
{
Expand All @@ -22,14 +23,8 @@ final class __Name__Test extends AbstractRectorTestCase
yield [new \Symplify\SmartFileSystem\SmartFileInfo(__DIR__ . '/Fixture/some_class.php.inc'), '__ExtraFileName__', __DIR__ . '/Source/extra_file.php'];
}

/**
* @return mixed[]
*/
protected function getRectorsWithConfiguration(): array
protected function provideConfigFileInfo(): ?\Symplify\SmartFileSystem\SmartFileInfo
{
return [
\Rector\__Package__\Rector\__Category__\__Name__::class =>
__TestRuleConfiguration__
];
return new \Symplify\SmartFileSystem\SmartFileInfo(__DIR__ . '/configured_rule.php');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,8 @@ final class __Name__Test extends AbstractRectorTestCase
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
}

/**
* @return mixed[]
*/
protected function getRectorsWithConfiguration(): array
protected function provideConfigFileInfo(): ?\Symplify\SmartFileSystem\SmartFileInfo
{
return [
\Rector\__Package__\Rector\__Category__\__Name__::class =>
__TestRuleConfiguration__
];
return new \Symplify\SmartFileSystem\SmartFileInfo(__DIR__ . '/configured_rule.php');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,8 @@ final class WhateverRectorTest extends AbstractRectorTestCase
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
}

/**
* @return mixed[]
*/
protected function getRectorsWithConfiguration(): array
protected function provideConfigFileInfo(): ?\Symplify\SmartFileSystem\SmartFileInfo
{
return [
\Rector\ModeratePackage\Rector\MethodCall\WhateverRector::class =>
[\Rector\ModeratePackage\Rector\MethodCall\WhateverRector::CLASS_TYPE_TO_METHOD_NAME => ['SomeClass' => 'configure']]
];
return new \Symplify\SmartFileSystem\SmartFileInfo(__DIR__ . '/configured_rule.php');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,8 @@ final class WhateverRectorTest extends AbstractRectorTestCase
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
}

/**
* @return mixed[]
*/
protected function getRectorsWithConfiguration(): array
protected function provideConfigFileInfo(): ?\Symplify\SmartFileSystem\SmartFileInfo
{
return [
\Utils\Rector\Rector\MethodCall\WhateverRector::class =>
[\Utils\Rector\Rector\MethodCall\WhateverRector::CLASS_TYPE_TO_METHOD_NAME => ['SomeClass' => 'configure']]
];
return new \Symplify\SmartFileSystem\SmartFileInfo(__DIR__ . '/configured_rule.php');
}
}
56 changes: 3 additions & 53 deletions packages/testing/src/PHPUnit/AbstractRectorTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
use Rector\Core\Stubs\StubLoader;
use Rector\Core\ValueObject\PhpVersion;
use Rector\Core\ValueObject\StaticNonPhpFileSuffixes;
use Rector\Naming\Tests\Rector\Class_\RenamePropertyToMatchTypeRector\Source\ContainerInterface;
use Rector\Testing\Application\EnabledRectorsProvider;
use Rector\Testing\Contract\RunnableInterface;
use Rector\Testing\Finder\RectorsFinder;
Expand All @@ -31,8 +30,6 @@
use Rector\Testing\ValueObject\InputFilePathWithExpectedFile;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\HttpKernel\KernelInterface;
use Symplify\EasyTesting\DataProvider\StaticFixtureFinder;
use Symplify\EasyTesting\DataProvider\StaticFixtureUpdater;
use Symplify\EasyTesting\StaticFixtureSplitter;
Expand Down Expand Up @@ -97,7 +94,7 @@ abstract class AbstractRectorTestCase extends AbstractKernelTestCase
protected $originalTempFileInfo;

/**
* @var Container|ContainerInterface|null
* @var SmartFileInfo
*/
protected static $allRectorContainer;

Expand Down Expand Up @@ -125,7 +122,7 @@ protected function setUp(): void
if ($this->provideConfigFileInfo() !== null) {
$configFileInfos = $this->resolveConfigs($this->provideConfigFileInfo());

$this->bootKernelWithConfigInfos(RectorKernel::class, $configFileInfos);
$this->bootKernelWithConfigs(RectorKernel::class, $configFileInfos);

$enabledRectorsProvider = $this->getService(EnabledRectorsProvider::class);
$enabledRectorsProvider->reset();
Expand Down Expand Up @@ -198,31 +195,8 @@ protected function provideConfigFileInfo(): ?SmartFileInfo
return null;
}

/**
* @deprecated Use config instead, just to narrow 2 ways to add configured config to just 1. Now
* with PHP its easy pick.
*
* @return mixed[]
*/
protected function getRectorsWithConfiguration(): array
{
// can be implemented, has the highest priority
return [];
}

/**
* @return mixed[]
*/
protected function getCurrentTestRectorClassesWithConfiguration(): array
{
if ($this->getRectorsWithConfiguration() !== []) {
foreach (array_keys($this->getRectorsWithConfiguration()) as $rectorClass) {
$this->ensureRectorClassIsValid($rectorClass, 'getRectorsWithConfiguration');
}

return $this->getRectorsWithConfiguration();
}

$rectorClass = $this->getRectorClass();
$this->ensureRectorClassIsValid($rectorClass, 'getRectorClass');

Expand Down Expand Up @@ -251,37 +225,12 @@ protected function setParameter(string $name, $value): void
$parameterProvider->changeParameter($name, $value);
}

/**
* @deprecated Will be supported in Symplify 9
* @param SmartFileInfo[] $configFileInfos
*/
protected function bootKernelWithConfigInfos(string $class, array $configFileInfos): KernelInterface
{
$configFiles = [];
foreach ($configFileInfos as $configFileInfo) {
$configFiles[] = $configFileInfo->getRealPath();
}

return $this->bootKernelWithConfigs($class, $configFiles);
}

protected function getPhpVersion(): int
{
// to be implemented
return self::PHP_VERSION_UNDEFINED;
}

protected function assertFileMissing(string $temporaryFilePath): void
{
// PHPUnit 9.0 ready
if (method_exists($this, 'assertFileDoesNotExist')) {
$this->assertFileDoesNotExist($temporaryFilePath);
} else {
// PHPUnit 8.0 ready
$this->assertFileNotExists($temporaryFilePath);
}
}

protected function doTestFileInfoWithoutAutoload(SmartFileInfo $fileInfo): void
{
$this->autoloadTestFixture = false;
Expand Down Expand Up @@ -518,6 +467,7 @@ private function createContainerWithAllRectors(): void
$coreRectorClasses = $rectorsFinder->findCoreRectorClasses();

$listForConfig = [];

foreach ($coreRectorClasses as $rectorClass) {
$listForConfig[$rectorClass] = null;
}
Expand Down
Loading

0 comments on commit 5c0a574

Please sign in to comment.