Skip to content

Fix rector crash after PHPUnitSetList constants were removed in 2.6.2 - #1

Open
katsugtgz wants to merge 1 commit into
terminal42:mainfrom
katsugtgz:fix-rector-phpunit-setlist
Open

Fix rector crash after PHPUnitSetList constants were removed in 2.6.2#1
katsugtgz wants to merge 1 commit into
terminal42:mainfrom
katsugtgz:fix-rector-phpunit-setlist

Conversation

@katsugtgz

Copy link
Copy Markdown

Bug

Since rector/rector 2.6.2 (released August 12), the rector step fails on every project using these tools:

[ERROR] Undefined constant Rector\PHPUnit\Set\PHPUnitSetList::PHPUNIT_40

Seen for example in the loupe CI: https://github.com/loupe-php/loupe/actions/runs/32068033140/job/95504580616

Cause

tools/rector/config.php builds a map of PHPUnitSetList::PHPUNIT_40 to PHPUNIT_120 constants in an array literal. PHP resolves the constants as soon as the array is built, before array_filter() can drop the rows for PHPUnit versions that do not apply. Rector 2.6.2 removed those constants (the set files were folded into PHPUnitSetList::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 for tools/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_BASED picks the upgrade rules from the phpunit/phpunit constraint of the analysed project itself, which is what the old map approximated.
  • PHPUnitSetList::ANNOTATIONS_TO_ATTRIBUTES was 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 @dataProvider annotation:

  • main: [ERROR] Undefined constant Rector\PHPUnit\Set\PHPUnitSetList::PHPUNIT_40
  • this branch: no error, and the annotation is correctly rewritten to #[DataProvider]

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant