Skip to content

[PHPUnit120] Skip PropertyCreateMockToCreateStubRector for property with expects() nested in closure#698

Merged
TomasVotruba merged 1 commit into
mainfrom
tv-skip-mock-expects-in-closure
Jun 29, 2026
Merged

[PHPUnit120] Skip PropertyCreateMockToCreateStubRector for property with expects() nested in closure#698
TomasVotruba merged 1 commit into
mainfrom
tv-skip-mock-expects-in-closure

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Bug

PropertyCreateMockToCreateStubRector had false positive: converted a mock property to createStub() even though the property had expects() calls — when those calls were nested inside a closure (e.g. willReturnCallback(function () { ... })).

Cause: MockObjectExprDetector::isPropertyUsedForMocking() used findInstancesOfScoped(), which stops traversal at closure boundaries, so $this->someMock->expects()->method() inside a callback went undetected.

Fix

Switched to non-scoped findInstancesOf() so usage inside closures is detected.

Added skip_property_used_in_closure.php.inc fixture.

@TomasVotruba TomasVotruba merged commit ceb0d4c into main Jun 29, 2026
8 checks passed
@TomasVotruba TomasVotruba deleted the tv-skip-mock-expects-in-closure branch June 29, 2026 20:15
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