Skip to content

Commit

Permalink
Merge pull request #84 from bystro/fix-83
Browse files Browse the repository at this point in the history
Fix #83 JSON node equal to true|false|null aware
  • Loading branch information
shouze authored Nov 23, 2017
2 parents 21eeea4 + b8ee186 commit bc883ec
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/Json/JsonContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public function theJsonNodeShouldBeEqualTo($jsonNode, $expectedValue)
{
$this->assert(function () use ($jsonNode, $expectedValue) {
$realValue = $this->evaluateJsonNodeValue($jsonNode);
$expectedValue = $this->evaluateExpectedValue($expectedValue);
$this->asserter->variable($realValue)->isEqualTo($expectedValue);
});
}
Expand Down Expand Up @@ -233,6 +234,19 @@ private function evaluateJsonNodeValue($jsonNode)
{
return $this->jsonInspector->readJsonNodeValue($jsonNode);
}

private function evaluateExpectedValue($expectedValue)
{
if (in_array($expectedValue, array('true', 'false'))) {
return filter_var($expectedValue, FILTER_VALIDATE_BOOLEAN);
}

if ($expectedValue === 'null') {
return null;
}

return $expectedValue;
}

private function readJson()
{
Expand Down

0 comments on commit bc883ec

Please sign in to comment.