feat: only count assertions on expectations which can fail a test #1180
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.
Hi folks, I've opened this PR to address an issue I've identified with Mockery reporting an incorrect assertion count, which causes tests to not be marked as risky when they should be.
A very minimal example of this issue can be seen with these simple tests:
The output from these tests with the current version of Mockery is:
The first test does not use Mockery, and has no assertions or expectations. It is correctly identified as a Risky test.
However, we can see the middle test does not fail, and is not identified as a risky test with no assertions -
allows
being a wrapper forshouldReceive
, which indicates a method can be called zero or more times - or in other words, this syntax lets us set up a stub that would never cause a test to fail whether it is called or not.This should not be counted as an assertion, since it is not possible for this syntax alone to cause a test to fail.
The third test is an example of an expectation which should count as an assertion, because without calling the method once, the test will fail.
This pull request changes how Mockery counts the number of assertions, which is used to inform PHP Unit about a risky test.
With this change, the above tests now output a more accurate report of two risky tests.
I have added tests to cover multiple cases, but I'm happy to add more if folks have suggestions for other cases.