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 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/src/Asserter.php b/src/Asserter.php index 58de681b..d7996b55 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 not a boolean') + { + $this->assert( + gettype($value) === 'boolean', + $message + ); + } + + protected function assertIsInteger($value, $message = 'The value is not an integer') + { + $this->assert( + gettype($value) === 'integer', + $message + ); + } } diff --git a/src/Context/JsonContext.php b/src/Context/JsonContext.php index d835fc91..318b7980 100644 --- a/src/Context/JsonContext.php +++ b/src/Context/JsonContext.php @@ -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->assertIsBoolean($actual); + } + + /** + * Checks if the json node value is an integer. + * + * @Then the JSON node :name should be an integer + */ + public function theJSONNodeShouldBeanInteger($node) + { + $json = $this->getJson(); + $actual = $this->inspector->evaluate($json, $node); + $this->assertIsInteger($actual); + } + /** * * Checks, that response JSON not matches with a swagger dump 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/json.feature b/tests/features/json.feature index 3521f60c..f0cfcb1b 100644 --- a/tests/features/json.feature +++ b/tests/features/json.feature @@ -31,7 +31,8 @@ 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 "bool_value" should be a boolean + And the JSON node "integer_value" should be an integer And the JSON nodes should be equal to: | foo | bar | | numbers[0] | öne | @@ -89,6 +90,14 @@ Feature: Testing JSONContext "type": "string", "required":true } + }, + "bool_value": { + "type": "boolean", + "required": false + }, + "integer_value": { + "type": "integer", + "required": false } } } @@ -150,7 +159,9 @@ Feature: Testing JSONContext } ] } - ] + ], + "bool_value": true, + "integer_value": 1 } """ And print last JSON response 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 ответ diff --git a/tests/fixtures/www/json/imajson.json b/tests/fixtures/www/json/imajson.json index 4a9726c2..03f9ece3 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, + "integer_value": 1 } 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 } } }