This repository was archived by the owner on Apr 20, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 4 files changed +71
-1
lines changed
Expand file tree Collapse file tree 4 files changed +71
-1
lines changed Original file line number Diff line number Diff line change @@ -72,6 +72,43 @@ Feature: Testing JSONContext
7272 }
7373 """
7474
75+ Scenario : Json validation deep
76+ Given I am on "/json/booking.json"
77+ Then the JSON should be invalid according to this schema:
78+ """
79+ {
80+ "type":"object",
81+ "$schema": "http://json-schema.org/draft-03/schema",
82+ "required":false,
83+ "properties":{
84+ "Booking": {
85+ "type":"object",
86+ "required":false
87+ },
88+ "Metadata": {
89+ "type":"object",
90+ "required":false,
91+ "properties":{
92+ "First": {
93+ "type":"object",
94+ "required":false,
95+ "properties":{
96+ "default_value": {
97+ "type":"boolean",
98+ "required":false
99+ },
100+ "enabled": {
101+ "type":"boolean",
102+ "required":true
103+ }
104+ }
105+ }
106+ }
107+ }
108+ }
109+ }
110+ """
111+
75112 Scenario : Json contents validation
76113 Given I am on "/json/imajson.json"
77114 Then the JSON should be equal to:
Original file line number Diff line number Diff line change 1+ {
2+ "Booking" : {
3+ "id" : " 1" ,
4+ "price" : " 77.21"
5+ }, "Metadata" :
6+ {
7+ "First" : {
8+ "bad_property_name" : true ,
9+ "default_value" : true
10+ }
11+ }
12+ }
Original file line number Diff line number Diff line change 44
55use Behat \Gherkin \Node \PyStringNode ;
66
7+ use Behat \Mink \Exception \ExpectationException ;
78use Sanpi \Behatch \Json \Json ;
89use Sanpi \Behatch \Json \JsonSchema ;
910use Sanpi \Behatch \Json \JsonInspector ;
@@ -158,6 +159,26 @@ public function theJsonShouldBeValidAccordingToThisSchema(PyStringNode $schema)
158159 );
159160 }
160161
162+ /**
163+ * @Then the JSON should be invalid according to this schema:
164+ */
165+ public function theJsonShouldBeInvalidAccordingToThisSchema (PyStringNode $ schema )
166+ {
167+ try {
168+ $ isValid = $ this ->inspector ->validate (
169+ $ this ->getJson (),
170+ new JsonSchema ($ schema )
171+ );
172+
173+ } catch (\Exception $ e ) {
174+ $ isValid = false ;
175+ }
176+
177+ if (true === $ isValid ) {
178+ throw new ExpectationException ('Expected to receive invalid json, got valid one ' , $ this ->getSession ());
179+ }
180+ }
181+
161182 /**
162183 * @Then the JSON should be valid according to the schema :filename
163184 */
Original file line number Diff line number Diff line change 66
77class Json
88{
9- private $ content ;
9+ protected $ content ;
1010
1111 public function __construct ($ content )
1212 {
You can’t perform that action at this time.
0 commit comments