-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
[5.8] Add message value assertion to assertJsonValidationErrors #27655
Conversation
So you can't have a mix of checking keys and checking both keys and messages? |
After some thought I've done some refactoring to check if the key was originally initialized and check for mixed types:
This will cover everything 👍 |
"Failed to find a validation error in the response for key: '{$value}'".PHP_EOL.PHP_EOL.$errorMessage | ||
); | ||
} else { | ||
PHPUnit::assertArraySubset( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please do not introduce a new usage of assertArraySubset
in Laravel. This is deprecated in PHPUnit 8 and we should avoid adding more uses of it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@driesvints Thanks. I just read the the deprecation post(sebastianbergmann/phpunit#3494) and it's said there is no alternative.
hmm, unfortunately, now there isn't a clean way to check if a key and value matches within an array in PHPUnit and changes to use PHP here would be ugly by checking if key is set in jsonErrors
then if the error message matches. Might have to table this until PHPUnit's issue/what you decide for assertJson
is sorted out. Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we can't find an alternative we're going to backport it into the framework directly but until we figure it out it's best to avoid adding more uses.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@driesvints if you are looking for a quick way out, I ported them to a phpunit extension https://packagist.org/packages/dms/phpunit-arraysubset-asserts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rdohms ah thanks. I'll put this on my todo list. Thanks for sharing 👍
Going to table this for now until I find a better solution for |
Moved to 5.8 branch per request (#27640).
This PR adds the assertion for JSON validation error messages in
assertJsonValidationErrors
.Currently, we can only check json validation error keys:
$this->assertJsonValidationErrors('key');
$this->assertJsonValidationErrors(['foo', 'bar']);
With this addition, you can check the key and the message:
$this->assertJsonValidationErrors(['key' => 'validation message']);
You can still continue to use the normal functionality by just passing a key or an array of keys.