[composer-based] Bond RemoveExpectAnyFromMockRector to PHPUnit 11+ - #756
Merged
Conversation
Removing expects($this->any()) leaves the mock without expectations, which is what unblocks the PHPUnit 11 mock-to-stub rules. Bond the rule to "phpunit/phpunit" >=11.0 and register it in the composer-based set.
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.
RemoveExpectAnyFromMockRectorhad no version bond at all — it was registered only in thephpunit-code-qualityset and fired on any PHPUnit version.The rule really belongs to the PHPUnit 11 mock-to-stub story: stripping
expects($this->any())leaves the mock with zero expectations, which is exactly what unblocksExpressionCreateMockToCreateStubRector,PropertyCreateMockToCreateStubRectorand friends.So it now implements
ComposerPackageConstraintInterfacewithphpunit/phpunit >=11.0, and is registered inconfig/sets/composer-based.phpnext to the other mock/stub rules. It stays in the code-quality set as well, same asBareCreateMockAssignToDirectUseRector.What the rule does:
use PHPUnit\Framework\TestCase; class SomeClass extends TestCase { public function test() { $translator = $this->createMock(SomeClass::class); - $translator->expects($this->any()) - ->method('trans') + $translator->method('trans') ->willReturn('translated max {{ max }}!'); } }