Skip to content

Commit

Permalink
[+++][FIX][Validator] Fix an issue with Symfony 3.3
Browse files Browse the repository at this point in the history
Symfony 3.3 remove the Content-Type and Content-Length headers when the status code is 204 or 304 or in the informational range (1xx). This commit handle those cases.
  • Loading branch information
Quentin Schuler authored Aug 18, 2017
1 parent f3f83a1 commit 4a44f9b
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/Test/SwaggerValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function validateResponseFor(ResponseInterface $actual, $method, $path, $

$contentType = $actual->getHeader('Content-Type');

if (!array_intersect($contentType, $produces)) {
if ($this->statusCodeMeetRequirements($code) && !array_intersect($contentType, $produces)) {
throw ContentTypeException::fromInvalidContentType($contentType, $produces);
}

Expand Down Expand Up @@ -131,4 +131,17 @@ private function getOperation($method, $path)
->getOperationFor($method)
;
}

    /**
     * Checks whether the status code is not 204 or 304 or is not in the informational range. Such responses does not
     * have any content nor Content-Type headers.
     *
     * @param int $code
     *
     * @return bool
     */
    private function statusCodeMeetRequirements($code)
    {
        return !in_array($code, [204, 304]) && substr((string) $code, 0, 1) !== '1';
    }
}

0 comments on commit 4a44f9b

Please sign in to comment.