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

[8.x] Fixed json validation check if there is encoded content #38189

Closed
wants to merge 3 commits into from
Closed

[8.x] Fixed json validation check if there is encoded content #38189

wants to merge 3 commits into from

Conversation

tabuna
Copy link
Contributor

@tabuna tabuna commented Jul 31, 2021

Hey, in recent commits #38046 #38088, JSON validation has been added when the application/json header is present, but this is not always required as the content can be encoded. This PR adds a check that will only check the content if it hasn't been encoded.

@tabuna tabuna changed the title Fixed json validation check if there is encoded content [8.x] Fixed json validation check if there is encoded content Jul 31, 2021
@jessarcher
Copy link
Member

Looks good 👍

I was going to wrap it in a try/catch to prevent it from ever returning a non status related message, but this works too.

@derekmd
Copy link
Contributor

derekmd commented Jul 31, 2021

Is GZIP-encoded content causing the exception "Invalid JSON was returned from the route" to be thrown?

This change may not be needed with #38192 now submitted to fix #38178.

When building the new custom PHPUnit message in statusMessageWithDetails(), this error checking block (called via $this->json()) must always be skipped:

if (is_null($decodedResponse) || $decodedResponse === false) {
if ($this->exception) {
throw $this->exception;
} else {
PHPUnit::fail('Invalid JSON was returned from the route.');
}
}

Ideally calling TestResponse@assertStatus() should gracefully fallback to generic message "Expected response status code [{$expected}] but received {$actual}." when the JSON response 'errors' key isn't found. That "Invalid JSON was returned from the route" exception is meant for dev feedback when calling the assertJson*() methods on plain key/value payloads.

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.

4 participants