Skip to content

Instantly share code, notes, and snippets.

@BashirShallah
Last active March 26, 2020 22:36
Show Gist options
  • Save BashirShallah/e4fbf74d83d79952d1487c3a1999245b to your computer and use it in GitHub Desktop.
Save BashirShallah/e4fbf74d83d79952d1487c3a1999245b to your computer and use it in GitHub Desktop.
<?php
// for Laravel 7+
use Illuminate\Testing\Assert;
use Illuminate\Testing\TestResponse;
// for Laravel 5.*
use Illuminate\Foundation\Testing\Assert;
use Illuminate\Foundation\Testing\TestResponse;
// Macro
TestResponse::macro('assertJsonPathContain', function ($path, $array) {
Assert::assertNotEmpty($this->json($path), $this->assertJsonMessage($data));
Assert::assertArraySubset($data, $this->json($path));
return $this;
});
// Usage Example
$response = $this->get('/api/users');
$response->assertJsonPathContain('data.0', [
'user_id' => $user->id,
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment