Skip to content

Commit

Permalink
Show property name on failing JSON schema assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
francislavoie committed Sep 17, 2024
1 parent 110fca6 commit 21053a8
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/Codeception/Module/REST.php
Original file line number Diff line number Diff line change
Expand Up @@ -967,15 +967,19 @@ public function seeResponseIsValidOnJsonSchemaString(string $schema): void
$validator->validate($responseObject, $schemaObject, JsonConstraint::CHECK_MODE_VALIDATE_SCHEMA);

$outcome = $validator->isValid();
$error = '';
$message = '';
if (!$outcome) {
$errors = $validator->getErrors();
$error = array_shift($errors)["message"];
foreach ($validator->getErrors() as $error) {
if ($message !== '') {
$message .= ', ';
}
$message .= sprintf("[Property: '%s'] %s", $error['property'], $error['message']);
}
}

Assert::assertTrue(
$outcome,
$error
$message
);
}

Expand Down

0 comments on commit 21053a8

Please sign in to comment.