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] assertOnlyJsonValidationErrors / assertOnlyInvalid #54678

Merged

Conversation

gdebrauwer
Copy link
Contributor

@gdebrauwer gdebrauwer commented Feb 18, 2025

Sometimes you want to test that a validation error is present but you want to be sure that no other validation error occurred. Currently, there is no easy way to do that, unless you provide every possible validation error key to a assertJsonMissingValidationErrors method call.

// Will fail if 'email' error is missing OR if 'name' error is present
// BUT nothing will fail if 'phone' error is present
$this->post('/user')
    ->assertJsonValidationErrors(['email'])
    ->assertMissingJsonValidationErrors(['name']);

This PR fixes that by creating a method that checks if the provided errors are present but also asserts that no other validation errors occurred:

// Will fail if 'email' error is missing OR if 'name' error is present OR if any other error is present
$this->post('/user')->assertOnlyJsonValidationErrors(['email']);

gdebrauwer and others added 3 commits February 18, 2025 18:28

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@taylorotwell taylorotwell merged commit 8af7463 into laravel:11.x Feb 19, 2025
44 checks passed
@taylorotwell
Copy link
Member

Useful - thanks!

browner12 added a commit to browner12/framework that referenced this pull request Mar 17, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
looks like a small oversight from laravel#54678 of which part of it was caught in laravel#54941
taylorotwell pushed a commit that referenced this pull request Mar 18, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
looks like a small oversight from #54678 of which part of it was caught in #54941
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