From c4953c724bac6292e9ec26ac2f4b36aba8da04b8 Mon Sep 17 00:00:00 2001 From: katsugtgz Date: Tue, 18 Aug 2026 14:25:44 +0700 Subject: [PATCH] Fix rector crash after PHPUnitSetList constants were removed rector/rector 2.6.2 removed the PHPUNIT_40 ... PHPUNIT_130 constants from PHPUnitSetList. The config references them in an array literal, so PHP evaluates the constants before array_filter() can drop the rows for versions that do not apply. Every consumer now crashes with Undefined constant Rector\PHPUnit\Set\PHPUnitSetList::PHPUNIT_40 Replace the version map with PHPUnitSetList::COMPOSER_BASED, which selects the upgrade rules from the phpunit/phpunit constraint of the analysed project itself, and keep ANNOTATIONS_TO_ATTRIBUTES, which the old map applied from PHPUnit 10 onward. --- tools/rector/config.php | 30 ++++++------------------------ 1 file changed, 6 insertions(+), 24 deletions(-) diff --git a/tools/rector/config.php b/tools/rector/config.php index 548140f..daacb5c 100644 --- a/tools/rector/config.php +++ b/tools/rector/config.php @@ -47,30 +47,12 @@ } } - if ($phpunitConstraint = $composerJson->requirement('phpunit/phpunit')) { - $lowerBound = $versionParser->parseConstraints($phpunitConstraint)->getLowerBound(); - - $setList = [ - '>= 4.0' => [PHPUnitSetList::PHPUNIT_40], - '>= 5.0' => [PHPUnitSetList::PHPUNIT_50], - '>= 6.0' => [PHPUnitSetList::PHPUNIT_60], - '>= 7.0' => [PHPUnitSetList::PHPUNIT_70], - '>= 8.0' => [PHPUnitSetList::PHPUNIT_80], - '>= 9.0' => [PHPUnitSetList::PHPUNIT_90], - '>= 10.0' => [PHPUnitSetList::PHPUNIT_100, PHPUnitSetList::ANNOTATIONS_TO_ATTRIBUTES], - '>= 11.0' => [PHPUnitSetList::PHPUNIT_110], - '>= 12.0' => [PHPUnitSetList::PHPUNIT_120], - ]; - - $setList = array_filter( - $setList, - static fn ($constraint) => $lowerBound->compareTo($versionParser->parseConstraints($constraint)->getLowerBound(), '>'), - ARRAY_FILTER_USE_KEY, - ); - - if (!empty($setList)) { - $rectorConfig->sets(array_merge([PHPUnitSetList::PHPUNIT_CODE_QUALITY], ...array_values($setList))); - } + if ($composerJson->requirement('phpunit/phpunit')) { + $rectorConfig->sets([ + PHPUnitSetList::PHPUNIT_CODE_QUALITY, + PHPUnitSetList::ANNOTATIONS_TO_ATTRIBUTES, + PHPUnitSetList::COMPOSER_BASED, + ]); } // https://getrector.com/blog/5-common-mistakes-in-rector-config-and-how-to-avoid-them