1 | <?php |
||
26 | class WebApiContext implements ApiClientAwareContext |
||
27 | { |
||
28 | /** |
||
29 | * @var string |
||
30 | */ |
||
31 | protected $authorization; |
||
32 | |||
33 | /** |
||
34 | * @var ClientInterface |
||
35 | */ |
||
36 | protected $client; |
||
37 | |||
38 | /** |
||
39 | * @var array |
||
40 | */ |
||
41 | protected $headers = array(); |
||
42 | |||
43 | /** |
||
44 | * @var ResponseInterface |
||
45 | */ |
||
46 | protected $response; |
||
47 | |||
48 | /** |
||
49 | * @var Request |
||
50 | */ |
||
51 | protected $request; |
||
52 | |||
53 | protected $placeHolders = array(); |
||
54 | |||
55 | /** |
||
56 | * {@inheritdoc} |
||
57 | */ |
||
58 | public function setClient(ClientInterface $client) |
||
62 | |||
63 | /** |
||
64 | * Adds Basic Authentication header to next request. |
||
65 | * |
||
66 | * @param string $username |
||
67 | * @param string $password |
||
68 | * |
||
69 | * @Given /^I am authenticating as "([^"]*)" with "([^"]*)" password$/ |
||
70 | */ |
||
71 | public function iAmAuthenticatingAs($username, $password) |
||
77 | |||
78 | /** |
||
79 | * Sets a HTTP Header. |
||
80 | * |
||
81 | * @param string $name header name |
||
82 | * @param string $value header value |
||
83 | * |
||
84 | * @Given /^I set header "([^"]*)" with value "([^"]*)"$/ |
||
85 | */ |
||
86 | public function iSetHeaderWithValue($name, $value) |
||
90 | |||
91 | /** |
||
92 | * Sends HTTP request to specific relative URL. |
||
93 | * |
||
94 | * @param string $method request method |
||
95 | * @param string $url relative url |
||
96 | * |
||
97 | * @When /^(?:I )?send a ([A-Z]+) request to "([^"]+)"$/ |
||
98 | */ |
||
99 | public function iSendARequest($method, $url) |
||
106 | |||
107 | /** |
||
108 | * Sends HTTP request to specific URL with field values from Table. |
||
109 | * |
||
110 | * @param string $method request method |
||
111 | * @param string $url relative url |
||
112 | * @param TableNode $post table of post values |
||
113 | * |
||
114 | * @When /^(?:I )?send a ([A-Z]+) request to "([^"]+)" with values:$/ |
||
115 | */ |
||
116 | public function iSendARequestWithValues($method, $url, TableNode $post) |
||
129 | |||
130 | /** |
||
131 | * Sends HTTP request to specific URL with raw body from PyString. |
||
132 | * |
||
133 | * @param string $method request method |
||
134 | * @param string $url relative url |
||
135 | * @param PyStringNode $string request body |
||
136 | * |
||
137 | * @When /^(?:I )?send a ([A-Z]+) request to "([^"]+)" with body:$/ |
||
138 | */ |
||
139 | public function iSendARequestWithBody($method, $url, PyStringNode $string) |
||
147 | |||
148 | /** |
||
149 | * Sends HTTP request to specific URL with form data from PyString. |
||
150 | * |
||
151 | * @param string $method request method |
||
152 | * @param string $url relative url |
||
153 | * @param PyStringNode $body request body |
||
154 | * |
||
155 | * @When /^(?:I )?send a ([A-Z]+) request to "([^"]+)" with form data:$/ |
||
156 | */ |
||
157 | public function iSendARequestWithFormData($method, $url, PyStringNode $body) |
||
183 | |||
184 | /** |
||
185 | * Checks that response has specific status code. |
||
186 | * |
||
187 | * @param string $code status code |
||
188 | * |
||
189 | * @Then /^(?:the )?response code should be (\d+)$/ |
||
190 | */ |
||
191 | public function theResponseCodeShouldBe($code) |
||
197 | |||
198 | /** |
||
199 | * Checks that response body contains specific text. |
||
200 | * |
||
201 | * @param string $text |
||
202 | * |
||
203 | * @Then /^(?:the )?response should contain "([^"]*)"$/ |
||
204 | */ |
||
205 | public function theResponseShouldContain($text) |
||
211 | |||
212 | /** |
||
213 | * Checks that response body doesn't contains specific text. |
||
214 | * |
||
215 | * @param string $text |
||
216 | * |
||
217 | * @Then /^(?:the )?response should not contain "([^"]*)"$/ |
||
218 | */ |
||
219 | public function theResponseShouldNotContain($text) |
||
225 | |||
226 | /** |
||
227 | * Checks that response body contains JSON from PyString. |
||
228 | * |
||
229 | * Do not check that the response body /only/ contains the JSON from PyString, |
||
230 | * |
||
231 | * @param PyStringNode $jsonString |
||
232 | * |
||
233 | * @throws \RuntimeException |
||
234 | * |
||
235 | * @Then /^(?:the )?response should contain json:$/ |
||
236 | */ |
||
237 | public function theResponseShouldContainJson(PyStringNode $jsonString) |
||
251 | |||
252 | /** |
||
253 | * @param mixed $expected |
||
254 | * @param mixed $actual |
||
255 | */ |
||
256 | protected function assertContains($expected, $actual) |
||
280 | |||
281 | /** |
||
282 | * Prints last response body. |
||
283 | * |
||
284 | * @Then print response |
||
285 | */ |
||
286 | public function printResponse() |
||
299 | |||
300 | /** |
||
301 | * @return ResponseInterface |
||
302 | */ |
||
303 | public function getResponse() |
||
307 | |||
308 | /** |
||
309 | * Prepare URL by replacing placeholders and trimming slashes. |
||
310 | * |
||
311 | * @param string $url |
||
312 | * |
||
313 | * @return string |
||
314 | */ |
||
315 | protected function prepareUrl($url) |
||
319 | |||
320 | /** |
||
321 | * Sets place holder for replacement. |
||
322 | * |
||
323 | * you can specify placeholders, which will |
||
324 | * be replaced in URL, request or response body. |
||
325 | * |
||
326 | * @param string $key token name |
||
327 | * @param string $value replace value |
||
328 | */ |
||
329 | public function setPlaceHolder($key, $value) |
||
333 | |||
334 | /** |
||
335 | * Replaces placeholders in provided text. |
||
336 | * |
||
337 | * @param string $string |
||
338 | * |
||
339 | * @return string |
||
340 | */ |
||
341 | protected function replacePlaceHolder($string) |
||
349 | |||
350 | /** |
||
351 | * Returns headers, that will be used to send requests. |
||
352 | * |
||
353 | * @return array |
||
354 | */ |
||
355 | protected function getHeaders() |
||
359 | |||
360 | /** |
||
361 | * Adds header |
||
362 | * |
||
363 | * @param string $name |
||
364 | * @param string $value |
||
365 | */ |
||
366 | protected function addHeader($name, $value) |
||
378 | |||
379 | /** |
||
380 | * Removes a header identified by $headerName |
||
381 | * |
||
382 | * @param string $headerName |
||
383 | */ |
||
384 | protected function removeHeader($headerName) |
||
390 | |||
391 | protected function sendRequest() |
||
403 | |||
404 | protected function getClient() |
||
412 | } |
||
413 |
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.