1 | <?php |
||
18 | abstract class AbstractJson implements Context |
||
19 | { |
||
20 | /** @var PropertyAccessor */ |
||
21 | private $accessor; |
||
22 | |||
23 | public function __construct() |
||
27 | |||
28 | /** |
||
29 | * Get the latest json response |
||
30 | * |
||
31 | * @return stdClass decoded json into an object |
||
32 | */ |
||
33 | abstract protected function getJson(): stdClass; |
||
34 | |||
35 | /** |
||
36 | * Get the value for a path |
||
37 | * |
||
38 | * @param string $path Path to parse |
||
39 | * |
||
40 | * @return mixed |
||
41 | * @throws AccessException path not valid |
||
42 | */ |
||
43 | protected function getValue(string $path) |
||
47 | |||
48 | /** |
||
49 | * @Then the response should be a valid json response |
||
50 | * |
||
51 | * --- |
||
52 | * |
||
53 | * This method is built-on the default php's json extension. You should |
||
54 | * overwrite it if you want to add supplementary checks or use something |
||
55 | * else instead (such as Seldaek's JsonLint package). |
||
56 | */ |
||
57 | public function responseIsValidjson() |
||
63 | |||
64 | /** @Then :path should be accessible in the latest json response */ |
||
65 | public function pathShouldBeReadable(string $path) |
||
69 | |||
70 | /** @Then :path should not exist in the latest json response */ |
||
71 | public function pathShouldNotBeReadable(string $path) |
||
75 | |||
76 | /** @Then in the json, :path should be equal to :expected */ |
||
77 | public function theJsonPathShouldBeEqualTo(string $path, $expected) |
||
81 | |||
82 | /** @Then in the json, :path should not be equal to :expected */ |
||
83 | public function theJsonPathShouldNotBeEqualTo(string $path, $expected) |
||
87 | |||
88 | /** @Then in the json, :path should be: */ |
||
89 | public function theJsonPathShouldBePyString(string $path, PyStringNode $expected) |
||
93 | |||
94 | /** @Then /^in the json, "(?P<path>(?:[^"]|\\")*)" should be (?P<expected>true|false)$/ */ |
||
95 | public function theJsonPathShouldBe(string $path, string $expected) |
||
99 | |||
100 | /** @Then /^in the json, "(?P<path>(?:[^"]|\\")*)" should not be (?P<expected>true|false)$/ */ |
||
101 | public function theJsonPathShouldNotBe(string $path, string $expected) |
||
105 | |||
106 | /** @Then in the json, :path should be null */ |
||
107 | public function theJsonPathShouldBeNull(string $path) |
||
111 | |||
112 | /** @Then in the json, :path should not be null */ |
||
113 | public function theJsonPathShouldNotBeNull(string $path) |
||
117 | |||
118 | /** @Then in the json, :path should be empty */ |
||
119 | public function theJsonPathShouldBeEmpty(string $path) |
||
123 | |||
124 | /** @Then in the json, :path should not be empty */ |
||
125 | public function theJsonPathShouldNotBeEmpty(string $path) |
||
129 | |||
130 | /** @Then in the json, :path should contain :expected */ |
||
131 | public function theJsonPathContains(string $path, $expected) |
||
135 | |||
136 | /** @Then /^in the json, :path should not contain :expected */ |
||
137 | public function theJsonPathNotContains(string $path, $expected) |
||
141 | |||
142 | /** @Then in the json, :path collection should contain an element with :value equal to :expected */ |
||
143 | public function theJsonPathCollectionContains(string $path, string $value, $expected) |
||
155 | |||
156 | /** @Then in the json, :path should be a valid date(time) */ |
||
157 | public function theJsonPathShouldBeAValidDate(string $path) |
||
165 | |||
166 | /** @Then in the json, :path should be greater than :expected */ |
||
167 | public function theJsonPathShouldBeGreaterThan(string $path, int $expected) |
||
171 | |||
172 | /** @Then in the json, :path should be greater than or equal to :expected */ |
||
173 | public function theJsonPathShouldBeGreaterOrEqualThan(string $path, int $expected) |
||
177 | |||
178 | /** @Then in the json, :path should be less than :expected */ |
||
179 | public function theJsonPathShouldBeLessThan(string $path, int $expected) |
||
183 | |||
184 | /** @Then in the json, :path should be less than or equal to :expected */ |
||
185 | public function theJsonPathShouldBeLessOrEqualThan(string $path, int $expected) |
||
189 | |||
190 | /** @Then in the json, :path should be an array */ |
||
191 | public function shouldBeAnArray(string $path) |
||
195 | |||
196 | /** @Then in the json, :path should have at least :count element(s) */ |
||
197 | public function theJsonPathShouldHaveAtLeastElements(string $path, int $count) |
||
204 | |||
205 | /** @Then in the json, :path should have :count element(s) */ |
||
206 | public function theJsonPathShouldHaveElements(string $path, int $count) |
||
210 | |||
211 | /** @Then in the json, :path should have at most :count element(s) */ |
||
212 | public function theJsonPathShouldHaveAtMostElements(string $path, int $count) |
||
219 | |||
220 | /** @Then in the json, :path should match :pattern */ |
||
221 | public function theJsonPathShouldMatch(string $path, string $pattern) |
||
225 | |||
226 | /** @Then in the json, :path should not match :pattern */ |
||
227 | public function theJsonPathShouldNotMatch(string $path, string $pattern) |
||
231 | |||
232 | /** @Then in the json, the root should be an array */ |
||
233 | public function rootShouldBeAnArray() |
||
237 | |||
238 | /** @Then in the json, the root should have :count element(s) */ |
||
239 | public function theRootShouldHaveElements(int $count) |
||
246 | |||
247 | /** @Then in the json, the root should have at most :count element(s) */ |
||
248 | public function theRootShouldHaveAtMostElements(int $count) |
||
255 | |||
256 | /** @Then in the json, :path should be a valid json encoded string */ |
||
257 | public function theJsonPathShouldBeAValidJsonEncodedString(string $path) |
||
264 | } |
||
265 |