Skip to content

[PHPUnit120] Add AnyMatcherToNewAnyInvokedCountRector for deprecated any() matcher assign - #764

Merged
TomasVotruba merged 1 commit into
mainfrom
any-matcher-to-new-any-invoked-count
Aug 9, 2026
Merged

[PHPUnit120] Add AnyMatcherToNewAnyInvokedCountRector for deprecated any() matcher assign#764
TomasVotruba merged 1 commit into
mainfrom
any-matcher-to-new-any-invoked-count

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

TestCase::any() is soft-deprecated since PHPUnit 12.5, hard-deprecated in 13.0 and removed in 14.0. See sebastianbergmann/phpunit#6461

This 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 Assign whose right side is a bare $this->any() on a TestCase/Assert. First-class callables, calls with args and non-PHPUnit any() methods are skipped. The expects($this->any()) case is already covered by RemoveExpectAnyFromMockRector.

Registered in the composer-based set, bonded to phpunit/phpunit >=12.5.

Note: AnyInvokedCount is marked @internal upstream. The upstream advice is to restructure the test towards createStub() or a specific matcher, which is out of reach for an automated rewrite, so the direct instance is used as the closest mechanical equivalent.

@TomasVotruba
TomasVotruba merged commit ed6bbc7 into main Aug 9, 2026
7 checks passed
@TomasVotruba
TomasVotruba deleted the any-matcher-to-new-any-invoked-count branch August 9, 2026 10:20
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