-
-
Notifications
You must be signed in to change notification settings - Fork 333
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add e2e tests for consecutive changing runs #3666
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/vendor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"require": { | ||
"php": "^8.1" | ||
}, | ||
"minimum-stability": "dev", | ||
"prefer-stable": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rector\Caching\ValueObject\Storage\FileCacheStorage; | ||
use Rector\CodingStyle\Rector\Stmt\NewlineAfterStatementRector; | ||
use Rector\Config\RectorConfig; | ||
use Rector\EarlyReturn\Rector\If_\ChangeAndIfToEarlyReturnRector; | ||
|
||
return static function (RectorConfig $rectorConfig): void { | ||
$rectorConfig->cacheClass(FileCacheStorage::class); | ||
|
||
$rectorConfig->paths([ | ||
__DIR__ . '/src', | ||
]); | ||
|
||
$rectorConfig->rule(ChangeAndIfToEarlyReturnRector::class); | ||
$rectorConfig->rule(NewlineAfterStatementRector::class); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
$a = true; | ||
$b = true; | ||
|
||
if ($a && $b) { | ||
return true; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
|
||
// runs a rector e2e test. | ||
// checks whether we expect a certain output, or alternatively that rector just processed everything without errors | ||
|
||
use Rector\Core\Console\Formatter\ColorConsoleDiffFormatter; | ||
use Rector\Core\Console\Formatter\ConsoleDiffer; | ||
use Rector\Core\Console\Style\SymfonyStyleFactory; | ||
use Rector\Core\Util\Reflection\PrivatesAccessor; | ||
use Symfony\Component\Console\Command\Command; | ||
|
||
$projectRoot = __DIR__ .'/..'; | ||
$rectorBin = $projectRoot . '/bin/rector'; | ||
$autoloadFile = $projectRoot . '/vendor/autoload.php'; | ||
|
||
// so we can use helper classes here | ||
require_once __DIR__ . '/../vendor/autoload.php'; | ||
|
||
$e2eCommand = 'php '. $rectorBin .' process --no-ansi -a '. $autoloadFile; | ||
|
||
if (isset($argv[1]) && $argv[1] === '-o') { | ||
$expectedDiff = $argv[2]; | ||
} else { | ||
$expectedDiff = 'expected-output.diff'; | ||
} | ||
Comment on lines
+22
to
+26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and adds support for a specific expected output file |
||
|
||
exec($e2eCommand, $output, $exitCode); | ||
$output = trim(implode("\n", $output)); | ||
$output = str_replace(__DIR__, '.', $output); | ||
|
||
if (!file_exists($expectedDiff)) { | ||
echo $output; | ||
exit($exitCode); | ||
} | ||
|
||
$symfonyStyleFactory = new SymfonyStyleFactory(new PrivatesAccessor()); | ||
$symfonyStyle = $symfonyStyleFactory->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); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this new runner removed the
--dry-run
option