From 0b6c0971ba5522165a8acd6e7df91b33d5bb97a7 Mon Sep 17 00:00:00 2001 From: gpenverne Date: Fri, 29 Nov 2019 12:03:03 +0100 Subject: [PATCH 01/15] Then the JSON node :name should be a boolean --- src/Context/JsonContext.php | 27 ++++++++++++++++++++++++++- tests/features/json.feature | 4 +++- tests/fixtures/www/json/imajson.json | 4 +++- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/Context/JsonContext.php b/src/Context/JsonContext.php index d835fc91..2408d1c9 100644 --- a/src/Context/JsonContext.php +++ b/src/Context/JsonContext.php @@ -370,7 +370,7 @@ public function printLastJsonResponse() } /** - * Checks, that response JSON matches with a swagger dump + * Checks, that response JSON not matches with a swagger dump * * @Then the JSON should be valid according to swagger :dumpPath dump schema :schemaName */ @@ -390,6 +390,31 @@ public function theJsonShouldBeValidAccordingToTheSwaggerSchema($dumpPath, $sche ) ); } + + /** + * Checks if the json node value is a boolean not an integer. + * + * @Then the JSON node :name should be a boolean + */ + public function theJSONNodeShouldBeaBoolean($node) + { + $json = $this->getJson(); + $actual = $this->inspector->evaluate($json, $node); + $this->assertSame($actual, (bool) $actual); + } + + /** + * Checks if the json node value is a boolean not an integer. + * + * @Then the JSON node :name should not be a boolean + */ + public function theJSONNodeShouldBeaBoolean($node) + { + $json = $this->getJson(); + $actual = $this->inspector->evaluate($json, $node); + $this->assertSame($actual, (int) $actual); + } + /** * * Checks, that response JSON not matches with a swagger dump diff --git a/tests/features/json.feature b/tests/features/json.feature index 3521f60c..27942be9 100644 --- a/tests/features/json.feature +++ b/tests/features/json.feature @@ -31,7 +31,9 @@ Feature: Testing JSONContext And the JSON node "numbers[0]" should match "/ö.{1}e/" And the JSON node "numbers[1]" should match "/.{2}o/" And the JSON node "numbers[2]" should match "/[a-z]{3}e.+/" - + And the JSON node "numbers[]" + And the JSON node "bool_value" should be a boolean + And the JSON node "not_bool_value" should not be a boolean And the JSON nodes should be equal to: | foo | bar | | numbers[0] | öne | diff --git a/tests/fixtures/www/json/imajson.json b/tests/fixtures/www/json/imajson.json index 4a9726c2..4e9cbab2 100644 --- a/tests/fixtures/www/json/imajson.json +++ b/tests/fixtures/www/json/imajson.json @@ -8,5 +8,7 @@ "complexeshizzle": true, "so": ["very", {"complicated": "indeed"}] } - ] + ], + "bool_value": true, + "not_bool_value": 1 } From 21eaf884f612f65aff8d88919aa1ee07c6be7517 Mon Sep 17 00:00:00 2001 From: gpenverne Date: Fri, 29 Nov 2019 12:11:12 +0100 Subject: [PATCH 02/15] Checks if the json node value is an integer --- src/Context/JsonContext.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Context/JsonContext.php b/src/Context/JsonContext.php index 2408d1c9..aea09c36 100644 --- a/src/Context/JsonContext.php +++ b/src/Context/JsonContext.php @@ -400,19 +400,19 @@ public function theJSONNodeShouldBeaBoolean($node) { $json = $this->getJson(); $actual = $this->inspector->evaluate($json, $node); - $this->assertSame($actual, (bool) $actual); + $this->assertSame((bool) $actual, $actual); } /** - * Checks if the json node value is a boolean not an integer. + * Checks if the json node value is an integer. * - * @Then the JSON node :name should not be a boolean + * @Then the JSON node :name should be an integer */ - public function theJSONNodeShouldBeaBoolean($node) + public function theJSONNodeShouldBeanInteger($node) { $json = $this->getJson(); $actual = $this->inspector->evaluate($json, $node); - $this->assertSame($actual, (int) $actual); + $this->assertSame((int) $actual, $actual); } /** From 96bea635dab37a8d136ed924b40a080695c7e28c Mon Sep 17 00:00:00 2001 From: gpenverne Date: Fri, 29 Nov 2019 12:11:31 +0100 Subject: [PATCH 03/15] integer test --- tests/features/json.feature | 2 +- tests/fixtures/www/json/imajson.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/features/json.feature b/tests/features/json.feature index 27942be9..4b38a9b9 100644 --- a/tests/features/json.feature +++ b/tests/features/json.feature @@ -33,7 +33,7 @@ Feature: Testing JSONContext And the JSON node "numbers[2]" should match "/[a-z]{3}e.+/" And the JSON node "numbers[]" And the JSON node "bool_value" should be a boolean - And the JSON node "not_bool_value" should not be a boolean + And the JSON node "not_bool_value" should be an integer And the JSON nodes should be equal to: | foo | bar | | numbers[0] | öne | diff --git a/tests/fixtures/www/json/imajson.json b/tests/fixtures/www/json/imajson.json index 4e9cbab2..03f9ece3 100644 --- a/tests/fixtures/www/json/imajson.json +++ b/tests/fixtures/www/json/imajson.json @@ -10,5 +10,5 @@ } ], "bool_value": true, - "not_bool_value": 1 + "integer_value": 1 } From 6c7eee6286f4225f776d8cfa010a7868606cd882 Mon Sep 17 00:00:00 2001 From: gpenverne Date: Fri, 29 Nov 2019 12:14:51 +0100 Subject: [PATCH 04/15] :construction: wip --- src/Context/JsonContext.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Context/JsonContext.php b/src/Context/JsonContext.php index aea09c36..80a4ec1f 100644 --- a/src/Context/JsonContext.php +++ b/src/Context/JsonContext.php @@ -370,7 +370,7 @@ public function printLastJsonResponse() } /** - * Checks, that response JSON not matches with a swagger dump + * Checks, that response JSON matches with a swagger dump * * @Then the JSON should be valid according to swagger :dumpPath dump schema :schemaName */ From 185c7b2cc5783fa96dd7a30b4dd66ad5b8a187f2 Mon Sep 17 00:00:00 2001 From: gpenverne Date: Fri, 29 Nov 2019 12:15:27 +0100 Subject: [PATCH 05/15] :tophat: Handle behat tests --- tests/features/json.feature | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/features/json.feature b/tests/features/json.feature index 4b38a9b9..dc92a935 100644 --- a/tests/features/json.feature +++ b/tests/features/json.feature @@ -31,7 +31,6 @@ Feature: Testing JSONContext And the JSON node "numbers[0]" should match "/ö.{1}e/" And the JSON node "numbers[1]" should match "/.{2}o/" And the JSON node "numbers[2]" should match "/[a-z]{3}e.+/" - And the JSON node "numbers[]" And the JSON node "bool_value" should be a boolean And the JSON node "not_bool_value" should be an integer And the JSON nodes should be equal to: From 069fcf75cb2c2d3a5fe7f29367e5e1b6f3baa41c Mon Sep 17 00:00:00 2001 From: gpenverne Date: Fri, 29 Nov 2019 12:44:38 +0100 Subject: [PATCH 06/15] :tophat: Better safe than sorry --- tests/features/json.feature | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/features/json.feature b/tests/features/json.feature index dc92a935..e996eeb2 100644 --- a/tests/features/json.feature +++ b/tests/features/json.feature @@ -32,7 +32,7 @@ Feature: Testing JSONContext And the JSON node "numbers[1]" should match "/.{2}o/" And the JSON node "numbers[2]" should match "/[a-z]{3}e.+/" And the JSON node "bool_value" should be a boolean - And the JSON node "not_bool_value" should be an integer + And the JSON node "integer_value" should be an integer And the JSON nodes should be equal to: | foo | bar | | numbers[0] | öne | @@ -151,7 +151,9 @@ Feature: Testing JSONContext } ] } - ] + ], + "bool_value": true, + "integer_value": 1 } """ And print last JSON response @@ -176,7 +178,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 From 91a5c15a50bdba91afde49f03b395c9c81bfdbcd Mon Sep 17 00:00:00 2001 From: gpenverne Date: Mon, 9 Dec 2019 09:52:10 +0100 Subject: [PATCH 07/15] Use Asserter --- src/Asserter.php | 16 ++++++++++++++++ src/Context/JsonContext.php | 4 ++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/Asserter.php b/src/Asserter.php index 58de681b..e03157d6 100644 --- a/src/Asserter.php +++ b/src/Asserter.php @@ -96,4 +96,20 @@ protected function assertFalse($value, $message = 'The value is true') $this->assertTrue($value); }, $message); } + + protected function assertIsBoolean($value, $message = 'The value is a boolean') + { + $this->assert( + gettype($value) === 'boolean', + $message ?: "Value '$value' is not a boolean" + ); + } + + protected function assertInteger($value, $message = 'The value is an integer') + { + $this->assert( + gettype($value) === 'integer', + $message ?: "Value '$value' is not an integer" + ); + } } diff --git a/src/Context/JsonContext.php b/src/Context/JsonContext.php index 80a4ec1f..318b7980 100644 --- a/src/Context/JsonContext.php +++ b/src/Context/JsonContext.php @@ -400,7 +400,7 @@ public function theJSONNodeShouldBeaBoolean($node) { $json = $this->getJson(); $actual = $this->inspector->evaluate($json, $node); - $this->assertSame((bool) $actual, $actual); + $this->assertIsBoolean($actual); } /** @@ -412,7 +412,7 @@ public function theJSONNodeShouldBeanInteger($node) { $json = $this->getJson(); $actual = $this->inspector->evaluate($json, $node); - $this->assertSame((int) $actual, $actual); + $this->assertIsInteger($actual); } /** From 1cda96eb63fc45b10073de783dbee643f3ccea37 Mon Sep 17 00:00:00 2001 From: gpenverne Date: Mon, 9 Dec 2019 10:02:44 +0100 Subject: [PATCH 08/15] remove useless message assignement --- src/Asserter.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Asserter.php b/src/Asserter.php index e03157d6..44270403 100644 --- a/src/Asserter.php +++ b/src/Asserter.php @@ -97,19 +97,19 @@ protected function assertFalse($value, $message = 'The value is true') }, $message); } - protected function assertIsBoolean($value, $message = 'The value is a boolean') + protected function assertIsBoolean($value, $message = 'The value is not a boolean') { $this->assert( gettype($value) === 'boolean', - $message ?: "Value '$value' is not a boolean" + $message ); } - protected function assertInteger($value, $message = 'The value is an integer') + protected function assertInteger($value, $message = 'The value is not an integer') { $this->assert( gettype($value) === 'integer', - $message ?: "Value '$value' is not an integer" + $message ); } } From 92ed937f22b88271ac640f2e6cc114eb48c618a0 Mon Sep 17 00:00:00 2001 From: gpenverne Date: Mon, 9 Dec 2019 10:32:43 +0100 Subject: [PATCH 09/15] try to fix travis ci --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index a1c5395d..51fc2211 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,5 @@ language: php +dist: trusty addons: chrome: stable From d75709719407d31ab20e26a3c1ebd408b0e66094 Mon Sep 17 00:00:00 2001 From: gpenverne Date: Mon, 9 Dec 2019 13:59:58 +0100 Subject: [PATCH 10/15] Wrong method name --- src/Asserter.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Asserter.php b/src/Asserter.php index 44270403..d7996b55 100644 --- a/src/Asserter.php +++ b/src/Asserter.php @@ -105,7 +105,7 @@ protected function assertIsBoolean($value, $message = 'The value is not a boolea ); } - protected function assertInteger($value, $message = 'The value is not an integer') + protected function assertIsInteger($value, $message = 'The value is not an integer') { $this->assert( gettype($value) === 'integer', From 3f614c07522a7223f755f72b2f6924a3b767d58e Mon Sep 17 00:00:00 2001 From: gpenverne Date: Mon, 9 Dec 2019 14:06:31 +0100 Subject: [PATCH 11/15] revert behat test --- tests/features/json.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/features/json.feature b/tests/features/json.feature index e996eeb2..86eb4a44 100644 --- a/tests/features/json.feature +++ b/tests/features/json.feature @@ -178,7 +178,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 6 elements + 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 From 9a1c1c9837aa81e54e70292f3c1a27a66324014f Mon Sep 17 00:00:00 2001 From: gpenverne Date: Mon, 9 Dec 2019 14:38:23 +0100 Subject: [PATCH 12/15] other behat --- tests/features/json.feature | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/features/json.feature b/tests/features/json.feature index 86eb4a44..991005b0 100644 --- a/tests/features/json.feature +++ b/tests/features/json.feature @@ -90,6 +90,14 @@ Feature: Testing JSONContext "type": "string", "required":true } + }, + "bool_value": { + "type": "bool", + "required": false + }, + "integer_value": { + "type": "integer", + "required": false } } } From a3753add41c558117b4b4865ad341515fd028f28 Mon Sep 17 00:00:00 2001 From: gpenverne Date: Mon, 9 Dec 2019 14:58:30 +0100 Subject: [PATCH 13/15] fix bool vs boolean (behat) --- tests/features/json.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/features/json.feature b/tests/features/json.feature index 991005b0..f0cfcb1b 100644 --- a/tests/features/json.feature +++ b/tests/features/json.feature @@ -92,7 +92,7 @@ Feature: Testing JSONContext } }, "bool_value": { - "type": "bool", + "type": "boolean", "required": false }, "integer_value": { From 98d013633283ebc3307bd1c1372e809c8b48096f Mon Sep 17 00:00:00 2001 From: gpenverne Date: Mon, 9 Dec 2019 15:24:17 +0100 Subject: [PATCH 14/15] update json schema for behat --- tests/fixtures/www/json/schema.json | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/fixtures/www/json/schema.json b/tests/fixtures/www/json/schema.json index fd78886d..dc066581 100644 --- a/tests/fixtures/www/json/schema.json +++ b/tests/fixtures/www/json/schema.json @@ -22,6 +22,14 @@ "type": "string", "required":true } + }, + "bool_value": { + "type": "boolean", + "required": false + }, + "integer_value": { + "type": "integer", + "required": false } } } From d6d820d6b32d29ad920a8d13ebc367d3d1853275 Mon Sep 17 00:00:00 2001 From: gpenverne Date: Mon, 9 Dec 2019 16:02:37 +0100 Subject: [PATCH 15/15] french translations --- i18n/en.xliff.dist | 8 ++++++++ i18n/fr.xliff | 8 ++++++++ tests/features/fr/json.feature | 14 +++++++++++++- tests/features/ja/json.feature | 12 +++++++++++- tests/features/pt/json.feature | 12 +++++++++++- tests/features/ru/json.feature | 12 +++++++++++- 6 files changed, 62 insertions(+), 4 deletions(-) diff --git a/i18n/en.xliff.dist b/i18n/en.xliff.dist index 54e63bb8..a58fa316 100644 --- a/i18n/en.xliff.dist +++ b/i18n/en.xliff.dist @@ -243,6 +243,14 @@ the JSON node :node should contain :text + + + + + + + + the JSON nodes should contain: diff --git a/i18n/fr.xliff b/i18n/fr.xliff index 8ac50a0b..ee0b43d1 100644 --- a/i18n/fr.xliff +++ b/i18n/fr.xliff @@ -227,6 +227,14 @@ [^"]*)" devrait contenir "(?P[^"]*)"$/]]> + + + [^"]*)" devrait être un booléen$/]]> + + + + [^"]*)" devrait être un entier$/]]> + diff --git a/tests/features/fr/json.feature b/tests/features/fr/json.feature index 8bb92bba..f1d9a6bb 100644 --- a/tests/features/fr/json.feature +++ b/tests/features/fr/json.feature @@ -26,6 +26,8 @@ Fonctionnalité: Et le nœud JSON "numbers[0]" devrait contenir "öne" Et le nœud JSON "numbers[1]" devrait contenir "two" Et le nœud JSON "numbers[2]" devrait contenir "three" + Et le nœud JSON "bool_value" devrait être un booléen + Et le nœud JSON "integer_value" devrait être un entier Et le nœud JSON "numbers[3].complexeshizzle" devrait être égal à "true" Et le nœud JSON "numbers[3].so[0]" devrait être égal à "very" Et le nœud JSON "numbers[3].so[1].complicated" devrait être égal à "indeed" @@ -83,6 +85,14 @@ Fonctionnalité: "type": "string", "required":true } + }, + "bool_value": { + "type": "boolean", + "required": false + }, + "integer_value": { + "type": "integer", + "required": false } } } @@ -107,7 +117,9 @@ Fonctionnalité: } ] } - ] + ], + "bool_value": true, + "integer_value": 1 } """ Et imprimer la dernière réponse JSON diff --git a/tests/features/ja/json.feature b/tests/features/ja/json.feature index d417ced6..5a862644 100644 --- a/tests/features/ja/json.feature +++ b/tests/features/ja/json.feature @@ -72,6 +72,14 @@ "type": "string", "required":true } + }, + "bool_value": { + "type": "boolean", + "required": false + }, + "integer_value": { + "type": "integer", + "required": false } } } @@ -97,7 +105,9 @@ } ] } - ] + ], + "bool_value": true, + "integer_value": 1 } """ かつ 最後のJSONレスポンスを表示する diff --git a/tests/features/pt/json.feature b/tests/features/pt/json.feature index d6d1b90b..7f128c87 100644 --- a/tests/features/pt/json.feature +++ b/tests/features/pt/json.feature @@ -87,6 +87,14 @@ Funcionalidade: Testando o JSONContext "type": "string", "required":true } + }, + "bool_value": { + "type": "boolean", + "required": false + }, + "integer_value": { + "type": "integer", + "required": false } } } @@ -111,7 +119,9 @@ Funcionalidade: Testando o JSONContext } ] } - ] + ], + "bool_value": true, + "integer_value": 1 } """ E exiba a última resposta JSON diff --git a/tests/features/ru/json.feature b/tests/features/ru/json.feature index fa138626..f690ed80 100644 --- a/tests/features/ru/json.feature +++ b/tests/features/ru/json.feature @@ -90,6 +90,14 @@ "type": "string", "required":true } + }, + "bool_value": { + "type": "boolean", + "required": false + }, + "integer_value": { + "type": "integer", + "required": false } } } @@ -151,7 +159,9 @@ } ] } - ] + ], + "bool_value": true, + "integer_value": 1 } """ И выведи последний JSON ответ