-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better messages for "JSON node should (not) contain" #33
base: main
Are you sure you want to change the base?
Conversation
c41fecc
to
818c276
Compare
$this->assertContains( | ||
$text, | ||
(string) $actual, | ||
'The node "'.$node.'" does not contain the expected text "'.$text.'" (found "'.$printedActual.'")' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The node '%s' should contain '%s', but it is '%s'.
is more concise. WDYT ?
@@ -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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Truncating the value might make debugging more difficult.
$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.'")' | ||
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(same comments as previous)
$text, | ||
(string) $actual, | ||
'The node "'.$node.'" does contain "'.$text.'" while it should not (found "'.$printedActual.'")' | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a unit test too ?
It does, but the value when you use "contain" might be a huge bloc of text. Maybe we can set the limit to 200 or 500 though.
Julien Deniau
…-------- Message d'origine --------
Le 04/06/2024 22:00, Hubert Lenoir a écrit :
@Jean-Beru commented on this pull request.
---------------------------------------------------------------
In [src/Context/JsonContext.php](#33 (comment)):
> @@ -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.'")'
The node '%s' should contain '%s', but it is '%s'. is more concise. WDYT ?
---------------------------------------------------------------
In [src/Context/JsonContext.php](#33 (comment)):
> @@ -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;
Truncating the value might make debugging more difficult.
---------------------------------------------------------------
In [src/Context/JsonContext.php](#33 (comment)):
> + $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.'")'
+ );
(same comments as previous)
—
Reply to this email directly, [view it on GitHub](#33 (review)), or [unsubscribe](https://github.com/notifications/unsubscribe-auth/AAKVNRPOVMPIXY3VTD26TATZFYMFLAVCNFSM6AAAAABIYFSHBCVHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDAOJXGI3TOMZZGE).
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Sure ! We can keep this value uncut for now (like in other contexts) and create an other PR to truncate it. Maybe using the verbosity ? |
See #31
Added better message for
theJsonNodeShouldContain
:and for
theJsonNodeShouldNotContain