From 175f62345d0a3a634f5c6733f62b0011340265dc Mon Sep 17 00:00:00 2001 From: nicolasheraly Date: Tue, 17 May 2016 15:24:06 +0200 Subject: [PATCH 1/2] Add theJsonNodeShouldNotBeNull method to JsonContext. --- src/Context/JsonContext.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Context/JsonContext.php b/src/Context/JsonContext.php index 1ea79d42..ad11e6a9 100644 --- a/src/Context/JsonContext.php +++ b/src/Context/JsonContext.php @@ -93,6 +93,18 @@ public function theJsonNodeShouldBeNull($node) } } + /** + * Checks, that given JSON node is not null. + * + * @Then the JSON node :node should not be null + */ + public function theJsonNodeShouldNotBeNull($name) + { + $this->not(function () use ($name) { + return $this->theJsonNodeShouldBeNull($name); + }, sprintf('The node %s should not be null', $name)); + } + /** * Checks, that given JSON node is true * From 2e1e31c1217997e98e79b7e3cd9d0e5c88c11804 Mon Sep 17 00:00:00 2001 From: nicolasheraly Date: Wed, 18 May 2016 10:27:46 +0200 Subject: [PATCH 2/2] Add scenario to check not null values. --- tests/features/json.feature | 15 +++++++++++++++ tests/fixtures/www/json/notnullvalues.json | 7 +++++++ 2 files changed, 22 insertions(+) create mode 100644 tests/fixtures/www/json/notnullvalues.json diff --git a/tests/features/json.feature b/tests/features/json.feature index 7c4c5f4b..a2ac923b 100644 --- a/tests/features/json.feature +++ b/tests/features/json.feature @@ -131,3 +131,18 @@ Feature: Testing JSONContext And the JSON node "root[4]" should be equal to the number 1312 And the JSON node "root[4]" should be equal to the number 1312.0 And the JSON node "root[5]" should be equal to the number 1936.2 + + 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 "one" should not be null + And the JSON node "one" should be false + And the JSON node "two" should not be null + And the JSON node "two" should be true + And the JSON node "three" should not be null + And the JSON node "three" should be equal to the string "" + And the JSON node "four" should not be null + 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 diff --git a/tests/fixtures/www/json/notnullvalues.json b/tests/fixtures/www/json/notnullvalues.json new file mode 100644 index 00000000..58234c8e --- /dev/null +++ b/tests/fixtures/www/json/notnullvalues.json @@ -0,0 +1,7 @@ +{ + "one": false, + "two": true, + "three": "", + "four": "foo", + "five": 5 +}