Skip to content

Move composer version bound rules to composer-based set - #747

Merged
TomasVotruba merged 1 commit into
mainfrom
composer-based-version-bound-rules
Jul 31, 2026
Merged

Move composer version bound rules to composer-based set#747
TomasVotruba merged 1 commit into
mainfrom
composer-based-version-bound-rules

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

The three remaining rules that declare a ComposerPackageConstraint were registered in several PHPUnit version sets, repeated so that a direct upgrade from an older version still picks them up:

// config/sets/phpunit120.php
// deprecated in PHPUnit 11.5, repeated here for a direct 11.4 → 12.0 upgrade
AssertContainsOnlyMethodCallRector::class,
AssertIsTypeMethodCallRector::class,

The composer package constraint already handles that, so the repetition is not needed. They move into composer-based.php, which the version sets import:

$rectorConfig->rules([
    // ...

    // stubs are required over mocks since PHPUnit 11.0
    MockObjectArgCreateStubToCreateMockRector::class,

    // deprecated in PHPUnit 11.5
    AssertContainsOnlyMethodCallRector::class,
    AssertIsTypeMethodCallRector::class,
]);
Rule Constraint
MockObjectArgCreateStubToCreateMockRector >=11.0
AssertContainsOnlyMethodCallRector >=11.5
AssertIsTypeMethodCallRector >=11.5
 // config/sets/phpunit130.php
-    $rectorConfig->rules([
-        // deprecated in PHPUnit 11.5, repeated here for a direct upgrade from an older version
-        AssertContainsOnlyMethodCallRector::class,
-        AssertIsTypeMethodCallRector::class,
-    ]);
+    // AssertContainsOnlyMethodCallRector and AssertIsTypeMethodCallRector are registered there,
+    // guarded by composer package constraint
+    $rectorConfig->sets([PHPUnitSetList::COMPOSER_BASED]);

phpunit110.php, phpunit120.php and phpunit130.php now import PHPUnitSetList::COMPOSER_BASED instead of listing the rules, so no set loses a rule.

Side effect worth a look: importing COMPOSER_BASED also brings its annotation to attribute rules into those three version sets. Those rules are bound to phpunit/phpunit >=10.0, so they are active for any project on 11 or newer - which is what a direct upgrade from a pre-attribute version needs anyway.

phpunit-mock-to-stub.php keeps its own MockObjectArgCreateStubToCreateMockRector registration - that one is thematic, not a version repetition.

@TomasVotruba
TomasVotruba merged commit 1a823c1 into main Jul 31, 2026
7 checks passed
@TomasVotruba
TomasVotruba deleted the composer-based-version-bound-rules branch July 31, 2026 19:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant