Last active
March 26, 2020 22:36
-
-
Save BashirShallah/e4fbf74d83d79952d1487c3a1999245b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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