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.7] Check for model in assertViewHas #26012

Merged
merged 1 commit into from
Oct 9, 2018

Conversation

FatBoyXPC
Copy link
Contributor

@FatBoyXPC FatBoyXPC commented Oct 9, 2018

When using assertViewHas with a model it can end up comparing class state that the test may not care about, such as wasRecentlyCreated, pivots, or relationships, etc. The way I currently go about this is by passing a callback to assertviewHas:

$this->assertViewHas('user', function ($model) use ($user) {
    return $user->is($model);
});

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 rewriting assertViewHas 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?

@FatBoyXPC FatBoyXPC force-pushed the add-model-to-assertviewhas branch from 95b9601 to b8f1e56 Compare October 9, 2018 05:01
@TBlindaruk TBlindaruk changed the title Check for model in assertViewHas [5.7] Check for model in assertViewHas Oct 9, 2018
@taylorotwell taylorotwell merged commit 5b9f4c1 into laravel:5.7 Oct 9, 2018
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.

2 participants