1 | <?php |
||
31 | class FeatureContext extends JsonContext implements SnippetAcceptingContext |
||
32 | { |
||
33 | /** |
||
34 | * The authentication. |
||
35 | * |
||
36 | * @var Authentication |
||
37 | */ |
||
38 | private $authentication; |
||
39 | |||
40 | /** |
||
41 | * The response data transformer. |
||
42 | * |
||
43 | * @var ResponseDataTransformer |
||
44 | */ |
||
45 | private $dataTransformer; |
||
46 | |||
47 | /** |
||
48 | * The command handler. |
||
49 | * |
||
50 | * @var mixed |
||
51 | */ |
||
52 | private $handler; |
||
53 | |||
54 | /** |
||
55 | * The HTTP client. |
||
56 | * |
||
57 | * @var Http |
||
58 | */ |
||
59 | private $http; |
||
60 | |||
61 | /** |
||
62 | * The handler's returned data. |
||
63 | * |
||
64 | * @var ResponseInterface|Model |
||
65 | */ |
||
66 | private $response; |
||
67 | |||
68 | /** |
||
69 | * Uses Guzzle as HTTP client. |
||
70 | * |
||
71 | * @Then the request uses Guzzle as HTTP client |
||
72 | */ |
||
73 | public function guzzle() |
||
85 | |||
86 | /** |
||
87 | * Added authentication to the requests. |
||
88 | * |
||
89 | * This method contains a hardcoded application key |
||
90 | * and access token to test purposes. |
||
91 | * |
||
92 | * @Then the request needs authentication |
||
93 | */ |
||
94 | public function theRequestNeedsAuthentication() |
||
100 | |||
101 | /** |
||
102 | * Adds response data transformer with given type class. |
||
103 | * |
||
104 | * @param string $resource The resource name: e.j. "answer" |
||
105 | * @param string $typeClass The fully qualified of type class |
||
106 | * |
||
107 | * @Then the request uses response :resource data transformer with :typeClass |
||
108 | */ |
||
109 | public function theRequestUsesResponseTransformerWith($resource, $typeClass) |
||
114 | |||
115 | /** |
||
116 | * Adds no transformation data transformer. |
||
117 | * |
||
118 | * @Then the request uses response no transformation data transformer |
||
119 | */ |
||
120 | public function theRequestUsesNoTransformationDataTransformer() |
||
124 | |||
125 | /** |
||
126 | * Builds the command handler with given values. |
||
127 | * |
||
128 | * @param string $resource The resource name: e.j. "answer" |
||
129 | * @param string $handler The handler class name |
||
130 | * |
||
131 | * @Then builds the :resource's :handler handler |
||
132 | */ |
||
133 | public function build($resource, $handler) |
||
142 | |||
143 | /** |
||
144 | * Handles the command. |
||
145 | * |
||
146 | * @param string $resource The resource name: e.j. "answer" |
||
147 | * @param string $command The command class name |
||
148 | * @param string $options The additional options as query params |
||
149 | * |
||
150 | * @Then handles the :resource's :command with :options options |
||
151 | */ |
||
152 | public function handle($resource, $command, $options) |
||
161 | |||
162 | /** |
||
163 | * Handles the command with the given arguments. |
||
164 | * |
||
165 | * @param string $resource The resource name: e.j. "answer" |
||
166 | * @param string $command The command class name |
||
167 | * @param string $arguments The arguments needed to build the correct request |
||
168 | * @param string $options The additional options as query params |
||
169 | * |
||
170 | * @Then handles the :resource's :command with :arguments and :options options |
||
171 | */ |
||
172 | public function handleWith($resource, $command, $arguments, $options) |
||
182 | |||
183 | /** |
||
184 | * Checks if the returned response is a json or a given instance. |
||
185 | * |
||
186 | * @param string|null $instance The instance of response, it can be null |
||
187 | * |
||
188 | * @throws \Exception when the response is not a valid instance |
||
189 | * @throws \Exception when the response is not a valid JSON |
||
190 | * |
||
191 | * @Then the response is a collection of :instance |
||
192 | * @Then the response is an instance of :instance |
||
193 | * @Then the response is a json |
||
194 | */ |
||
195 | public function theResponseIs($instance = null) |
||
216 | |||
217 | /** |
||
218 | * Checks if the given value of property is the same of the response value. |
||
219 | * |
||
220 | * @param string $property The class property |
||
221 | * @param string $value The class property value |
||
222 | * @param int $item The index of response, by default is 1 |
||
223 | * |
||
224 | * @throws \Exception when the response value is different of the given value |
||
225 | * |
||
226 | * @Then the :property gets :value |
||
227 | * @Then the :property of the item :item, gets :value |
||
228 | */ |
||
229 | public function theGivenPropertyGetsValue($property, $value, $item = 1) |
||
256 | |||
257 | /** |
||
258 | * Prints the response content. |
||
259 | * |
||
260 | * @Then /^print last response$/ |
||
261 | */ |
||
262 | public function printLastResponse() |
||
270 | |||
271 | /** |
||
272 | * {@inheritdoc} |
||
273 | */ |
||
274 | protected function getJson() |
||
278 | |||
279 | /** |
||
280 | * Gets the namespaced class name of given data transformer class. |
||
281 | * |
||
282 | * @param string $class The class name |
||
283 | * |
||
284 | * @return string |
||
285 | */ |
||
286 | private function getResponseDataTransformer($class) |
||
297 | |||
298 | /** |
||
299 | * Gets the namespaced class name of given command class. |
||
300 | * |
||
301 | * @param string $type The resource name: e.j. "answer" |
||
302 | * @param string $class The class name |
||
303 | * |
||
304 | * @return string |
||
305 | */ |
||
306 | private function getCommand($type, $class) |
||
310 | |||
311 | /** |
||
312 | * Gets the namespaced class name of given command handler class. |
||
313 | * |
||
314 | * @param string $type The resource name: e.j. "answer" |
||
315 | * @param string $class The class name |
||
316 | * |
||
317 | * @return string |
||
318 | */ |
||
319 | private function getCommandHandler($type, $class) |
||
327 | |||
328 | /** |
||
329 | * Gets the namespaced class of domain model class implementation. |
||
330 | * |
||
331 | * @param string $class The class name |
||
332 | * |
||
333 | * @return string |
||
334 | */ |
||
335 | private function getModelClass($class) |
||
343 | |||
344 | /** |
||
345 | * Checks if the given JSON is valid or not. |
||
346 | * |
||
347 | * @param string $json The JSON |
||
348 | * |
||
349 | * @return bool |
||
350 | */ |
||
351 | private function isValidJson($json) |
||
357 | } |
||
358 |