1 | <?php |
||
24 | class WebApiContext implements ApiClientAwareContext |
||
25 | { |
||
26 | /** |
||
27 | * @var string |
||
28 | */ |
||
29 | private $authorization; |
||
30 | |||
31 | /** |
||
32 | * @var ClientInterface |
||
33 | */ |
||
34 | private $client; |
||
35 | |||
36 | /** |
||
37 | * @var array |
||
38 | */ |
||
39 | private $headers = array(); |
||
40 | |||
41 | /** |
||
42 | * @var \GuzzleHttp\Message\RequestInterface |
||
43 | */ |
||
44 | private $request; |
||
45 | |||
46 | /** |
||
47 | * @var \GuzzleHttp\Message\ResponseInterface |
||
48 | */ |
||
49 | private $response; |
||
50 | |||
51 | private $placeHolders = array(); |
||
52 | |||
53 | /** |
||
54 | * {@inheritdoc} |
||
55 | */ |
||
56 | public function setClient(ClientInterface $client) |
||
60 | |||
61 | /** |
||
62 | * Adds Basic Authentication header to next request. |
||
63 | * |
||
64 | * @param string $username |
||
65 | * @param string $password |
||
66 | * |
||
67 | * @Given /^I am authenticating as "([^"]*)" with "([^"]*)" password$/ |
||
68 | */ |
||
69 | public function iAmAuthenticatingAs($username, $password) |
||
75 | |||
76 | /** |
||
77 | * Sets a HTTP Header. |
||
78 | * |
||
79 | * @param string $name header name |
||
80 | * @param string $value header value |
||
81 | * |
||
82 | * @Given /^I set header "([^"]*)" with value "([^"]*)"$/ |
||
83 | */ |
||
84 | public function iSetHeaderWithValue($name, $value) |
||
88 | |||
89 | /** |
||
90 | * Sends HTTP request to specific relative URL. |
||
91 | * |
||
92 | * @param string $method request method |
||
93 | * @param string $url relative url |
||
94 | * |
||
95 | * @When /^(?:I )?send a ([A-Z]+) request to "([^"]+)"$/ |
||
96 | */ |
||
97 | public function iSendARequest($method, $url) |
||
107 | |||
108 | /** |
||
109 | * Sends HTTP request to specific URL with field values from Table. |
||
110 | * |
||
111 | * @param string $method request method |
||
112 | * @param string $url relative url |
||
113 | * @param TableNode $post table of post values |
||
114 | * |
||
115 | * @When /^(?:I )?send a ([A-Z]+) request to "([^"]+)" with values:$/ |
||
116 | */ |
||
117 | public function iSendARequestWithValues($method, $url, TableNode $post) |
||
136 | |||
137 | /** |
||
138 | * Sends HTTP request to specific URL with raw body from PyString. |
||
139 | * |
||
140 | * @param string $method request method |
||
141 | * @param string $url relative url |
||
142 | * @param PyStringNode $string request body |
||
143 | * |
||
144 | * @When /^(?:I )?send a ([A-Z]+) request to "([^"]+)" with body:$/ |
||
145 | */ |
||
146 | public function iSendARequestWithBody($method, $url, PyStringNode $string) |
||
161 | |||
162 | /** |
||
163 | * Sends HTTP request to specific URL with form data from PyString. |
||
164 | * |
||
165 | * @param string $method request method |
||
166 | * @param string $url relative url |
||
167 | * @param PyStringNode $body request body |
||
168 | * |
||
169 | * @When /^(?:I )?send a ([A-Z]+) request to "([^"]+)" with form data:$/ |
||
170 | */ |
||
171 | public function iSendARequestWithFormData($method, $url, PyStringNode $body) |
||
187 | |||
188 | /** |
||
189 | * Checks that response has specific status code. |
||
190 | * |
||
191 | * @param string $code status code |
||
192 | * |
||
193 | * @Then /^(?:the )?response code should be (\d+)$/ |
||
194 | */ |
||
195 | public function theResponseCodeShouldBe($code) |
||
201 | |||
202 | /** |
||
203 | * Checks that response body contains specific text. |
||
204 | * |
||
205 | * @param string $text |
||
206 | * |
||
207 | * @Then /^(?:the )?response should contain "([^"]*)"$/ |
||
208 | */ |
||
209 | public function theResponseShouldContain($text) |
||
215 | |||
216 | /** |
||
217 | * Checks that response body doesn't contains specific text. |
||
218 | * |
||
219 | * @param string $text |
||
220 | * |
||
221 | * @Then /^(?:the )?response should not contain "([^"]*)"$/ |
||
222 | */ |
||
223 | public function theResponseShouldNotContain($text) |
||
229 | |||
230 | /** |
||
231 | * Checks that response body contains JSON from PyString. |
||
232 | * |
||
233 | * Do not check that the response body /only/ contains the JSON from PyString, |
||
234 | * |
||
235 | * @param PyStringNode $jsonString |
||
236 | * |
||
237 | * @throws \RuntimeException |
||
238 | * |
||
239 | * @Then /^(?:the )?response should contain json:$/ |
||
240 | */ |
||
241 | public function theResponseShouldContainJson(PyStringNode $jsonString) |
||
255 | |||
256 | /** |
||
257 | * Asserts that *only* the keys defined in etalon exist and are equal to the values defined in actual. |
||
258 | * |
||
259 | * @param array $etalon |
||
260 | * @param array $actual |
||
261 | */ |
||
262 | private function assertEtalonKeyValuesEqualsActual(array $etalon, array $actual) |
||
274 | |||
275 | /** |
||
276 | * Checks that JSON response key equals the value specified. |
||
277 | * |
||
278 | * Do not check that the response body /only/ contains the JSON from PyString, |
||
279 | * |
||
280 | * @param string $key |
||
281 | * @param string $value |
||
282 | * |
||
283 | * @Then /^(?:the )?response key "([^"]*)" should equal "([^"]*)"$/ |
||
284 | */ |
||
285 | public function theResponseKeyShouldEqual($key, $value) |
||
292 | |||
293 | /** |
||
294 | * Checks that JSON response key matches the value specified. |
||
295 | * |
||
296 | * Do not check that the response body /only/ contains the JSON from PyString, |
||
297 | * |
||
298 | * @param string $key |
||
299 | * @param string $value |
||
300 | * |
||
301 | * @Then /^(?:the )?response key "([^"]*)" should match "([^"]*)"$/ |
||
302 | */ |
||
303 | public function theResponseKeyShouldMatch($key, $value) |
||
310 | |||
311 | /** |
||
312 | * Prints last response body. |
||
313 | * |
||
314 | * @Then print response |
||
315 | */ |
||
316 | public function printResponse() |
||
329 | |||
330 | /** |
||
331 | * Prepare URL by replacing placeholders and trimming slashes. |
||
332 | * |
||
333 | * @param string $url |
||
334 | * |
||
335 | * @return string |
||
336 | */ |
||
337 | private function prepareUrl($url) |
||
341 | |||
342 | /** |
||
343 | * Sets place holder for replacement. |
||
344 | * |
||
345 | * you can specify placeholders, which will |
||
346 | * be replaced in URL, request or response body. |
||
347 | * |
||
348 | * @param string $key token name |
||
349 | * @param string $value replace value |
||
350 | */ |
||
351 | public function setPlaceHolder($key, $value) |
||
355 | |||
356 | /** |
||
357 | * Replaces placeholders in provided text. |
||
358 | * |
||
359 | * @param string $string |
||
360 | * |
||
361 | * @return string |
||
362 | */ |
||
363 | protected function replacePlaceHolder($string) |
||
371 | |||
372 | /** |
||
373 | * Returns headers, that will be used to send requests. |
||
374 | * |
||
375 | * @return array |
||
376 | */ |
||
377 | protected function getHeaders() |
||
381 | |||
382 | /** |
||
383 | * Adds header |
||
384 | * |
||
385 | * @param string $name |
||
386 | * @param string $value |
||
387 | */ |
||
388 | protected function addHeader($name, $value) |
||
400 | |||
401 | /** |
||
402 | * Removes a header identified by $headerName |
||
403 | * |
||
404 | * @param string $headerName |
||
405 | */ |
||
406 | protected function removeHeader($headerName) |
||
412 | |||
413 | private function sendRequest() |
||
425 | |||
426 | private function getClient() |
||
434 | |||
435 | /** |
||
436 | * @return \GuzzleHttp\Message\RequestInterface |
||
437 | */ |
||
438 | public function getRequest() |
||
442 | |||
443 | /** |
||
444 | * @return \GuzzleHttp\Message\ResponseInterface |
||
445 | */ |
||
446 | public function getResponse() |
||
450 | } |
||
451 |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.