Add macros for TestResponse

This commit is contained in:
philipp lang 2025-06-13 14:17:28 +02:00
parent adf9341dd7
commit 31c582e81d
1 changed files with 20 additions and 0 deletions

View File

@ -119,12 +119,24 @@ class TestCase extends BaseTestCase
/** @var TestResponse */
$response = $this;
$props = data_get($response->viewData('page'), 'props');
Assert::assertTrue(Arr::has($props, $path), 'Failed that key ' . $path . ' is in Response.');
Assert::assertNotNull($props);
$json = new AssertableJsonString($props);
$json->assertPath($path, $value);
return $this;
});
TestResponse::macro('assertInertiaPathArray', function ($arr) {
/** @var TestResponse */
$response = $this;
foreach ($arr as $key => $value) {
$response->assertInertiaPath($key, $value);
}
return $response;
});
TestResponse::macro('assertInertiaCount', function ($path, $count) {
/** @var TestResponse */
$response = $this;
@ -171,5 +183,13 @@ class TestCase extends BaseTestCase
return $this;
});
TestResponse::macro('assertNull', function (string $path) {
/** @var TestResponse */
$response = $this;
$response->assertHasJsonPath($path)->assertJsonPath($path, null);
return $this;
});
}
}