Skip to content

Instantly share code, notes, and snippets.

Last active Mar 8, 2019
What would you like to do?
TestResponse::assertViewHasDeep assertion
use PHPUnit\Framework\Assert as PHPUnit;
use Illuminate\Support\Arr;
use Illuminate\Foundation\Testing\TestResponse;
use Illuminate\Database\Eloquent\Model;
TestResponse::macro('assertViewHasDeep', function ($key, $value = null) {
$data = $this->original->getData();
$keys = explode('.', $key);
foreach ($keys as $key) {
if (Arr::accessible($data)) {
PHPUnit::assertTrue(Arr::exists($data, $key));
} elseif (is_object($data)) {
} else {
PHPUnit::fail('Data does not conform to given key.');
$data = data_get($data, $key);
if ($value instanceof Closure) {
} elseif ($value instanceof Model) {
} else {
PHPUnit::assertEquals($value, $data);
return $this;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment