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

[11.x] Add assertExactJsonStructure method #52311

Merged
merged 1 commit into from
Jul 30, 2024

Conversation

gdebrauwer
Copy link
Contributor

@gdebrauwer gdebrauwer commented Jul 29, 2024

If an API route returns the following response

{
    "data": {
        "id": 1,
        "firstname": "Taylor",
        "lastname": "Otwell"
    }
}

then the following assertion will succeed

$response->assertJsonStructure([
    'data' => [
        'firstname',
        'lastname',
    ],
]);

But what if that API response should not include the "id" key? The assertJsonStructure() method does not allow you to assert that.

That is were this new assertExactJsonStructure() method comes in:

// This fails
$response->assertExactJsonStructure([
    'data' => [
        'firstname',
        'lastname',
    ],
]);

// This succeeds
$response->assertExactJsonStructure([
    'data' => [
        'id',
        'firstname',
        'lastname',
    ],
]);

@gdebrauwer gdebrauwer marked this pull request as draft July 29, 2024 13:48
Copy link

Thanks for submitting a PR!

Note that draft PR's are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.

Pull requests that are abandoned in draft may be closed due to inactivity.

@gdebrauwer gdebrauwer marked this pull request as ready for review July 29, 2024 13:53
@taylorotwell taylorotwell merged commit 394a6db into laravel:11.x Jul 30, 2024
31 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