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

Test boolean values #278

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
language: php
dist: trusty

addons:
chrome: stable
Expand Down
8 changes: 8 additions & 0 deletions i18n/en.xliff.dist
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,14 @@
<source>the JSON node :node should contain :text</source>
<target></target>
</trans-unit>
<trans-unit id="the-json-node-should-be-a-boolean">
<source><![CDATA[the JSON node :name should be a boolean]]></source>
<target></target>
</trans-unit>
<trans-unit id="the-json-node-should-be-an-integer">
<source><![CDATA[the JSON node :name should be an integer]]></source>
<target></target>
</trans-unit>
<trans-unit id="the-json-nodes-should-contain">
<source>the JSON nodes should contain:</source>
<target></target>
Expand Down
8 changes: 8 additions & 0 deletions i18n/fr.xliff
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,14 @@
<source><![CDATA[the JSON node :node should contain :text]]></source>
<target><![CDATA[/^le n(?:œ|oe)ud JSON "(?P<node>[^"]*)" devrait contenir "(?P<text>[^"]*)"$/]]></target>
</trans-unit>
<trans-unit id="the-json-node-should-be-a-boolean">
<source><![CDATA[the JSON node :name should be a boolean]]></source>
<target><![CDATA[/^le n(?:œ|oe)ud JSON "(?P<node>[^"]*)" devrait être un booléen$/]]></target>
</trans-unit>
<trans-unit id="the-json-node-should-be-an-integer">
<source><![CDATA[the JSON node :name should be an integer]]></source>
<target><![CDATA[/^le n(?:œ|oe)ud JSON "(?P<node>[^"]*)" devrait être un entier$/]]></target>
</trans-unit>
<trans-unit id="the-json-nodes-should-contain">
<source><![CDATA[the JSON nodes should contain:]]></source>
<target><![CDATA[/^les n(?:œ|oe)uds JSON devraient contenir:$/]]></target>
Expand Down
16 changes: 16 additions & 0 deletions src/Asserter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}
}
25 changes: 25 additions & 0 deletions src/Context/JsonContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 13 additions & 1 deletion tests/features/fr/json.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -83,6 +85,14 @@ Fonctionnalité:
"type": "string",
"required":true
}
},
"bool_value": {
"type": "boolean",
"required": false
},
"integer_value": {
"type": "integer",
"required": false
}
}
}
Expand All @@ -107,7 +117,9 @@ Fonctionnalité:
}
]
}
]
],
"bool_value": true,
"integer_value": 1
}
"""
Et imprimer la dernière réponse JSON
Expand Down
12 changes: 11 additions & 1 deletion tests/features/ja/json.feature
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@
"type": "string",
"required":true
}
},
"bool_value": {
"type": "boolean",
"required": false
},
"integer_value": {
"type": "integer",
"required": false
}
}
}
Expand All @@ -97,7 +105,9 @@
}
]
}
]
],
"bool_value": true,
"integer_value": 1
}
"""
かつ 最後のJSONレスポンスを表示する
Expand Down
15 changes: 13 additions & 2 deletions tests/features/json.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down Expand Up @@ -89,6 +90,14 @@ Feature: Testing JSONContext
"type": "string",
"required":true
}
},
"bool_value": {
"type": "boolean",
"required": false
},
"integer_value": {
"type": "integer",
"required": false
}
}
}
Expand Down Expand Up @@ -150,7 +159,9 @@ Feature: Testing JSONContext
}
]
}
]
],
"bool_value": true,
"integer_value": 1
}
"""
And print last JSON response
Expand Down
12 changes: 11 additions & 1 deletion tests/features/pt/json.feature
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ Funcionalidade: Testando o JSONContext
"type": "string",
"required":true
}
},
"bool_value": {
"type": "boolean",
"required": false
},
"integer_value": {
"type": "integer",
"required": false
}
}
}
Expand All @@ -111,7 +119,9 @@ Funcionalidade: Testando o JSONContext
}
]
}
]
],
"bool_value": true,
"integer_value": 1
}
"""
E exiba a última resposta JSON
Expand Down
12 changes: 11 additions & 1 deletion tests/features/ru/json.feature
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@
"type": "string",
"required":true
}
},
"bool_value": {
"type": "boolean",
"required": false
},
"integer_value": {
"type": "integer",
"required": false
}
}
}
Expand Down Expand Up @@ -151,7 +159,9 @@
}
]
}
]
],
"bool_value": true,
"integer_value": 1
}
"""
И выведи последний JSON ответ
Expand Down
4 changes: 3 additions & 1 deletion tests/fixtures/www/json/imajson.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@
"complexeshizzle": true,
"so": ["very", {"complicated": "indeed"}]
}
]
],
"bool_value": true,
"integer_value": 1
}
8 changes: 8 additions & 0 deletions tests/fixtures/www/json/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@
"type": "string",
"required":true
}
},
"bool_value": {
"type": "boolean",
"required": false
},
"integer_value": {
"type": "integer",
"required": false
}
}
}