Fix rector crash after PHPUnitSetList constants were removed in 2.6.2 - #1
Open
katsugtgz wants to merge 1 commit into
Open
Fix rector crash after PHPUnitSetList constants were removed in 2.6.2#1katsugtgz wants to merge 1 commit into
katsugtgz wants to merge 1 commit into
Conversation
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.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
Since rector/rector 2.6.2 (released August 12), the rector step fails on every project using these tools:
Seen for example in the loupe CI: https://github.com/loupe-php/loupe/actions/runs/32068033140/job/95504580616
Cause
tools/rector/config.phpbuilds a map ofPHPUnitSetList::PHPUNIT_40toPHPUNIT_120constants in an array literal. PHP resolves the constants as soon as the array is built, beforearray_filter()can drop the rows for PHPUnit versions that do not apply. Rector 2.6.2 removed those constants (the set files were folded intoPHPUnitSetList::COMPOSER_BASED), so the array construction now crashes regardless of which PHPUnit version the analysed project actually uses.The tools install with
"rector/rector": "^2.0"and no lock file fortools/rector, so the new version is pulled in on the next run.Fix
Drop the version map and use the constants that still exist:
PHPUnitSetList::COMPOSER_BASEDpicks the upgrade rules from thephpunit/phpunitconstraint of the analysed project itself, which is what the old map approximated.PHPUnitSetList::ANNOTATIONS_TO_ATTRIBUTESwas applied by the old map from PHPUnit 10 onward, so it stays unconditional.Verification
Installed the tools with rector 2.6.2 and ran rector against a small test class with a
@dataProviderannotation:main:[ERROR] Undefined constant Rector\PHPUnit\Set\PHPUnitSetList::PHPUNIT_40#[DataProvider]