Skip to content
This repository has been archived by the owner on Apr 20, 2021. It is now read-only.

Commit

Permalink
Avoid bug with number when testing string
Browse files Browse the repository at this point in the history
Fixes #263
  • Loading branch information
alexislefebvre committed Oct 17, 2018
1 parent cbda31e commit d63995c
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/Context/JsonContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
3 changes: 2 additions & 1 deletion tests/features/json.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion tests/features/ru/json.feature
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@
Сценарий: Тестирование не-null значений
Пусть я на странице "/json/notnullvalues.json"
Тогда ответ должен быть в JSON
И узел JSON '' должен содержать 5 элементов
И узел JSON '' должен содержать 6 элементов
И узел JSON "one" не должен быть null
И узел JSON "one" должен быть ложью
И узел JSON "two" не должен быть null
Expand All @@ -187,3 +187,4 @@
И узел JSON "four" должен быть равен строке "foo"
И узел JSON "five" не должен быть null
И узел JSON "five" должен быть равен числу 5
И узел JSON "six" должен быть равен строке "44000"
3 changes: 2 additions & 1 deletion tests/fixtures/www/json/notnullvalues.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
"two": true,
"three": "",
"four": "foo",
"five": 5
"five": 5,
"six": "44000"
}

0 comments on commit d63995c

Please sign in to comment.