Skip to content
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions e2e/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
7 changes: 3 additions & 4 deletions e2e/fractor/fractor.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php

use a9f\Fractor\Configuration\FractorConfigurationBuilder;
use a9f\Fractor\Configuration\FractorConfiguration;

return static function (FractorConfigurationBuilder $fractorConfig) {
// no-op for now
};
return FractorConfiguration::configure()
->withPaths([__DIR__ . '/result/**']);
14 changes: 7 additions & 7 deletions e2e/fractor/lifter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
]
);
}
)
]);
Expand Down
2 changes: 1 addition & 1 deletion e2e/missing-config-file/expected-output.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Configuration file /home/aw/Dev/own-php/lifter/e2e/missing-config-file//lifter.php does not exist
Configuration file <test-dir>/lifter.php does not exist
2 changes: 1 addition & 1 deletion e2e/rector/expected-output.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
RECTOR:
RECTOR: [OK] 1 file has been changed by Rector

RECTOR:
19 changes: 13 additions & 6 deletions e2e/run-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ composer install
SUCCESS=1

fail() {
echo $1

SUCCESS=0
}

Expand All @@ -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#<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 $@
Expand Down
24 changes: 14 additions & 10 deletions res/run_fractor.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
<?php

use a9f\Fractor\Configuration\FractorConfiguration;
use a9f\Fractor\Caching\ValueObject\Storage\MemoryCacheStorage;
use a9f\Fractor\Configuration\FractorConfigurationBuilder;
use a9f\Lifter\Configuration\LifterConfigFactory;
use a9f\Lifter\Upgrade\Step\FractorStep;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Webmozart\Assert\Assert;
use Symfony\Component\DependencyInjection\ContainerBuilder;

return static function (ContainerConfigurator $configurator) {
$fractorConfig = FractorConfiguration::configure();
return static function (ContainerBuilder $container) {
$fractorConfig = $container->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)) {
Expand Down Expand Up @@ -45,5 +49,5 @@

($step->fractorClosure)($fractorConfig);

$fractorConfig($configurator);
};
return $fractorConfig;
};
8 changes: 7 additions & 1 deletion src/Upgrade/Step/FractorStepExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 16 additions & 2 deletions src/Upgrade/Step/RectorStepExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";
});
}
}
Loading