1 | <?php declare(strict_types=1); |
||
24 | abstract class AbstractContext implements Context |
||
25 | { |
||
26 | /** @var PropertyAccessor */ |
||
27 | private $accessor; |
||
28 | |||
29 | public function __construct() |
||
33 | |||
34 | /** |
||
35 | * Get the latest json response |
||
36 | * |
||
37 | * @return stdClass decoded json into an object |
||
38 | */ |
||
39 | abstract protected function getJson(); |
||
40 | |||
41 | /** |
||
42 | * Get the value for a path |
||
43 | * |
||
44 | * @param string $path Path to parse |
||
45 | * |
||
46 | * @return mixed |
||
47 | * @throws AccessException path not valid |
||
48 | */ |
||
49 | protected function getValue(string $path) |
||
53 | |||
54 | /** |
||
55 | * @Then the response should be a valid json response |
||
56 | * |
||
57 | * --- |
||
58 | * |
||
59 | * This method is built-on the default php's json extension. You should |
||
60 | * overwrite it if you want to add supplementary checks or use something |
||
61 | * else instead (such as Seldaek's JsonLint package). |
||
62 | */ |
||
63 | public function responseIsValidjson() |
||
69 | |||
70 | /** @Then :path should be accessible in the latest json response */ |
||
71 | public function pathShouldBeReadable(string $path) |
||
75 | |||
76 | /** @Then :path should not exist in the latest json response */ |
||
77 | public function pathShouldNotBeReadable(string $path) |
||
81 | |||
82 | /** @Then in the json, :path should be equal to :expected */ |
||
83 | public function theJsonPathShouldBeEqualTo(string $path, $expected) |
||
87 | |||
88 | /** @Then in the json, :path should not be equal to :expected */ |
||
89 | public function theJsonPathShouldNotBeEqualTo(string $path, $expected) |
||
93 | |||
94 | /** @Then in the json, :path should be: */ |
||
95 | public function theJsonPathShouldBePyString(string $path, PyStringNode $expected) |
||
99 | |||
100 | /** @Then /^in the json, "(?P<path>(?:[^"]|\\")*)" should be (?P<expected>true|false)$/ */ |
||
101 | public function theJsonPathShouldBe(string $path, string $expected) |
||
105 | |||
106 | /** @Then /^in the json, "(?P<path>(?:[^"]|\\")*)" should not be (?P<expected>true|false)$/ */ |
||
107 | public function theJsonPathShouldNotBe(string $path, string $expected) |
||
111 | |||
112 | /** @Then in the json, :path should be null */ |
||
113 | public function theJsonPathShouldBeNull(string $path) |
||
117 | |||
118 | /** @Then in the json, :path should not be null */ |
||
119 | public function theJsonPathShouldNotBeNull(string $path) |
||
123 | |||
124 | /** @Then in the json, :path should be empty */ |
||
125 | public function theJsonPathShouldBeEmpty(string $path) |
||
129 | |||
130 | /** @Then in the json, :path should not be empty */ |
||
131 | public function theJsonPathShouldNotBeEmpty(string $path) |
||
135 | |||
136 | /** @Then in the json, :path should contain :expected */ |
||
137 | public function theJsonPathContains(string $path, $expected) |
||
141 | |||
142 | /** @Then /^in the json, :path should not contain :expected */ |
||
143 | public function theJsonPathNotContains(string $path, $expected) |
||
147 | |||
148 | /** @Then in the json, :path collection should contain an element with :value equal to :expected */ |
||
149 | public function theJsonPathCollectionContains(string $path, string $value, $expected) |
||
161 | |||
162 | /** @Then in the json, :path should be a valid date(time) */ |
||
163 | public function theJsonPathShouldBeAValidDate(string $path) |
||
171 | |||
172 | /** @Then in the json, :path should be greater than :expected */ |
||
173 | public function theJsonPathShouldBeGreaterThan(string $path, int $expected) |
||
177 | |||
178 | /** @Then in the json, :path should be greater than or equal to :expected */ |
||
179 | public function theJsonPathShouldBeGreaterOrEqualThan(string $path, int $expected) |
||
183 | |||
184 | /** @Then in the json, :path should be less than :expected */ |
||
185 | public function theJsonPathShouldBeLessThan(string $path, int $expected) |
||
189 | |||
190 | /** @Then in the json, :path should be less than or equal to :expected */ |
||
191 | public function theJsonPathShouldBeLessOrEqualThan(string $path, int $expected) |
||
195 | |||
196 | /** @Then in the json, :path should be an array */ |
||
197 | public function shouldBeAnArray(string $path) |
||
201 | |||
202 | /** @Then in the json, :path should have at least :count element(s) */ |
||
203 | public function theJsonPathShouldHaveAtLeastElements(string $path, int $count) |
||
210 | |||
211 | /** @Then in the json, :path should have :count element(s) */ |
||
212 | public function theJsonPathShouldHaveElements(string $path, int $count) |
||
216 | |||
217 | /** @Then in the json, :path should have at most :count element(s) */ |
||
218 | public function theJsonPathShouldHaveAtMostElements(string $path, int $count) |
||
225 | |||
226 | /** @Then in the json, :path should match :pattern */ |
||
227 | public function theJsonPathShouldMatch(string $path, string $pattern) |
||
231 | |||
232 | /** |
||
233 | * @Then in the json, :path should not match :pattern |
||
234 | * |
||
235 | * ----- |
||
236 | * |
||
237 | * Note :: The body of this assertion should be replaced by a |
||
238 | * `Assert::notRegex` as soon as the Assert's PR |
||
239 | * https://github.com/webmozart/assert/pull/58 is merged and released. |
||
240 | */ |
||
241 | public function theJsonPathShouldNotMatch(string $path, string $pattern) |
||
250 | |||
251 | /** @Then in the json, the root should be an array */ |
||
252 | public function rootShouldBeAnArray() |
||
256 | |||
257 | /** @Then in the json, the root should have :count element(s) */ |
||
258 | public function theRootShouldHaveElements(int $count) |
||
265 | |||
266 | /** @Then in the json, the root should have at most :count element(s) */ |
||
267 | public function theRootShouldHaveAtMostElements(int $count) |
||
274 | |||
275 | /** @Then in the json, :path should be a valid json encoded string */ |
||
276 | public function theJsonPathShouldBeAValidJsonEncodedString(string $path) |
||
283 | } |
||
284 |
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: