Skip to content

Commit 21053a8

Browse files
committed
Show property name on failing JSON schema assertions
1 parent 110fca6 commit 21053a8

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/Codeception/Module/REST.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -967,15 +967,19 @@ public function seeResponseIsValidOnJsonSchemaString(string $schema): void
967967
$validator->validate($responseObject, $schemaObject, JsonConstraint::CHECK_MODE_VALIDATE_SCHEMA);
968968

969969
$outcome = $validator->isValid();
970-
$error = '';
970+
$message = '';
971971
if (!$outcome) {
972-
$errors = $validator->getErrors();
973-
$error = array_shift($errors)["message"];
972+
foreach ($validator->getErrors() as $error) {
973+
if ($message !== '') {
974+
$message .= ', ';
975+
}
976+
$message .= sprintf("[Property: '%s'] %s", $error['property'], $error['message']);
977+
}
974978
}
975979

976980
Assert::assertTrue(
977981
$outcome,
978-
$error
982+
$message
979983
);
980984
}
981985

0 commit comments

Comments
 (0)