[8.x] Fix display of validation errors occurred when asserting status #38088
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As discovered by @paulredmond, the display of unexpected validation errors introduced in #38046 doesn't actually work in practice because a
ValidationException
is not reported by the exception handler. Paul's diagnosis can be found here. Thankfully this doesn't actually break any existing behaviour.This PR fixes the issue by also showing errors from a redirect response with session errors (i.e. a non-JSON validation response) and errors in JSON response content, instead of only looking at reported exceptions.
I have learned my lesson and tested this in a new
laravel/laravel
project.Errors in redirect response session:
Errors in response JSON content:
The behaviour is slightly different than before because
assertStatus()
no longer only displays errors for unexpected 500 and 422 responses, and instead just displays any reported exceptions, session errors, or JSON errors when the status is not as asserted. This also makesassertStatus()
behave the same asassertSuccessful()
.I also took the opportunity to standardise the messaging of "Expected response status code" which in some instances was just "Expected status code".