From d63995c60dd1ec312456986164177a4539ce9aad Mon Sep 17 00:00:00 2001 From: Alexis Lefebvre Date: Tue, 16 Oct 2018 22:17:59 +0200 Subject: [PATCH] Avoid bug with number when testing string Fixes #263 --- src/Context/JsonContext.php | 2 ++ tests/features/json.feature | 3 ++- tests/features/ru/json.feature | 3 ++- tests/fixtures/www/json/notnullvalues.json | 3 ++- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Context/JsonContext.php b/src/Context/JsonContext.php index 99630567..064a230c 100644 --- a/src/Context/JsonContext.php +++ b/src/Context/JsonContext.php @@ -171,6 +171,8 @@ public function theJsonNodeShouldBeEqualToTheString($node, $text) $actual = $this->inspector->evaluate($json, $node); + $text = (string) $text; + if ($actual !== $text) { throw new \Exception( sprintf('The node value is `%s`', json_encode($actual)) diff --git a/tests/features/json.feature b/tests/features/json.feature index 3521f60c..088a0342 100644 --- a/tests/features/json.feature +++ b/tests/features/json.feature @@ -175,7 +175,7 @@ Feature: Testing JSONContext Scenario: Check not null values Given I am on "/json/notnullvalues.json" Then the response should be in JSON - And the JSON node '' should have 5 elements + And the JSON node '' should have 6 elements And the JSON node "one" should not be null And the JSON node "one" should be false And the JSON node "two" should not be null @@ -186,6 +186,7 @@ Feature: Testing JSONContext And the JSON node "four" should be equal to the string "foo" And the JSON node "five" should not be null And the JSON node "five" should be equal to the number 5 + And the JSON node "six" should be equal to the string "44000" Scenario: Json validation against swagger dump file Given I am on "/json/swaggerpartial.json" diff --git a/tests/features/ru/json.feature b/tests/features/ru/json.feature index fa138626..af065b27 100644 --- a/tests/features/ru/json.feature +++ b/tests/features/ru/json.feature @@ -176,7 +176,7 @@ Сценарий: Тестирование не-null значений Пусть я на странице "/json/notnullvalues.json" Тогда ответ должен быть в JSON - И узел JSON '' должен содержать 5 элементов + И узел JSON '' должен содержать 6 элементов И узел JSON "one" не должен быть null И узел JSON "one" должен быть ложью И узел JSON "two" не должен быть null @@ -187,3 +187,4 @@ И узел JSON "four" должен быть равен строке "foo" И узел JSON "five" не должен быть null И узел JSON "five" должен быть равен числу 5 + И узел JSON "six" должен быть равен строке "44000" diff --git a/tests/fixtures/www/json/notnullvalues.json b/tests/fixtures/www/json/notnullvalues.json index 58234c8e..8c1db598 100644 --- a/tests/fixtures/www/json/notnullvalues.json +++ b/tests/fixtures/www/json/notnullvalues.json @@ -3,5 +3,6 @@ "two": true, "three": "", "four": "foo", - "five": 5 + "five": 5, + "six": "44000" }