/**
* @param RequestInterface $request
* @param ResponseInterface $response
* @throws ValidatorResponseException
*/
private function assertValidHeaders(RequestInterface $request, ResponseInterface $response)
{
$method = $request->getMethod();
$path = $request->getUri()->getPath();
$statusCode = $response->getStatusCode();
$schemaHeaders = $this->schemaHelper->getResponseHeaders($method, $path, $statusCode);
/** @var NamedParameter $schemaHeader */
foreach ($schemaHeaders as $schemaHeader) {
$key = $schemaHeader->getKey();
/** @var string[] $header */
foreach ($response->getHeader($key) as $header) {
foreach ($header as $headerValue) {
try {
$schemaHeader->validate($headerValue);
} catch (ValidationException $exception) {
$message = sprintf('Response header %s with value "%s" for %s %s ' . 'with status code %s does not match schema: %s', $key, $headerValue, strtoupper($method), $path, $statusCode, $exception->getMessage());
throw new ValidatorResponseException($message, 0, $exception);
}
}
}
}
}