Skip to content

[CodeQuality] Use atLeast() instead of exactly() in DecorateWillReturnMapWithExpectsMockRector#719

Merged
TomasVotruba merged 1 commit into
mainfrom
decorate-willreturnmap-atleast
Jul 13, 2026
Merged

[CodeQuality] Use atLeast() instead of exactly() in DecorateWillReturnMapWithExpectsMockRector#719
TomasVotruba merged 1 commit into
mainfrom
decorate-willreturnmap-atleast

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

willReturnMap() only maps argument combinations to return values — it does not enforce a strict call count. Decorating with expects($this->exactly(N)) forces the mock to be called exactly N times (N = map entry count), which produces false test failures when the mocked method is called fewer or more times than there are map entries.

Switching to atLeast(N) keeps a lower-bound expectation without over-constraining the call count.

Before

$someMock->method('some')->willReturnMap([1, 2]);

After

-$someMock->method('some')->willReturnMap([1, 2]);
+$someMock->expects($this->atLeast(2))->method('some')->willReturnMap([1, 2]);

@TomasVotruba TomasVotruba force-pushed the decorate-willreturnmap-atleast branch from f484df8 to eee5d04 Compare July 13, 2026 09:18
@TomasVotruba TomasVotruba force-pushed the decorate-willreturnmap-atleast branch from eee5d04 to b9def97 Compare July 13, 2026 09:19
@TomasVotruba TomasVotruba enabled auto-merge (squash) July 13, 2026 09:20
@TomasVotruba TomasVotruba merged commit 7dcbd20 into main Jul 13, 2026
8 checks passed
@TomasVotruba TomasVotruba deleted the decorate-willreturnmap-atleast branch July 13, 2026 09: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