[5.7] Check for model in assertViewHas #26012
Merged
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.
When using
assertViewHas
with a model it can end up comparing class state that the test may not care about, such aswasRecentlyCreated
,pivots
, orrelationships
, etc. The way I currently go about this is by passing a callback toassertviewHas
:I think being able to instead call it with
assertViewHas('user', $user)
would be a nice change, and I don't see any obvious negative consequences to this (unless the user cared about the 'hidden' state).I'm not too cracked up about the test I added as it requires internal knowledge of
$response
, but I figure it's better than adding no tests. I could get rid of this line, but it would require rewritingassertViewHas
to not be reliant on__get
.Edit: I have a couple custom assertions I would like to PR. They are related to each other, but not to this one - should I submit it as a separate PR or make it part of this one?