Skip to content

Commit

Permalink
Merge pull request #28893 from browner12/assert-view
Browse files Browse the repository at this point in the history
[5.8] allow view assertions to see all data
  • Loading branch information
taylorotwell authored Jun 20, 2019
2 parents 8452136 + 9c15e78 commit f1bb3fe
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
12 changes: 6 additions & 6 deletions src/Illuminate/Foundation/Testing/TestResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -787,13 +787,13 @@ public function assertViewHas($key, $value = null)
$this->ensureResponseHasView();

if (is_null($value)) {
PHPUnit::assertArrayHasKey($key, $this->original->getData());
PHPUnit::assertArrayHasKey($key, $this->original->gatherData());
} elseif ($value instanceof Closure) {
PHPUnit::assertTrue($value($this->original->getData()[$key]));
PHPUnit::assertTrue($value($this->original->gatherData()[$key]));
} elseif ($value instanceof Model) {
PHPUnit::assertTrue($value->is($this->original->getData()[$key]));
PHPUnit::assertTrue($value->is($this->original->gatherData()[$key]));
} else {
PHPUnit::assertEquals($value, $this->original->getData()[$key]);
PHPUnit::assertEquals($value, $this->original->gatherData()[$key]);
}

return $this;
Expand Down Expand Up @@ -828,7 +828,7 @@ public function viewData($key)
{
$this->ensureResponseHasView();

return $this->original->getData()[$key];
return $this->original->gatherData()[$key];
}

/**
Expand All @@ -841,7 +841,7 @@ public function assertViewMissing($key)
{
$this->ensureResponseHasView();

PHPUnit::assertArrayNotHasKey($key, $this->original->getData());
PHPUnit::assertArrayNotHasKey($key, $this->original->gatherData());

return $this;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/View/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ protected function getContents()
*
* @return array
*/
protected function gatherData()
public function gatherData()
{
$data = array_merge($this->factory->getShared(), $this->data);

Expand Down
4 changes: 2 additions & 2 deletions tests/Foundation/FoundationTestResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function testAssertViewHas()
{
$response = $this->makeMockResponse([
'render' => 'hello world',
'getData' => ['foo' => 'bar'],
'gatherData' => ['foo' => 'bar'],
]);

$response->assertViewHas('foo');
Expand All @@ -48,7 +48,7 @@ public function is($model)

$response = $this->makeMockResponse([
'render' => 'hello world',
'getData' => ['foo' => $model],
'gatherData' => ['foo' => $model],
]);

$response->original->foo = $model;
Expand Down

0 comments on commit f1bb3fe

Please sign in to comment.