Skip to content

Commit f3fedcc

Browse files
committed
Actionable error message for large json documents
1 parent 87cdc17 commit f3fedcc

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/Constraint/JsonValueMatchesMany.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ class JsonValueMatchesMany extends Constraint
1717
/** @var JsonValueMatches[] */
1818
private $constraints = array();
1919

20+
/** @var string[] */
21+
private $failedConstraints = array();
22+
2023
/**
2124
* JsonValueMatchesMany constructor.
2225
*
@@ -59,11 +62,23 @@ function (Constraint $constraint) {
5962
*/
6063
protected function matches($other): bool
6164
{
65+
$result = true;
6266
foreach ($this->constraints as $constraint) {
6367
if (!$constraint->evaluate($other, '', true)) {
64-
return false;
68+
$result = false;
69+
$this->failedConstraints[] = $constraint->toString();
6570
}
6671
}
67-
return true;
72+
return $result;
73+
}
74+
75+
/**
76+
* Returns a string representation of matches that evaluate to false.
77+
*
78+
* @return string
79+
*/
80+
protected function additionalFailureDescription($other): string
81+
{
82+
return "\n" . implode("\n", $this->failedConstraints);
6883
}
6984
}

0 commit comments

Comments
 (0)