Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent shouldNotReceive from getting overridden by invocation count methods #1329

Conversation

ghostwriter
Copy link
Member

@ghostwriter ghostwriter commented Aug 14, 2023

Resolves #1328

Currently, to indicate that an expectation is never expected to be called, Mockery internally sets the invocation count to 0 using Mocker\Expectation::never() which is equivalent to times(0).

So adding additional once(),twice(), times(n) invocation count methods will change the expectation behavior from shouldNotReceive to shouldReceive.

warning
Chaining additional invocation count methods to shouldNotReceive(), never(), and times(0) has been deprecated and will throw an exception in a future version of Mockery.

throw new \InvalidArgumentException(
'shouldNotReceive() method does not accept chaining additional invocation count methods.'
);

If the mock shouldNotReceive a call more or less than x times, use Call count modifiers atLeast() or atMost().

ghostwriter and others added 3 commits August 14, 2023 14:56
Signed-off-by: Nathanael Esayeas <nathanael.esayeas@protonmail.com>
Co-Authored-By: Danny-Smart <113538899+Danny-Smart@users.noreply.github.com>
Signed-off-by: Nathanael Esayeas <nathanael.esayeas@protonmail.com>
Signed-off-by: Nathanael Esayeas <nathanael.esayeas@protonmail.com>
@ghostwriter ghostwriter added Bug An error or unexpected behavior. Patch Backwards compatible bug fixes and improvements Fixed for bug fixes or error corrections labels Aug 14, 2023
@ghostwriter ghostwriter added this to the 1.6.7 milestone Aug 14, 2023
@ghostwriter ghostwriter self-assigned this Aug 14, 2023
@ghostwriter ghostwriter linked an issue Aug 14, 2023 that may be closed by this pull request
@codecov
Copy link

codecov bot commented Aug 14, 2023

Codecov Report

Merging #1329 (fe754a2) into 1.6.x (b8e0bb7) will increase coverage by 0.04%.
The diff coverage is 100.00%.

Additional details and impacted files
@@             Coverage Diff              @@
##              1.6.x    #1329      +/-   ##
============================================
+ Coverage     77.66%   77.70%   +0.04%     
- Complexity     1016     1018       +2     
============================================
  Files            76       76              
  Lines          2601     2606       +5     
============================================
+ Hits           2020     2025       +5     
  Misses          581      581              
Files Changed Coverage Δ
library/Mockery/Expectation.php 95.53% <100.00%> (+0.08%) ⬆️

@ghostwriter ghostwriter removed the Patch Backwards compatible bug fixes and improvements label Aug 14, 2023
@ghostwriter ghostwriter force-pushed the issue-1328/shouldnotreceive-is-overridden-by-invocation-count-methods branch from ca01d13 to e181f30 Compare August 15, 2023 01:08
@ghostwriter ghostwriter added Patch Backwards compatible bug fixes and improvements deprecation something is or will be deprecated Deprecated for features or functionality that will be removed in a future release and removed deprecation something is or will be deprecated labels Aug 15, 2023
Signed-off-by: Nathanael Esayeas <nathanael.esayeas@protonmail.com>
@ghostwriter ghostwriter force-pushed the issue-1328/shouldnotreceive-is-overridden-by-invocation-count-methods branch from e181f30 to fe754a2 Compare August 15, 2023 02:34
@ghostwriter
Copy link
Member Author

I left this pull request open but received no response for discussion, again.

I will merge it now, but welcome any feedback post-merge.

Thanks!

@ghostwriter ghostwriter merged commit fab5c13 into 1.6.x Aug 23, 2023
19 of 22 checks passed
@ghostwriter ghostwriter deleted the issue-1328/shouldnotreceive-is-overridden-by-invocation-count-methods branch August 23, 2023 09:14
@Danny-Smart
Copy link
Contributor

No news is good news 😄

I found no fault when I checked this before

@ghostwriter ghostwriter mentioned this pull request Dec 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug An error or unexpected behavior. Deprecated for features or functionality that will be removed in a future release Fixed for bug fixes or error corrections Patch Backwards compatible bug fixes and improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

shouldNotReceive is overridden by invocation count methods
2 participants