diff --git a/composer.json b/composer.json index 33d5173..00ef4b6 100644 --- a/composer.json +++ b/composer.json @@ -12,8 +12,8 @@ ], "require": { "php": "^8.2", - "a9f/fractor": "^0.3", - "rector/rector": "^1.0", + "a9f/fractor": "^0.5", + "rector/rector": "^2.0", "symfony/config": "^6.4 || ^7.0", "symfony/console": "^6.4 || ^7.0", "symfony/dependency-injection": "^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": { 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') + ] + ); } ) ]); 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/rector/expected-output.txt b/e2e/rector/expected-output.txt index 632fde4..6d093dc 100644 --- a/e2e/rector/expected-output.txt +++ b/e2e/rector/expected-output.txt @@ -1,3 +1,3 @@ RECTOR: RECTOR: [OK] 1 file has been changed by Rector - +RECTOR: diff --git a/e2e/run-test.sh b/e2e/run-test.sh index ffa45cd..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,25 +32,30 @@ 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 ] then run_test fractor + run_test missing-config-file run_test rector else for test in $@ diff --git a/res/run_fractor.php b/res/run_fractor.php index e05981a..c5f490e 100644 --- a/res/run_fractor.php +++ b/res/run_fractor.php @@ -1,22 +1,26 @@ 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)) { 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)) { @@ -45,5 +49,5 @@ ($step->fractorClosure)($fractorConfig); - $fractorConfig($configurator); -}; + return $fractorConfig; +}; \ No newline at end of file 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"; }); } }