From e0ab7895db9eed0964b56d875fbe3949bf937b29 Mon Sep 17 00:00:00 2001
From: Sven Luijten <11269635+svenluijten@users.noreply.github.com>
Date: Thu, 18 Mar 2021 22:26:12 +0100
Subject: [PATCH 1/2] Document whereType and whereAllType
---
http-tests.md | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/http-tests.md b/http-tests.md
index 9c9af002627..d166cbbee80 100644
--- a/http-tests.md
+++ b/http-tests.md
@@ -391,6 +391,25 @@ However, instead of making two separate calls to the `has` method to assert agai
->etc()
)
);
+
+
+#### Asserting JSON Types
+
+You may only want to assert that the properties in the JSON response are of a certain type. The `Illuminate\Testing\Fluent\AssertableJson` class provides the `whereType` and `whereAllType` methods for that.
+
+ $response->assertJson(fn (AssertableJson $json) =>
+ $json->whereType('id', 'integer')
+ ->whereAllType(['users.0.name' => 'string', 'meta' => 'array'])
+ );
+
+Instead of asserting just _one_ type, this also gives you the option to use union types by either seperating the types with a `|` character, or passing an array of types as the second parameter:
+
+ $response->assertJson(fn (AssertableJson $json) =>
+ $json->whereType('name', 'string|null')
+ ->whereType('id', ['string', 'integer'])
+ );
+
+You may assert any of the following types using this method: `string`, `integer`, `double`, `boolean`, `array`, and `null`.
## Testing File Uploads
From 36e520be0a0bf9660db82656b73c29c5379f3792 Mon Sep 17 00:00:00 2001
From: Sven Luijten <11269635+svenluijten@users.noreply.github.com>
Date: Thu, 18 Mar 2021 22:29:33 +0100
Subject: [PATCH 2/2] Update http-tests.md
---
http-tests.md | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/http-tests.md b/http-tests.md
index d166cbbee80..8cb67ab957c 100644
--- a/http-tests.md
+++ b/http-tests.md
@@ -395,14 +395,14 @@ However, instead of making two separate calls to the `has` method to assert agai
#### Asserting JSON Types
-You may only want to assert that the properties in the JSON response are of a certain type. The `Illuminate\Testing\Fluent\AssertableJson` class provides the `whereType` and `whereAllType` methods for that.
+You may only want to assert that the properties in the JSON response are of a certain type. The `Illuminate\Testing\Fluent\AssertableJson` class provides the `whereType` and `whereAllType` methods for doing just that.
$response->assertJson(fn (AssertableJson $json) =>
$json->whereType('id', 'integer')
->whereAllType(['users.0.name' => 'string', 'meta' => 'array'])
);
-Instead of asserting just _one_ type, this also gives you the option to use union types by either seperating the types with a `|` character, or passing an array of types as the second parameter:
+Instead of asserting just _one_ type, these methods also give you the option to use union types by either seperating the types with a `|` character, or passing an array of types as the second parameter:
$response->assertJson(fn (AssertableJson $json) =>
$json->whereType('name', 'string|null')