[8.x] Add assertion to verify type of key in JSON #36638
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As continuation on #36454 and #36620, this PR adds 2 new methods to
\Illuminate\Testing\Fluent\AssertableJson
:whereType
whereAllType
These new methods can be used to verify that the keys in the JSON response are of the expected type(s), similar to the already existing
where
andwhereAll
methods on the same class:You can also use union types by passing either an array, or a pipe-delimited string as the second argument to
whereType
:This currently uses PHP's own
gettype()
function, and only supports the following types:string
integer
double
boolean
array
null
AKA the only types JSON supports 🙂
I did not add the possibility to pass a
\Closure
towhereType
, because at that point you should just use thewhere
method directly. I'm open to suggestions here though (how would passing a
\Closure
even work?).Just wanted to say thanks to @claudiodekker for their amazing contribution this is building upon! ❤️