Skip to content

Commit

Permalink
allow view assertions to see all data
Browse files Browse the repository at this point in the history
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'
  • Loading branch information
browner12 committed Jun 19, 2019
1 parent 9b7520a commit 9c15e78
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 @@ -766,13 +766,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 @@ -807,7 +807,7 @@ public function viewData($key)
{
$this->ensureResponseHasView();

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

/**
Expand All @@ -820,7 +820,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 9c15e78

Please sign in to comment.