Skip to content

Commit

Permalink
Improved debugging of failed schema validation (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
alongosz authored Aug 26, 2023
1 parent 99ad33a commit 69bf683
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/contracts/BaseRestWebTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,22 @@ private function validateAgainstSchema(
string $resourceType,
string $format
): void {
$validator = $this->getSchemaValidator($format);
$validator->validate($response, $this->getSchemaFileBasePath($resourceType, $format));
try {
$validator = $this->getSchemaValidator($format);
$validator->validate($response, $this->getSchemaFileBasePath($resourceType, $format));
} catch (\Throwable $e) {
self::fail(
sprintf(
'Failed to validate against schema the response of Media Type %s in %s format. ' .
"The response was:\n%s\n" .
"The exception was:\n%s\n",
$resourceType,
$format,
$response,
$e
)
);
}
}

private function getSchemaValidator(string $format): ValidatorInterface
Expand Down

0 comments on commit 69bf683

Please sign in to comment.