Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[10.x] Add assertJsonPathCanonicalizing method #48117

Merged
merged 4 commits into from
Aug 21, 2023

Conversation

gdebrauwer
Copy link
Contributor

When testing API calls, I often have lots of tests that need to check if a json response contains all the expected ids without looking at the order of the ids in the response. For example, in a API call test that asserts if a querystring filter option works correctly, you will not (or not easily be able to) setup your expected models with fixed and known order in the response. That is currently not possible as assertJsonPath takes the order of the expected values into account.

To fix this, this PR adds a dedicated json assertion. I used the "canonicalizing" suffix because that is what PHPUnit calls this kind of assertion. (But maybe someone knows a better, more Laravel-like 😅, name for this method?)

$users = User::factory()->count(2)->create();

$this->get('/api/users')->assertJsonPathCanonicalizing('data.*.id', $users->pluck('id')->all());

@taylorotwell taylorotwell merged commit 4899c53 into laravel:10.x Aug 21, 2023
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants