Skip to content

[5.8] allow view assertions to see all data#28893

Merged
taylorotwell merged 1 commit intolaravel:5.8from
browner12:assert-view
Jun 20, 2019
Merged

[5.8] allow view assertions to see all data#28893
taylorotwell merged 1 commit intolaravel:5.8from
browner12:assert-view

Conversation

@browner12
Copy link
Copy Markdown
Contributor

Problem

The assertViewHas() assertion in the HTTP testing will currently only look at data bound directly to the view, and not data that has been 'shared' with the view. This makes it a little clunkier to check for shared data.

$response = $this->get('/');

$response->assertOk();

$response->assertViewHas('someKey');  // fails with shared data

$this->assertArrayHasKey('someKey', $response->original->gatherData());

Solution

The view assertions now use the gatherData() method, instead of the getData() method, which provides us both the directly bound data, and the globally shared data.

Concerns

  • Is this BC kosher? Not sure if this would be considered a 'bug fix' or a 'change of behavior', and I guess depends on the intent of the assertion.
  • Or does this belong in a separate assertion? assertViewHasShared() or something similar?

currently, the view assertions can only see data passed directly to the view. this change allows the assertions to also see the data that has been 'shared'
@taylorotwell taylorotwell merged commit f1bb3fe into laravel:5.8 Jun 20, 2019
@browner12 browner12 deleted the assert-view branch June 20, 2019 13:43
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