diff --git a/.github/workflows/e2e_with_cache.yaml b/.github/workflows/e2e_with_cache.yaml deleted file mode 100644 index 7c04221333c..00000000000 --- a/.github/workflows/e2e_with_cache.yaml +++ /dev/null @@ -1,54 +0,0 @@ -# This workflow runs system tests: Use the Rector application from the source -# checkout to process "fixture" projects in e2e/ directory -# to see if those can be processed successfully -name: End to End tests with cache - -on: - pull_request: - branches: - - main - push: - branches: - - main - -env: - # see https://github.com/composer/composer/issues/9368#issuecomment-718112361 - COMPOSER_ROOT_VERSION: "dev-main" - -jobs: - end_to_end: - runs-on: ubuntu-latest - timeout-minutes: 3 - strategy: - fail-fast: false - matrix: - php_version: ['8.4'] - directory: - - 'e2e/applied-rule-removed-node-with-cache' - - 'e2e/timeout-file-not-cached' - - name: End to end test - ${{ matrix.directory }} - - steps: - - uses: actions/checkout@v5 - - - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php_version }} - coverage: none - - # run in root rector-src - - run: composer install --ansi - - # run in e2e subdir - - - run: composer install --ansi - working-directory: ${{ matrix.directory }} - - # run e2e test - - run: php ../e2eTestRunner.php - working-directory: ${{ matrix.directory }} - - # this tests that a 2nd run with cache and "--dry-run" gives same results, see https://github.com/rectorphp/rector-src/pull/3614#issuecomment-1507742338 - - run: php ../e2eTestRunnerWithCache.php - working-directory: ${{ matrix.directory }} diff --git a/config/config.php b/config/config.php index b1afe8533af..db093de4e03 100644 --- a/config/config.php +++ b/config/config.php @@ -2,9 +2,7 @@ declare(strict_types=1); -use OndraM\CiDetector\CiDetector; use Rector\Bootstrap\ExtensionConfigResolver; -use Rector\Caching\ValueObject\Storage\MemoryCacheStorage; use Rector\Config\RectorConfig; return static function (RectorConfig $rectorConfig): void { @@ -27,12 +25,6 @@ $rectorConfig->cacheDirectory(sys_get_temp_dir() . '/rector_cached_files'); $rectorConfig->containerCacheDirectory(sys_get_temp_dir()); - // use faster in-memory cache in CI. - // CI always starts from scratch, therefore IO intensive caching is not worth it - if (new CiDetector()->isCiDetected()) { - $rectorConfig->cacheClass(MemoryCacheStorage::class); - } - // load internal rector-* extension configs $extensionConfigResolver = new ExtensionConfigResolver(); foreach ($extensionConfigResolver->provide() as $extensionConfigFile) { diff --git a/e2e/applied-rule-removed-node-with-cache/.gitignore b/e2e/applied-rule-removed-node-with-cache/.gitignore deleted file mode 100644 index 61ead86667c..00000000000 --- a/e2e/applied-rule-removed-node-with-cache/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/vendor diff --git a/e2e/applied-rule-removed-node-with-cache/composer.json b/e2e/applied-rule-removed-node-with-cache/composer.json deleted file mode 100644 index 5468cd74606..00000000000 --- a/e2e/applied-rule-removed-node-with-cache/composer.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "require": { - "php": "^8.1" - }, - "minimum-stability": "dev", - "prefer-stable": true -} diff --git a/e2e/applied-rule-removed-node-with-cache/expected-output.diff b/e2e/applied-rule-removed-node-with-cache/expected-output.diff deleted file mode 100644 index 94f3ee2fa9d..00000000000 --- a/e2e/applied-rule-removed-node-with-cache/expected-output.diff +++ /dev/null @@ -1,40 +0,0 @@ -2 files with changes -==================== - -1) src/AlwaysTrue.php:4 - - ---------- begin diff ---------- -@@ Line 4 @@ - { - public function run() - { -- if (1 === 1) { -- } -- - return 'no'; - } - } - ----------- end diff ----------- - -Applied rules: - * RemoveAlwaysTrueIfConditionRector - - -2) src/DeadConstructor.php:2 - - ---------- begin diff ---------- -@@ Line 2 @@ - - final class DeadConstructor - { -- public function __construct() -- { -- } - } - ----------- end diff ----------- - -Applied rules: - * RemoveEmptyClassMethodRector - - - [OK] 2 files would have been changed (dry-run) by Rector diff --git a/e2e/applied-rule-removed-node-with-cache/rector.php b/e2e/applied-rule-removed-node-with-cache/rector.php deleted file mode 100644 index 84cdd17281d..00000000000 --- a/e2e/applied-rule-removed-node-with-cache/rector.php +++ /dev/null @@ -1,19 +0,0 @@ -cacheClass(FileCacheStorage::class); - - $rectorConfig->paths([ - __DIR__ . '/src', - ]); - - $rectorConfig->rule(RemoveEmptyClassMethodRector::class); - $rectorConfig->rule(RemoveAlwaysTrueIfConditionRector::class); -}; diff --git a/e2e/applied-rule-removed-node-with-cache/src/AlwaysTrue.php b/e2e/applied-rule-removed-node-with-cache/src/AlwaysTrue.php deleted file mode 100644 index 7b70b9e9ccd..00000000000 --- a/e2e/applied-rule-removed-node-with-cache/src/AlwaysTrue.php +++ /dev/null @@ -1,12 +0,0 @@ -create(); - -$matchedExpectedOutput = false; -$expectedOutput = trim((string) file_get_contents($expectedDiff)); -if ($output === $expectedOutput) { - $symfonyStyle->success('End-to-end test successfully completed'); - exit(Command::SUCCESS); -} - -// print color diff, to make easy find the differences -$defaultDiffer = new DefaultDiffer(); -$colorConsoleDiffFormatter = new ColorConsoleDiffFormatter(); -$diff = $colorConsoleDiffFormatter->format($defaultDiffer->diff($output, $expectedOutput)); -$symfonyStyle->writeln($diff); - -exit(Command::FAILURE); diff --git a/e2e/timeout-file-not-cached/.gitignore b/e2e/timeout-file-not-cached/.gitignore deleted file mode 100644 index 61ead86667c..00000000000 --- a/e2e/timeout-file-not-cached/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/vendor diff --git a/e2e/timeout-file-not-cached/composer.json b/e2e/timeout-file-not-cached/composer.json deleted file mode 100644 index 5468cd74606..00000000000 --- a/e2e/timeout-file-not-cached/composer.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "require": { - "php": "^8.1" - }, - "minimum-stability": "dev", - "prefer-stable": true -} diff --git a/e2e/timeout-file-not-cached/expected-output.diff b/e2e/timeout-file-not-cached/expected-output.diff deleted file mode 100644 index 26cd1063c43..00000000000 --- a/e2e/timeout-file-not-cached/expected-output.diff +++ /dev/null @@ -1,7 +0,0 @@ -[ERROR] Could not process - "/home/runner/work/rector-src/rector-src/vendor/symplify/easy-parallel/ - src/ValueObject/ParallelProcess.php" file, due to: - "Child process timed out after 0 seconds". On line: 105 - - [ERROR] Could not process some files, due to: - "Reached system errors count limit of 50, exiting...". diff --git a/e2e/timeout-file-not-cached/rector.php b/e2e/timeout-file-not-cached/rector.php deleted file mode 100644 index b6053d61914..00000000000 --- a/e2e/timeout-file-not-cached/rector.php +++ /dev/null @@ -1,18 +0,0 @@ -cacheClass(FileCacheStorage::class); - $rectorConfig->parallel(0); - - $rectorConfig->paths([ - __DIR__ . '/src', - ]); - - $rectorConfig->sets([LevelSetList::UP_TO_PHP_82]); -}; diff --git a/e2e/timeout-file-not-cached/src/SomeFixturePrinter.php b/e2e/timeout-file-not-cached/src/SomeFixturePrinter.php deleted file mode 100644 index 69ed3a47227..00000000000 --- a/e2e/timeout-file-not-cached/src/SomeFixturePrinter.php +++ /dev/null @@ -1,9 +0,0 @@ -isCiDetected()) { + return new Cache(new MemoryCacheStorage()); } - if ($cacheClass === FileCacheStorage::class) { - // ensure cache directory exists - if (! $this->fileSystem->exists($cacheDirectory)) { - $this->fileSystem->mkdir($cacheDirectory); - } + $cacheDirectory = SimpleParameterProvider::provideStringParameter(Option::CACHE_DIR); - $fileCacheStorage = new FileCacheStorage($cacheDirectory, $this->fileSystem); - return new Cache($fileCacheStorage); + // ensure cache directory exists + if (! $this->fileSystem->exists($cacheDirectory)) { + $this->fileSystem->mkdir($cacheDirectory); } - return new Cache(new MemoryCacheStorage()); + $fileCacheStorage = new FileCacheStorage($cacheDirectory, $this->fileSystem); + return new Cache($fileCacheStorage); } } diff --git a/src/Config/RectorConfig.php b/src/Config/RectorConfig.php index 1f4581bb286..ef492c30300 100644 --- a/src/Config/RectorConfig.php +++ b/src/Config/RectorConfig.php @@ -431,11 +431,14 @@ public function containerCacheDirectory(string $directoryPath): void /** * @param class-string $cacheClass */ + #[Deprecated(message: <<<'TXT' + Cache storage is selected automatically: file cache locally, in-memory cache in CI, + where the ephemeral workspace makes writing a cache that is never re-read wasted IO. + The passed value is ignored. + TXT)] public function cacheClass(string $cacheClass): void { Assert::isAOf($cacheClass, CacheStorageInterface::class); - - SimpleParameterProvider::setParameter(Option::CACHE_CLASS, $cacheClass); } /** diff --git a/src/Configuration/Option.php b/src/Configuration/Option.php index 6c3ddb126fe..e5fd0c98457 100644 --- a/src/Configuration/Option.php +++ b/src/Configuration/Option.php @@ -4,9 +4,6 @@ namespace Rector\Configuration; -use Rector\Caching\Contract\ValueObject\Storage\CacheStorageInterface; -use Rector\Caching\ValueObject\Storage\FileCacheStorage; - final class Option { public const string SOURCE = 'source'; @@ -145,15 +142,6 @@ final class Option */ public const string CACHE_DIR = 'cache_dir'; - /** - * Cache backend. Most of the time we cache in files, but in ephemeral environment (e.g. CI), a faster `MemoryCacheStorage` can be useful. - * @internal Use RectorConfig::cacheClass() instead - * - * @var class-string - * @internal - */ - public const string CACHE_CLASS = FileCacheStorage::class; - public const string DEBUG = 'debug'; public const string XDEBUG = 'xdebug'; diff --git a/src/Configuration/RectorConfigBuilder.php b/src/Configuration/RectorConfigBuilder.php index 97411cb1c03..cb62b024e18 100644 --- a/src/Configuration/RectorConfigBuilder.php +++ b/src/Configuration/RectorConfigBuilder.php @@ -103,11 +103,6 @@ final class RectorConfigBuilder */ private array $fileExtensions = []; - /** - * @var null|class-string - */ - private ?string $cacheClass = null; - private ?string $cacheDirectory = null; private ?string $containerCacheDirectory = null; @@ -314,10 +309,6 @@ public function __invoke(RectorConfig $rectorConfig): void $rectorConfig->fileExtensions($this->fileExtensions); } - if ($this->cacheClass !== null) { - $rectorConfig->cacheClass($this->cacheClass); - } - if ($this->cacheDirectory !== null) { $rectorConfig->cacheDirectory($this->cacheDirectory); } @@ -830,6 +821,9 @@ public function withFileExtensions(array $fileExtensions): self } /** + * The $cacheClass argument is deprecated and ignored. Cache storage is selected automatically: + * file cache locally, in-memory cache in CI. + * * @param class-string|null $cacheClass */ public function withCache( @@ -838,7 +832,6 @@ public function withCache( ?string $containerCacheDirectory = null ): self { $this->cacheDirectory = $cacheDirectory; - $this->cacheClass = $cacheClass; $this->containerCacheDirectory = $containerCacheDirectory; return $this; diff --git a/tests/Caching/Detector/config.php b/tests/Caching/Detector/config.php index 5e535c343a8..5e5a9c61284 100644 --- a/tests/Caching/Detector/config.php +++ b/tests/Caching/Detector/config.php @@ -2,10 +2,8 @@ declare(strict_types=1); -use Rector\Caching\ValueObject\Storage\MemoryCacheStorage; use Rector\Config\RectorConfig; return static function (RectorConfig $rectorConfig): void { $rectorConfig->cacheDirectory(sys_get_temp_dir() . '/_rector_cached_files_test'); - $rectorConfig->cacheClass(MemoryCacheStorage::class); }; diff --git a/tests/Caching/ValueObject/Storage/config.php b/tests/Caching/ValueObject/Storage/config.php index 5e535c343a8..5e5a9c61284 100644 --- a/tests/Caching/ValueObject/Storage/config.php +++ b/tests/Caching/ValueObject/Storage/config.php @@ -2,10 +2,8 @@ declare(strict_types=1); -use Rector\Caching\ValueObject\Storage\MemoryCacheStorage; use Rector\Config\RectorConfig; return static function (RectorConfig $rectorConfig): void { $rectorConfig->cacheDirectory(sys_get_temp_dir() . '/_rector_cached_files_test'); - $rectorConfig->cacheClass(MemoryCacheStorage::class); };