From 556a1d792599e3b975121ccf6d9ccc3745b814cb Mon Sep 17 00:00:00 2001 From: Markus Gerdes Date: Wed, 24 Jul 2024 13:28:13 +0200 Subject: [PATCH 01/12] fix: import the fractor configuration if found in fractor.php file Otherwise there was an error: ``` FRACTOR: Fatal error: Uncaught TypeError: a9f\Fractor\Configuration\FractorConfigurationBuilder::__invoke(): Argument #1 ($containerConfigurator) must be of type Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator, a9f\Fractor\Configuration\FractorConfigurationBuilder given, called in /var/www/html/lifter/vendor/a9f/lifter/res/run_fractor.php on line 19 and defined in /var/www/html/lifter/vendor/a9f/fractor/src/Configuration/FractorConfigurationBuilder.php:49 ``` --- res/run_fractor.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/res/run_fractor.php b/res/run_fractor.php index e05981a..3950f1a 100644 --- a/res/run_fractor.php +++ b/res/run_fractor.php @@ -14,9 +14,7 @@ if (!is_string($fractorConfigFile)) { throw new \RuntimeException('No file passed in env variable FRACTOR_CONFIG_FILE', 1712507292); } - $fractorConfigClosure = (require $fractorConfigFile); - Assert::isCallable($fractorConfigClosure, 'FRACTOR_CONFIG_FILE did not yield a callable'); - $fractorConfigClosure($fractorConfig); + $fractorConfig->import($fractorConfigFile); $lifterConfigFile = getenv('LIFTER_CONFIG_FILE'); if (!is_string($lifterConfigFile)) { From 764321f440e04cc763c00ad29e97af061c5fdbb8 Mon Sep 17 00:00:00 2001 From: Markus Gerdes <107911221+mgerdes-atl@users.noreply.github.com> Date: Tue, 3 Dec 2024 14:05:23 +0100 Subject: [PATCH 02/12] Additonally allow Fractor 0.4 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 33d5173..f9ac32e 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ ], "require": { "php": "^8.2", - "a9f/fractor": "^0.3", + "a9f/fractor": "^0.3 || ^0.4", "rector/rector": "^1.0", "symfony/config": "^6.4 || ^7.0", "symfony/console": "^6.4 || ^7.0", From 9cb15ed481b041882cf1234cfd257a9ce699c34b Mon Sep 17 00:00:00 2001 From: Andreas Wolf Date: Mon, 16 Dec 2024 15:24:18 +0100 Subject: [PATCH 03/12] fix: Use new Fractor config in e2e tests --- e2e/fractor/fractor.php | 7 +++---- e2e/fractor/lifter.php | 14 +++++++------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/e2e/fractor/fractor.php b/e2e/fractor/fractor.php index 61e6515..3682131 100644 --- a/e2e/fractor/fractor.php +++ b/e2e/fractor/fractor.php @@ -1,7 +1,6 @@ withPaths([__DIR__ . '/result/**']); \ No newline at end of file diff --git a/e2e/fractor/lifter.php b/e2e/fractor/lifter.php index 8711ed7..40133d9 100644 --- a/e2e/fractor/lifter.php +++ b/e2e/fractor/lifter.php @@ -17,13 +17,13 @@ new FractorStep( 'Update phpunit/phpunit to 11.x', static function (FractorConfigurationBuilder $fractorConfig) { - $fractorConfig->withPaths([__DIR__ . '/result/**']); - $fractorConfig->withConfiguredRule( - ChangePackageVersionComposerJsonFractor::class, - [ - new PackageAndVersion('phpunit/phpunit', '^11.2') - ] - ); + return $fractorConfig + ->withConfiguredRule( + ChangePackageVersionComposerJsonFractor::class, + [ + new PackageAndVersion('phpunit/phpunit', '^11.2') + ] + ); } ) ]); From e2d01dfe8f9336f8546d3ca1913e9203680b6832 Mon Sep 17 00:00:00 2001 From: Andreas Wolf Date: Mon, 16 Dec 2024 15:25:49 +0100 Subject: [PATCH 04/12] cleanup: Remove unused import --- res/run_fractor.php | 1 - 1 file changed, 1 deletion(-) diff --git a/res/run_fractor.php b/res/run_fractor.php index 3950f1a..4a11068 100644 --- a/res/run_fractor.php +++ b/res/run_fractor.php @@ -4,7 +4,6 @@ use a9f\Lifter\Configuration\LifterConfigFactory; use a9f\Lifter\Upgrade\Step\FractorStep; use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; -use Webmozart\Assert\Assert; return static function (ContainerConfigurator $configurator) { $fractorConfig = FractorConfiguration::configure(); From 0ff4c096e8a707faae2ced755d6a8e94c6c69541 Mon Sep 17 00:00:00 2001 From: Andreas Wolf Date: Mon, 16 Dec 2024 15:24:18 +0100 Subject: [PATCH 05/12] Drop support for Fractor < 0.5, add 0.5 Fractor 0.4 changed the config format, and 0.5 introduced the cache that we need to disable, thus we cannot support 0.4/0.5at the same time. --- composer.json | 2 +- e2e/composer.json | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index f9ac32e..c1526f9 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ ], "require": { "php": "^8.2", - "a9f/fractor": "^0.3 || ^0.4", + "a9f/fractor": "^0.5", "rector/rector": "^1.0", "symfony/config": "^6.4 || ^7.0", "symfony/console": "^6.4 || ^7.0", diff --git a/e2e/composer.json b/e2e/composer.json index 0f49140..c775f8c 100644 --- a/e2e/composer.json +++ b/e2e/composer.json @@ -3,10 +3,10 @@ "type": "project", "require": { "a9f/lifter": "@dev", - "a9f/fractor": "^0.3", - "a9f/fractor-composer-json": "^0.3", - "a9f/fractor-doc-generator": "^0.3", - "a9f/fractor-extension-installer": "^0.3", + "a9f/fractor": "^0.4 || ^0.5", + "a9f/fractor-composer-json": "^0.4 || ^0.5", + "a9f/fractor-doc-generator": "^0.4 || ^0.5", + "a9f/fractor-extension-installer": "^0.4 || ^0.5", "symplify/rule-doc-generator-contracts": "^11.2" }, "require-dev": { From f34494f6c99b505097488190c0bcefc1c88a72ca Mon Sep 17 00:00:00 2001 From: Andreas Wolf Date: Mon, 16 Dec 2024 15:38:47 +0100 Subject: [PATCH 06/12] fix: Adjust expected test output for Rector --- e2e/rector/expected-output.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/e2e/rector/expected-output.txt b/e2e/rector/expected-output.txt index 632fde4..95446e1 100644 --- a/e2e/rector/expected-output.txt +++ b/e2e/rector/expected-output.txt @@ -1,3 +1,4 @@ RECTOR: RECTOR: [OK] 1 file has been changed by Rector +RECTOR: From 72390047455afc0c90dd87c6b7d5d18fda0aad3c Mon Sep 17 00:00:00 2001 From: Andreas Wolf Date: Mon, 19 May 2025 18:56:47 +0200 Subject: [PATCH 07/12] Add missing test in CI --- e2e/run-test.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/e2e/run-test.sh b/e2e/run-test.sh index ffa45cd..642f00d 100755 --- a/e2e/run-test.sh +++ b/e2e/run-test.sh @@ -49,6 +49,7 @@ run_test() { if [ $# -eq 0 ] then run_test fractor + run_test missing-config-file run_test rector else for test in $@ From 768980344e67a50daa97979e4da6929633e23d74 Mon Sep 17 00:00:00 2001 From: Andreas Wolf Date: Mon, 19 May 2025 19:10:23 +0200 Subject: [PATCH 08/12] Make e2e test fixtures optional --- e2e/missing-config-file/expected-output.txt | 2 +- e2e/run-test.sh | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/e2e/missing-config-file/expected-output.txt b/e2e/missing-config-file/expected-output.txt index 60a436e..797b19d 100644 --- a/e2e/missing-config-file/expected-output.txt +++ b/e2e/missing-config-file/expected-output.txt @@ -1 +1 @@ -Configuration file /home/aw/Dev/own-php/lifter/e2e/missing-config-file//lifter.php does not exist +Configuration file /lifter.php does not exist diff --git a/e2e/run-test.sh b/e2e/run-test.sh index 642f00d..2ba49ee 100755 --- a/e2e/run-test.sh +++ b/e2e/run-test.sh @@ -14,6 +14,8 @@ composer install SUCCESS=1 fail() { + echo $1 + SUCCESS=0 } @@ -30,20 +32,24 @@ run_test() { cd $TESTS_BASE_DIR/$TEST_DIR - [[ -f $TESTS_BASE_DIR/$TEST_DIR/output.txt ]] && rm -f $TESTS_BASE_DIR/$TEST_DIR/output.txt + OUTPUT_FILE=$TESTS_BASE_DIR/$TEST_DIR/output.txt + + [[ -f $OUTPUT_FILE ]] && rm -f $OUTPUT_FILE [[ -d ./result/ ]] && rm -rf ./result/ - cp -r fixtures/ result/ + [[ -d ./fixtures ]] && cp -r fixtures/ result/ cd $TESTS_BASE_DIR if [[ -x $TESTS_BASE_DIR/$TEST_DIR/run.sh ]] then - ($TESTS_BASE_DIR/$TEST_DIR/run.sh > $TESTS_BASE_DIR/$TEST_DIR/output.txt) || { echo "Test $TEST_DIR failed"; fail; } + ($TESTS_BASE_DIR/$TEST_DIR/run.sh > $OUTPUT_FILE) || fail "Test $TEST_DIR failed" else - (./vendor/bin/lifter run --file=$TESTS_BASE_DIR/$TEST_DIR/lifter.php > $TESTS_BASE_DIR/$TEST_DIR/output.txt) || { echo "Test $TEST_DIR failed"; fail; } + (./vendor/bin/lifter run --file=$TESTS_BASE_DIR/$TEST_DIR/lifter.php > $OUTPUT_FILE) || fail "Test $TEST_DIR failed" fi - diff -ub $TEST_DIR/expected-output.txt $TEST_DIR/output.txt || { echo "Program output does not match expectation"; fail; } - diff -rub $TEST_DIR/expected-result/ $TEST_DIR/result/ || { echo "Produced result does not match expectations"; fail; } + sed -i -e "s#$TESTS_BASE_DIR/$TEST_DIR##g" $OUTPUT_FILE + + diff -ub $TEST_DIR/expected-output.txt $TEST_DIR/output.txt || fail "Program output does not match expectation" + [[ -d $TEST_DIR/expected-result/ ]] && { diff -rub $TEST_DIR/expected-result/ $TEST_DIR/result/ || fail "Produced result does not match expectations"; } } if [ $# -eq 0 ] From 3f08cd525317968b19dde5b733c1ccc1bf97d91f Mon Sep 17 00:00:00 2001 From: Andreas Wolf Date: Mon, 16 Dec 2024 14:16:26 +0100 Subject: [PATCH 09/12] Require Rector 2.0 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index c1526f9..00ef4b6 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ "require": { "php": "^8.2", "a9f/fractor": "^0.5", - "rector/rector": "^1.0", + "rector/rector": "^2.0", "symfony/config": "^6.4 || ^7.0", "symfony/console": "^6.4 || ^7.0", "symfony/dependency-injection": "^6.4 || ^7.0", From 1de5811ef3ae0d90905b214f3252bf02acca9fe6 Mon Sep 17 00:00:00 2001 From: Andreas Wolf Date: Mon, 19 May 2025 21:22:36 +0200 Subject: [PATCH 10/12] Adjust Fractor config for v0.5 --- res/run_fractor.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/res/run_fractor.php b/res/run_fractor.php index 4a11068..dddf61d 100644 --- a/res/run_fractor.php +++ b/res/run_fractor.php @@ -1,12 +1,12 @@ get(FractorConfigurationBuilder::class); // this is an additional file that can be used to configure Fractor before the individual step $fractorConfigFile = getenv('FRACTOR_CONFIG_FILE'); @@ -42,5 +42,5 @@ ($step->fractorClosure)($fractorConfig); - $fractorConfig($configurator); -}; + return $fractorConfig; +}; \ No newline at end of file From 5579e8a00a5fbee0ef8d01994049304ec99a4edb Mon Sep 17 00:00:00 2001 From: Andreas Wolf Date: Thu, 5 Jun 2025 18:20:45 +0200 Subject: [PATCH 11/12] Disable Fractor cache --- res/run_fractor.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/res/run_fractor.php b/res/run_fractor.php index dddf61d..c5f490e 100644 --- a/res/run_fractor.php +++ b/res/run_fractor.php @@ -1,5 +1,6 @@ get(FractorConfigurationBuilder::class); + $fractorConfig->withCache( + null, + MemoryCacheStorage::class, + null, + ); + // this is an additional file that can be used to configure Fractor before the individual step $fractorConfigFile = getenv('FRACTOR_CONFIG_FILE'); if (!is_string($fractorConfigFile)) { From 7286997d9047cd90a5fe8363de2e2e60d18c827c Mon Sep 17 00:00:00 2001 From: Andreas Wolf Date: Mon, 16 Dec 2024 15:46:50 +0100 Subject: [PATCH 12/12] TMP --- e2e/rector/expected-output.txt | 1 - src/Upgrade/Step/FractorStepExecutor.php | 8 +++++++- src/Upgrade/Step/RectorStepExecutor.php | 18 ++++++++++++++++-- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/e2e/rector/expected-output.txt b/e2e/rector/expected-output.txt index 95446e1..6d093dc 100644 --- a/e2e/rector/expected-output.txt +++ b/e2e/rector/expected-output.txt @@ -1,4 +1,3 @@ RECTOR: RECTOR: [OK] 1 file has been changed by Rector RECTOR: - diff --git a/src/Upgrade/Step/FractorStepExecutor.php b/src/Upgrade/Step/FractorStepExecutor.php index c9d3499..3c41fe4 100644 --- a/src/Upgrade/Step/FractorStepExecutor.php +++ b/src/Upgrade/Step/FractorStepExecutor.php @@ -56,11 +56,17 @@ public function run(int $index, UpgradeStep $step): void ], timeout: 3600 ); - $process->run(static function ($type, $data) { + $firstLine = true; + $process->run(static function ($type, $data) use (&$firstLine) { $data = trim($data); // TODO do we need to handle CRLF separately here? $lines = explode("\n", $data); + if (!$firstLine) { + echo array_shift($lines); + } else { + $firstLine = false; + } $lines = array_map( static fn (string $line) => "FRACTOR: $line", $lines diff --git a/src/Upgrade/Step/RectorStepExecutor.php b/src/Upgrade/Step/RectorStepExecutor.php index 0d11ef7..60d70cb 100644 --- a/src/Upgrade/Step/RectorStepExecutor.php +++ b/src/Upgrade/Step/RectorStepExecutor.php @@ -56,8 +56,22 @@ public function run(int $index, UpgradeStep $step): void ], timeout: 3600 ); - $process->run(static function ($type, $data) { - echo 'RECTOR: ' . $data; + $firstLine = true; + $process->run(static function ($type, $data) use (&$firstLine) { + $data = trim($data); + + // TODO do we need to handle CRLF separately here? + $lines = explode("\n", $data); + if (!$firstLine) { + echo array_shift($lines); + } else { + $firstLine = false; + } + $lines = array_map( + static fn (string $line) => "RECTOR: $line", + $lines + ); + echo implode("\n", $lines), "\n"; }); } }