-
-
Notifications
You must be signed in to change notification settings - Fork 339
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
187 additions
and
0 deletions.
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 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 | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
php_version: ['8.1'] | ||
directory: | ||
- 'e2e/applied-rule-removed-node-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 ../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 }} |
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 | ||
} |
40 changes: 40 additions & 0 deletions
40
e2e/applied-rule-removed-node-with-cache/expected-output.diff
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,40 @@ | ||
2 files with changes | ||
==================== | ||
|
||
1) src/DeadConstructor.php:1 | ||
|
||
---------- begin diff ---------- | ||
@@ @@ | ||
|
||
final class DeadConstructor | ||
{ | ||
- public function __construct() | ||
- { | ||
- } | ||
} | ||
----------- end diff ----------- | ||
|
||
Applied rules: | ||
* RemoveEmptyClassMethodRector | ||
|
||
|
||
2) src/AlwaysTrue.php:3 | ||
|
||
---------- begin diff ---------- | ||
@@ @@ | ||
{ | ||
public function run() | ||
{ | ||
- if (1 === 1) { | ||
- } | ||
- | ||
return 'no'; | ||
} | ||
} | ||
----------- end diff ----------- | ||
|
||
Applied rules: | ||
* RemoveAlwaysTrueIfConditionRector | ||
|
||
|
||
[OK] 2 files would have changed (dry-run) 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\Config\RectorConfig; | ||
use Rector\DeadCode\Rector\ClassMethod\RemoveEmptyClassMethodRector; | ||
use Rector\DeadCode\Rector\If_\RemoveAlwaysTrueIfConditionRector; | ||
|
||
return static function (RectorConfig $rectorConfig): void { | ||
$rectorConfig->cacheClass(FileCacheStorage::class); | ||
|
||
$rectorConfig->paths([ | ||
__DIR__ . '/src', | ||
]); | ||
|
||
$rectorConfig->rule(RemoveEmptyClassMethodRector::class); | ||
$rectorConfig->rule(RemoveAlwaysTrueIfConditionRector::class); | ||
}; |
12 changes: 12 additions & 0 deletions
12
e2e/applied-rule-removed-node-with-cache/src/AlwaysTrue.php
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,12 @@ | ||
<?php | ||
|
||
final class AlwaysTrue | ||
{ | ||
public function run() | ||
{ | ||
if (1 === 1) { | ||
} | ||
|
||
return 'no'; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
e2e/applied-rule-removed-node-with-cache/src/DeadConstructor.php
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 | ||
|
||
final class DeadConstructor | ||
{ | ||
public function __construct() | ||
{ | ||
} | ||
} |
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,48 @@ | ||
#!/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 SebastianBergmann\Diff\Differ; | ||
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 --dry-run --no-ansi -a '. $autoloadFile; | ||
|
||
exec($e2eCommand, $output, $exitCode); | ||
$output = trim(implode("\n", $output)); | ||
$output = str_replace(__DIR__, '.', $output); | ||
|
||
$expectedDiff = 'expected-output.diff'; | ||
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); |