From 31c582e81d9a2b35a6ea11e077a4fcc744b9bda3 Mon Sep 17 00:00:00 2001 From: philipp lang Date: Fri, 13 Jun 2025 14:17:28 +0200 Subject: [PATCH] Add macros for TestResponse --- tests/TestCase.php | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/tests/TestCase.php b/tests/TestCase.php index 555f2c4a..6731b997 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -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; + }); } }