[13.x] Add bulk JSON path assertions to TestResponse#59829
Merged
taylorotwell merged 2 commits intolaravel:13.xfrom Apr 23, 2026
Merged
[13.x] Add bulk JSON path assertions to TestResponse#59829taylorotwell merged 2 commits intolaravel:13.xfrom
taylorotwell merged 2 commits intolaravel:13.xfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What & Why
When writing HTTP tests that assert multiple JSON values, developers currently have to chain individual
assertJsonPath()calls. This becomes verbose and repetitive. This PR addsassertJsonPaths()andassertJsonMissingPaths()toIlluminate\Testing\TestResponseas bulk alternatives that accept arrays of paths and expected values.Before:
After:
API
assertJsonPaths(array $paths)Accepts an associative array mapping JSON paths to expected values. Supports closures for flexible assertions (inherited from
assertJsonPath()). Returns$thisfor fluent chaining.assertJsonMissingPaths($paths)Accepts a single path string or an array of path strings (via
Arr::wrap()). Asserts each path is absent from the JSON response. Returns$thisfor fluent chaining.Implementation Notes
Both methods are intentionally thin wrappers over the existing
assertJsonPath()andassertJsonMissingPath()methods. They fail fast on the first bad path and explicitly guard against empty input:assertJsonPaths([])fails with: "No JSON paths were provided."assertJsonMissingPaths([])fails with: "No JSON missing paths were provided."Test Coverage
Added to
tests/Testing/TestResponseTest.php:For
assertJsonPaths:testAssertJsonPaths— success case with mixed scalar and closure valuestestAssertJsonPathsCanFail— failure case demonstrating fail-fast behaviortestAssertJsonPathsCanFailWhenPathsAreEmpty— empty input guardFor
assertJsonMissingPaths:testAssertJsonMissingPaths— success case with string and array inputtestAssertJsonMissingPathsCanFail— failure case demonstrating fail-fast behaviortestAssertJsonMissingPathsCanFailWhenPathsAreEmpty— empty input guardTest Plan
./vendor/bin/phpunit tests/Testing/TestResponseTest.php./vendor/bin/pint --dirty