[PHPUnit120] Add AnyMatcherToNewAnyInvokedCountRector for deprecated any() matcher assign - #764
Merged
Merged
Conversation
…ecated $this->any() matcher assign
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.
TestCase::any()is soft-deprecated since PHPUnit 12.5, hard-deprecated in 13.0 and removed in 14.0. See sebastianbergmann/phpunit#6461This rule flips the standalone matcher assign to a direct instance:
use PHPUnit\Framework\TestCase; final class SomeTest extends TestCase { public function test(): void { - $matcher = $this->any(); + $matcher = new \PHPUnit\Framework\MockObject\Rule\AnyInvokedCount(); } }Scope is deliberately narrow — only an
Assignwhose right side is a bare$this->any()on aTestCase/Assert. First-class callables, calls with args and non-PHPUnitany()methods are skipped. Theexpects($this->any())case is already covered byRemoveExpectAnyFromMockRector.Registered in the composer-based set, bonded to
phpunit/phpunit >=12.5.Note:
AnyInvokedCountis marked@internalupstream. The upstream advice is to restructure the test towardscreateStub()or a specific matcher, which is out of reach for an automated rewrite, so the direct instance is used as the closest mechanical equivalent.