1 | <?php |
||
10 | class JsonContext implements Context, SnippetAcceptingContext |
||
11 | { |
||
12 | private $jsonInspector; |
||
13 | |||
14 | private $asserter; |
||
15 | |||
16 | private $jsonSchemaBaseUrl; |
||
17 | |||
18 | public function __construct(JsonInspector $jsonInspector, $jsonSchemaBaseUrl = null) |
||
19 | { |
||
20 | $this->jsonInspector = $jsonInspector; |
||
21 | $this->asserter = new asserter; |
||
22 | $this->jsonSchemaBaseUrl = rtrim($jsonSchemaBaseUrl, '/'); |
||
23 | } |
||
24 | |||
25 | /** |
||
26 | * @When /^I load JSON:$/ |
||
27 | */ |
||
28 | public function iLoadJson(PyStringNode $jsonContent) |
||
32 | |||
33 | /** |
||
34 | * @Then /^the response should be in JSON$/ |
||
35 | */ |
||
36 | public function responseShouldBeInJson() |
||
40 | |||
41 | /** |
||
42 | * @Then /^the JSON node "(?P<jsonNode>[^"]*)" should be equal to "(?P<expectedValue>.*)"$/ |
||
43 | */ |
||
44 | public function theJsonNodeShouldBeEqualTo($jsonNode, $expectedValue) |
||
50 | |||
51 | /** |
||
52 | * @Then /^the JSON node "(?P<jsonNode>[^"]*)" should have (?P<expectedNth>\d+) elements?$/ |
||
53 | * @Then /^the JSON array node "(?P<jsonNode>[^"]*)" should have (?P<expectedNth>\d+) elements?$/ |
||
54 | */ |
||
55 | public function theJsonNodeShouldHaveElements($jsonNode, $expectedNth) |
||
61 | |||
62 | /** |
||
63 | * @Then /^the JSON array node "(?P<jsonNode>[^"]*)" should contain "(?P<expectedValue>.*)" element$/ |
||
64 | */ |
||
65 | public function theJsonArrayNodeShouldContainElements($jsonNode, $expectedValue) |
||
71 | |||
72 | /** |
||
73 | * @Then /^the JSON node "(?P<jsonNode>[^"]*)" should contain "(?P<expectedValue>.*)"$/ |
||
74 | */ |
||
75 | public function theJsonNodeShouldContain($jsonNode, $expectedValue) |
||
81 | |||
82 | /** |
||
83 | * Checks, that given JSON node does not contain given value |
||
84 | * |
||
85 | * @Then /^the JSON node "(?P<jsonNode>[^"]*)" should not contain "(?P<unexpectedValue>.*)"$/ |
||
86 | */ |
||
87 | public function theJsonNodeShouldNotContain($jsonNode, $unexpectedValue) |
||
93 | |||
94 | /** |
||
95 | * Checks, that given JSON node exist |
||
96 | * |
||
97 | * @Given /^the JSON node "(?P<jsonNode>[^"]*)" should exist$/ |
||
98 | */ |
||
99 | public function theJsonNodeShouldExist($jsonNode) |
||
107 | |||
108 | /** |
||
109 | * Checks, that given JSON node does not exist |
||
110 | * |
||
111 | * @Given /^the JSON node "(?P<jsonNode>[^"]*)" should not exist$/ |
||
112 | */ |
||
113 | public function theJsonNodeShouldNotExist($jsonNode) |
||
127 | |||
128 | /** |
||
129 | * @Then /^the JSON should be valid according to this schema:$/ |
||
130 | */ |
||
131 | public function theJsonShouldBeValidAccordingToThisSchema(PyStringNode $jsonSchemaContent) |
||
137 | |||
138 | /** |
||
139 | * @Then /^the JSON should be valid according to the schema "(?P<filename>[^"]*)"$/ |
||
140 | */ |
||
141 | public function theJsonShouldBeValidAccordingToTheSchema($filename) |
||
152 | |||
153 | /** |
||
154 | * @Then /^the JSON should be equal to:$/ |
||
155 | */ |
||
156 | public function theJsonShouldBeEqualTo(PyStringNode $jsonContent) |
||
168 | |||
169 | private function evaluateJsonNodeValue($jsonNode) |
||
173 | |||
174 | private function readJson() |
||
178 | |||
179 | private function resolveFilename($filename) |
||
203 | } |
||
204 |