[5.3] Allow passing a closure to assertViewHas for finer control #15074
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.
This PR allows you to pass a closure as the
$value
argument, where the user can return a statement that should evaluate totrue
if the data in the view is what they want.For example, this assertion would pass as long as the
currentUser
variable passed to the view had aname
attribute of"Taylor"
:This makes it much easier to write assertions against view data when it's hard to mimic the entire object you want to inspect. It's almost impossible to do this with Eloquent models currently if you create one in a factory in your test for example, because the object in your test and the object retrieved in your app code will have subtle differences in private attributes that don't actually matter to your test.