-
Notifications
You must be signed in to change notification settings - Fork 11k
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
[8.x] Display unexpected validation errors when asserting status #38046
[8.x] Display unexpected validation errors when asserting status #38046
Conversation
Hi @jessarcher & @taylorotwell! I've been experimenting with this feature in an example app, and in theory the code works (i.e. tests pass), but in userland tests I don't believe This means that A fresh Laravel 8.51 app shows the following error without the expected validation messages: I am not sure off the top of my head how to get around this, but sure enough this feature works when I remove |
@@ -165,7 +166,7 @@ public function assertStatus($status) | |||
{ | |||
$actual = $this->getStatusCode(); | |||
|
|||
$lastException = $actual === 500 && $status !== 500 | |||
$lastException = $actual !== $status && in_array($actual, [422, 500]) | |||
? $this->exceptions->last() |
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.
This will always return null
in the case of ValidationException
since it's part of the base Handler internal don't report array:
framework/src/Illuminate/Foundation/Exceptions/Handler.php
Lines 87 to 98 in 63fd6ad
protected $internalDontReport = [ | |
AuthenticationException::class, | |
AuthorizationException::class, | |
HttpException::class, | |
HttpResponseException::class, | |
ModelNotFoundException::class, | |
MultipleRecordsFoundException::class, | |
RecordsNotFoundException::class, | |
SuspiciousOperationException::class, | |
TokenMismatchException::class, | |
ValidationException::class, | |
]; |
Crap. Thanks for catching this! I'm working on a solution that checks the response for session errors and errors in the content. |
This PR expands on #38025 to also show any unexpected validation errors that occurred when asserting a status code other than 422.
Currently the only way to see the validation errors is by dumping the response, running the test again, and then removing the dump. With this PR, the unexpected validation errors will be displayed straight away.
If the response being asserted against is JSON, the validation errors will be also be displayed as JSON. Otherwise the errors will be displayed as a simple list.