Skip to content

Commit c41fecc

Browse files
committed
Better messages for "JSON node should (not) contain"
1 parent 89c831e commit c41fecc

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/Context/JsonContext.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,13 @@ public function theJsonNodeShouldContain($node, $text): void
226226

227227
$actual = $this->inspector->evaluate($json, $node);
228228

229-
$this->assertContains($text, (string) $actual);
229+
$printedActual = strlen($actual) > 50 ? substr($actual, 0, 50) . '[…]' : $actual;
230+
231+
$this->assertContains(
232+
$text,
233+
(string) $actual,
234+
'The node "'.$node.'" does not contain the expected text "'.$text.'" (found "'.$printedActual.'")'
235+
);
230236
}
231237

232238
/**
@@ -252,7 +258,13 @@ public function theJsonNodeShouldNotContain($node, $text): void
252258

253259
$actual = $this->inspector->evaluate($json, $node);
254260

255-
$this->assertNotContains($text, (string) $actual);
261+
$printedActual = strlen($actual) > 50 ? substr($actual, 0, 50) . '[…]' : $actual;
262+
263+
$this->assertNotContains(
264+
$text,
265+
(string) $actual,
266+
'The node "'.$node.'" does contain "'.$text.'" while it should not (found "'.$printedActual.'")'
267+
);
256268
}
257269

258270
/**

0 commit comments

Comments
 (0)