Skip to content

Bond stub and mock rules to phpunit/phpunit >=11.0 - #750

Merged
TomasVotruba merged 2 commits into
mainfrom
mock-to-stub-phpunit-11-constraint
Jul 31, 2026
Merged

Bond stub and mock rules to phpunit/phpunit >=11.0#750
TomasVotruba merged 2 commits into
mainfrom
mock-to-stub-phpunit-11-constraint

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

The stub and mock rules were only reachable through PHPUnitSetList::PHPUNIT_MOCK_TO_STUB, with nothing tying them to a PHPUnit version. They now declare the constraint themselves and are registered in the composer-based set, so withComposerBased(phpunit: true) picks them up on any project with PHPUnit 11 or newer.

-final class BareCreateMockAssignToDirectUseRector extends AbstractRector
+final class BareCreateMockAssignToDirectUseRector extends AbstractRector implements ComposerPackageConstraintInterface
 {
+    public function provideComposerPackageConstraint(): ComposerPackageConstraint
+    {
+        return new ComposerPackageConstraint('phpunit/phpunit', '>=11.0');
+    }

Rules bound to >=11.0:

  • CreateStubOverCreateMockArgRector
  • CreateStubInCoalesceArgRector
  • ExpressionCreateMockToCreateStubRector
  • PropertyCreateMockToCreateStubRector
  • MockObjectVarToStubRector
  • AddIntersectionVarToMockObjectPropertyRector
  • AddStubIntersectionVarToStubPropertyRector
  • BareCreateMockAssignToDirectUseRector

MockObjectArgCreateStubToCreateMockRector already declared >=11.0 and was already in the set.

And registered in composer-based.php:

// stubs over mocks, where no expectations are set, since PHPUnit 11.0
CreateStubOverCreateMockArgRector::class,
CreateStubInCoalesceArgRector::class,
ExpressionCreateMockToCreateStubRector::class,
PropertyCreateMockToCreateStubRector::class,
MockObjectVarToStubRector::class,
AddIntersectionVarToMockObjectPropertyRector::class,
AddStubIntersectionVarToStubPropertyRector::class,
BareCreateMockAssignToDirectUseRector::class,

// mocks back over stubs, where a mock object is required
MockObjectArgCreateStubToCreateMockRector::class,

phpunit-mock-to-stub.php is left as is - the rules now self-gate wherever they are registered, so a PHPUnit 10 project including that set no longer gets stub conversions it cannot use.

Based on #749, which restores rector/rector-src to dev-main; without it composer install fails on main.

@TomasVotruba
TomasVotruba merged commit 94a0237 into main Jul 31, 2026
7 checks passed
@TomasVotruba
TomasVotruba deleted the mock-to-stub-phpunit-11-constraint branch July 31, 2026 20:36
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