[9.x] Add expects to built-in Facade testing methods #34936
Merged
+26
−0
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.
The built-in testing layer for Facades wraps many underlying Mockery methods which is very great. But it's missing one of the most important testing methods -
expects
.Currently
shouldReceive
is the only out of the box expectation. However, in most cases,shouldReceive
does not provide the desired confidence. This can be confusing when new to testing.In the end, just because something should receive a call, doesn't mean it did. So
shouldReceive
must included a count modifier such asonce
,twice
, etc to trigger the desired behavior.Given that it's often the case where you want to ensure something was called, I believe adding
expects
can help improve the testing experience within Laravel.Within Mockery
expects
is simply an alias forshouldRecieve()->once()
, yet it's a far more expressive method (which aligns nicely with Laravel), streamlines the code, and avoids the footgun scenario described above.Before:
After: