Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Collaborator

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.


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

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 ?

);
}

/**
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.'")'
);
Comment on lines +261 to +267
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(same comments as previous)

}
Copy link
Collaborator

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 ?


/**
Expand Down
Loading