Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Document whereType and whereAllType
  • Loading branch information
svenluijten authored Mar 18, 2021
commit e0ab7895db9eed0964b56d875fbe3949bf937b29
19 changes: 19 additions & 0 deletions http-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,25 @@ However, instead of making two separate calls to the `has` method to assert agai
->etc()
)
);

<a name="asserting-json-types"></a>
#### 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`.

<a name="testing-file-uploads"></a>
## Testing File Uploads
Expand Down