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

[5.3] Allow passing a closure to assertViewHas for finer control #15074

Merged
merged 1 commit into from
Aug 26, 2016
Merged

[5.3] Allow passing a closure to assertViewHas for finer control #15074

merged 1 commit into from
Aug 26, 2016

Conversation

adamwathan
Copy link
Contributor

This PR allows you to pass a closure as the $value argument, where the user can return a statement that should evaluate to true 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 a name attribute of "Taylor":

$this->assertViewHas('currentUser', function ($user) {
    return $user['name'] == '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.

@taylorotwell taylorotwell merged commit 5de1561 into laravel:5.3 Aug 26, 2016
@reinink
Copy link
Contributor

reinink commented Aug 26, 2016

That went quick. :feelsgood:

@GrahamCampbell GrahamCampbell changed the title Allow passing a closure to assertViewHas for finer control [5.3] Allow passing a closure to assertViewHas for finer control Aug 26, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants