Skip to content

Commit

Permalink
Better messages for "JSON node should (not) contain"
Browse files Browse the repository at this point in the history
  • Loading branch information
jdeniau committed Jun 4, 2024
1 parent 89c831e commit 818c276
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/Context/JsonContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,13 @@ public function theJsonNodeShouldContain($node, $text): void

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

$this->assertContains($text, (string) $actual);
$printedActual = \strlen($actual) > 50 ? substr($actual, 0, 50).'[…]' : $actual;

$this->assertContains(
$text,
(string) $actual,
'The node "'.$node.'" does not contain the expected text "'.$text.'" (found "'.$printedActual.'")'
);
}

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

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

$this->assertNotContains($text, (string) $actual);
$printedActual = \strlen($actual) > 50 ? substr($actual, 0, 50).'[…]' : $actual;

$this->assertNotContains(
$text,
(string) $actual,
'The node "'.$node.'" does contain "'.$text.'" while it should not (found "'.$printedActual.'")'
);
}

/**
Expand Down

0 comments on commit 818c276

Please sign in to comment.