Skip to content

Commit bc883ec

Browse files
authored
Merge pull request #84 from bystro/fix-83
Fix #83 JSON node equal to true|false|null aware
2 parents 21eeea4 + b8ee186 commit bc883ec

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/Json/JsonContext.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public function theJsonNodeShouldBeEqualTo($jsonNode, $expectedValue)
4545
{
4646
$this->assert(function () use ($jsonNode, $expectedValue) {
4747
$realValue = $this->evaluateJsonNodeValue($jsonNode);
48+
$expectedValue = $this->evaluateExpectedValue($expectedValue);
4849
$this->asserter->variable($realValue)->isEqualTo($expectedValue);
4950
});
5051
}
@@ -233,6 +234,19 @@ private function evaluateJsonNodeValue($jsonNode)
233234
{
234235
return $this->jsonInspector->readJsonNodeValue($jsonNode);
235236
}
237+
238+
private function evaluateExpectedValue($expectedValue)
239+
{
240+
if (in_array($expectedValue, array('true', 'false'))) {
241+
return filter_var($expectedValue, FILTER_VALIDATE_BOOLEAN);
242+
}
243+
244+
if ($expectedValue === 'null') {
245+
return null;
246+
}
247+
248+
return $expectedValue;
249+
}
236250

237251
private function readJson()
238252
{

0 commit comments

Comments
 (0)