diff --git a/.github/workflows/e2e_consecutive_changes.yaml b/.github/workflows/e2e_consecutive_changes.yaml new file mode 100644 index 00000000000..f3be9164276 --- /dev/null +++ b/.github/workflows/e2e_consecutive_changes.yaml @@ -0,0 +1,52 @@ +# 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 consecutive changes + +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 + strategy: + fail-fast: false + matrix: + php_version: ['8.1'] + directory: + - 'e2e/consecutive-changes-with-cache' + + name: End to end test - ${{ matrix.directory }} + + steps: + - uses: actions/checkout@v3 + + - 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 ../e2eTestChangingRunnerWithCache.php -o expected-output-1.diff + working-directory: ${{ matrix.directory }} + + # this tests that a 2nd run with cache and consecutive changes works, see https://github.com/rectorphp/rector-src/pull/3614#issuecomment-1507742338 + - run: php ../e2eTestChangingRunnerWithCache.php -o expected-output-2.diff + working-directory: ${{ matrix.directory }} diff --git a/e2e/consecutive-changes-with-cache/.gitignore b/e2e/consecutive-changes-with-cache/.gitignore new file mode 100644 index 00000000000..61ead86667c --- /dev/null +++ b/e2e/consecutive-changes-with-cache/.gitignore @@ -0,0 +1 @@ +/vendor diff --git a/e2e/consecutive-changes-with-cache/composer.json b/e2e/consecutive-changes-with-cache/composer.json new file mode 100644 index 00000000000..5468cd74606 --- /dev/null +++ b/e2e/consecutive-changes-with-cache/composer.json @@ -0,0 +1,7 @@ +{ + "require": { + "php": "^8.1" + }, + "minimum-stability": "dev", + "prefer-stable": true +} diff --git a/e2e/consecutive-changes-with-cache/expected-output-1.diff b/e2e/consecutive-changes-with-cache/expected-output-1.diff new file mode 100644 index 00000000000..b0c4248c851 --- /dev/null +++ b/e2e/consecutive-changes-with-cache/expected-output-1.diff @@ -0,0 +1,27 @@ +1 file with changes +=================== + +1) src/Source.php:1 + + ---------- begin diff ---------- +@@ @@ + + $a = true; + $b = true; +- +-if ($a && $b) { +- return true; ++if (!$a) { ++ return; + } ++if (!$b) { ++ return; ++} ++return true; + ----------- end diff ----------- + +Applied rules: + * ChangeAndIfToEarlyReturnRector + + + [OK] 1 file has been changed by Rector diff --git a/e2e/consecutive-changes-with-cache/expected-output-2.diff b/e2e/consecutive-changes-with-cache/expected-output-2.diff new file mode 100644 index 00000000000..fe9f908413f --- /dev/null +++ b/e2e/consecutive-changes-with-cache/expected-output-2.diff @@ -0,0 +1,23 @@ + 1 file with changes +=================== + +1) src/Source.php:4 + + ---------- begin diff ---------- +@@ @@ + if (!$a) { + return; + } ++ + if (!$b) { + return; + } ++ + return true; + ----------- end diff ----------- + +Applied rules: + * NewlineAfterStatementRector + + + [OK] 1 file has been changed by Rector diff --git a/e2e/consecutive-changes-with-cache/rector.php b/e2e/consecutive-changes-with-cache/rector.php new file mode 100644 index 00000000000..f8ea9dfeb9a --- /dev/null +++ b/e2e/consecutive-changes-with-cache/rector.php @@ -0,0 +1,19 @@ +cacheClass(FileCacheStorage::class); + + $rectorConfig->paths([ + __DIR__ . '/src', + ]); + + $rectorConfig->rule(ChangeAndIfToEarlyReturnRector::class); + $rectorConfig->rule(NewlineAfterStatementRector::class); +}; diff --git a/e2e/consecutive-changes-with-cache/src/Source.php b/e2e/consecutive-changes-with-cache/src/Source.php new file mode 100644 index 00000000000..823bcc14174 --- /dev/null +++ b/e2e/consecutive-changes-with-cache/src/Source.php @@ -0,0 +1,8 @@ +create(); + +$matchedExpectedOutput = false; +$expectedOutput = trim(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 +$consoleDiffer = new ConsoleDiffer(new ColorConsoleDiffFormatter()); +$diff = $consoleDiffer->diff($output, $expectedOutput); +$symfonyStyle->writeln($diff); + +exit(Command::FAILURE);