From ae9ef293af7e09773b61dea021f6cba86ea84309 Mon Sep 17 00:00:00 2001 From: Saw-jan Date: Thu, 26 Sep 2024 12:17:54 +0545 Subject: [PATCH] test: only one error per path --- tests/acceptance/bootstrap/FeatureContext.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/tests/acceptance/bootstrap/FeatureContext.php b/tests/acceptance/bootstrap/FeatureContext.php index d7440f720..bce949a06 100644 --- a/tests/acceptance/bootstrap/FeatureContext.php +++ b/tests/acceptance/bootstrap/FeatureContext.php @@ -1107,7 +1107,6 @@ class FeatureContext extends BehatVariablesContext { * @throws Exception */ public function validateSchemaObject(JsonSchema $schemaObj): void { - // TODO: check duplicate properties $this->checkInvalidValidator($schemaObj); if ($schemaObj->type && $schemaObj->type !== "object") { @@ -1256,7 +1255,6 @@ class FeatureContext extends BehatVariablesContext { $this->validateSchemaRequirements($schema); $schema->in($json); } catch (JsonSchemaException $e) { - // file_put_contents("test.log", var_export($e, true)); $this->throwJsonSchemaException($e); } } @@ -1287,15 +1285,23 @@ class FeatureContext extends BehatVariablesContext { public function throwJsonSchemaException(JsonSchemaException $e): void { $errors = $this->getJsonSchemaErrors($e); $messages = ["JSON Schema validation failed:"]; - foreach ($errors as $key => $error) { + + $previousPointer = ''; + $errorCount = 0; + foreach ($errors as $error) { $expected = $error->constraint; $actual = $error->data; $errorMessage = $error->error; - $schemaPointer = \str_replace("/", "->", \trim($error->getSchemaPointer(), "/")); - $dataPointer = \str_replace("/", "->", \trim($error->getDataPointer(), "/")); + $schemaPointer = \str_replace("/", ".", \trim($error->getSchemaPointer(), "/")); + $dataPointer = \str_replace("/", ".", \trim($error->getDataPointer(), "/")); $pointer = \str_contains($schemaPointer, "additionalProperties") ? $dataPointer : $schemaPointer; - $message = ($key + 1) . ". "; + if ($pointer === $previousPointer) { + continue; + } + $previousPointer = $pointer; + + $message = ++$errorCount . ". "; switch (true) { case $error instanceof ArrayException: case $error instanceof LogicException: