1 | <?php |
||
32 | class RawGuzzleContext implements GuzzleAwareContext |
||
33 | { |
||
34 | /** |
||
35 | * @var string |
||
36 | */ |
||
37 | const GUZZLE_EXTENSION_NAME = 'Behat Guzzle Extension'; |
||
38 | |||
39 | /** |
||
40 | * @var string |
||
41 | */ |
||
42 | const GUZZLE_EXTENSION_VERSION = '0.4.1'; |
||
43 | |||
44 | /** |
||
45 | * @var Client |
||
46 | * |
||
47 | * @access private |
||
48 | */ |
||
49 | private $client; |
||
50 | |||
51 | /** |
||
52 | * @var array |
||
53 | * |
||
54 | * @access private |
||
55 | */ |
||
56 | private $parameters; |
||
57 | |||
58 | /** |
||
59 | * @var Response |
||
60 | * |
||
61 | * @access private |
||
62 | */ |
||
63 | private $response; |
||
64 | |||
65 | /** |
||
66 | * @var mixed |
||
67 | * |
||
68 | * @access private |
||
69 | */ |
||
70 | private $result; |
||
71 | |||
72 | /** |
||
73 | * Execute command |
||
74 | * |
||
75 | * @param string $command Command to execute |
||
76 | * @param array $data Data to send |
||
77 | * |
||
78 | * @access protected |
||
79 | * @return void |
||
80 | */ |
||
81 | 13 | public function executeCommand($command, array $data = array()) |
|
110 | |||
111 | /** |
||
112 | * Returns Client instance |
||
113 | * |
||
114 | * @access public |
||
115 | * @return Client |
||
116 | */ |
||
117 | 16 | public function getGuzzleClient() |
|
128 | |||
129 | /** |
||
130 | * Sets Client instance |
||
131 | * |
||
132 | * @param Client $client Guzzle client |
||
133 | * |
||
134 | * @access public |
||
135 | * @return void |
||
136 | */ |
||
137 | 15 | public function setGuzzleClient(Client $client) |
|
141 | |||
142 | /** |
||
143 | * Add Guzzle header |
||
144 | * |
||
145 | * @param string $field Field name |
||
146 | * @param string $value Header value |
||
147 | * |
||
148 | * @access public |
||
149 | * @return void |
||
150 | */ |
||
151 | 2 | public function addGuzzleHeader($field, $value) |
|
155 | |||
156 | /** |
||
157 | * Remove Guzzle header |
||
158 | * |
||
159 | * @param string $field Field name |
||
160 | * |
||
161 | * @access public |
||
162 | * @return void |
||
163 | */ |
||
164 | 1 | public function removeGuzzleHeader($field) |
|
168 | |||
169 | /** |
||
170 | * Returns specific Guzzle parameter |
||
171 | * |
||
172 | * @param string $name |
||
173 | * |
||
174 | * @access public |
||
175 | * @return mixed |
||
176 | */ |
||
177 | 1 | public function getGuzzleParameter($name) |
|
183 | |||
184 | /** |
||
185 | * Applies the given parameter to the Guzzle configuration. Consider that |
||
186 | * all parameters get reset for each feature context |
||
187 | * |
||
188 | * @param string $name The key of the parameter |
||
189 | * @param string $value The value of the parameter |
||
190 | * |
||
191 | * @access public |
||
192 | * @return void |
||
193 | */ |
||
194 | 1 | public function setGuzzleParameter($name, $value) |
|
198 | |||
199 | /** |
||
200 | * Returns the parameters provided for Guzzle |
||
201 | * |
||
202 | * @access public |
||
203 | * @return array |
||
204 | */ |
||
205 | 1 | public function getGuzzleParameters() |
|
209 | |||
210 | /** |
||
211 | * Sets parameters provided for Guzzle |
||
212 | * |
||
213 | * @param array $parameters |
||
214 | * |
||
215 | * @access public |
||
216 | * @return void |
||
217 | */ |
||
218 | 1 | public function setGuzzleParameters(array $parameters) |
|
222 | |||
223 | /** |
||
224 | * Returns Response instance |
||
225 | * |
||
226 | * @access public |
||
227 | * @return Response |
||
228 | */ |
||
229 | 5 | public function getGuzzleResponse() |
|
233 | |||
234 | /** |
||
235 | * Returns result |
||
236 | * |
||
237 | * @access public |
||
238 | * @return mixed |
||
239 | */ |
||
240 | 8 | public function getGuzzleResult() |
|
244 | |||
245 | /** |
||
246 | * Compare array values |
||
247 | * |
||
248 | * @param array $input Array with values to compare |
||
249 | * @param array $control Array with correct values |
||
250 | * |
||
251 | * @access protected |
||
252 | * @return void |
||
253 | */ |
||
254 | 7 | protected function compareArrays(array $input, array $control) |
|
272 | |||
273 | /** |
||
274 | * Compare array values |
||
275 | * |
||
276 | * @param mixed $input Input value |
||
277 | * @param mixed $control Correct control value |
||
278 | * |
||
279 | * @throws Exception When two field values do not match |
||
280 | * |
||
281 | * @access protected |
||
282 | * @return void |
||
283 | */ |
||
284 | 8 | protected function compareValues($input, $control) |
|
297 | |||
298 | /** |
||
299 | * Get request options |
||
300 | * |
||
301 | * @access private |
||
302 | * @return array |
||
303 | */ |
||
304 | 2 | private function getRequestOptions() |
|
316 | |||
317 | /** |
||
318 | * Set request options |
||
319 | * |
||
320 | * @param array $options Request options |
||
321 | * |
||
322 | * @access private |
||
323 | * @return void |
||
324 | */ |
||
325 | 2 | private function setRequestOptions(array $options) |
|
332 | |||
333 | /** |
||
334 | * Update header |
||
335 | * |
||
336 | * Adds, updates or removes header (if no value is provided) |
||
337 | * |
||
338 | * @param string $field Field name |
||
339 | * @param mixed $value Header value |
||
340 | * |
||
341 | * @access private |
||
342 | * @return void |
||
343 | */ |
||
344 | 2 | private function updateHeader($field, $value = null) |
|
356 | } |
||
357 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the parent class: