Total Complexity | 59 |
Total Lines | 507 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like HTTPTest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use HTTPTest, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
14 | class HTTPTest extends ServerTest |
||
15 | { |
||
16 | protected $expectHttp2 = false; |
||
17 | |||
18 | /** |
||
19 | * Returns all test methods from the base class, except the ones which failed already |
||
20 | * |
||
21 | * @todo (re)introduce skipping of tests which failed when executed individually even if test runs happen as separate processes |
||
22 | * @todo reintroduce skipping of tests within the loop |
||
23 | */ |
||
24 | public function getSingleHttpTestMethods() |
||
25 | { |
||
26 | $unsafeMethods = array( |
||
27 | 'testCatchExceptions', 'testUtf8Method', 'testServerComments', |
||
28 | 'testExoticCharsetsRequests', 'testExoticCharsetsRequests2', 'testExoticCharsetsRequests3', |
||
29 | 'testWrapInexistentUrl', |
||
30 | ); |
||
31 | |||
32 | $methods = array(); |
||
33 | foreach(get_class_methods('ServerTest') as $method) |
||
34 | { |
||
35 | if (strpos($method, 'test') === 0 && !in_array($method, $unsafeMethods)) |
||
36 | { |
||
37 | if (!isset(self::$failed_tests[$method])) { |
||
38 | $methods[$method] = array($method); |
||
39 | } |
||
40 | } |
||
41 | } |
||
42 | |||
43 | return $methods; |
||
44 | } |
||
45 | |||
46 | /** |
||
47 | * @dataProvider getSingleHttpTestMethods |
||
48 | * @param string $method |
||
49 | */ |
||
50 | public function testDeflate($method) |
||
51 | { |
||
52 | if (!function_exists('gzdeflate')) |
||
53 | { |
||
54 | $this->markTestSkipped('Zlib missing: cannot test deflate functionality'); |
||
55 | return; |
||
56 | } |
||
57 | |||
58 | $this->client->accepted_compression = array('deflate'); |
||
59 | $this->client->request_compression = 'deflate'; |
||
60 | |||
61 | $this->$method(); |
||
62 | } |
||
63 | |||
64 | /** |
||
65 | * @dataProvider getSingleHttpTestMethods |
||
66 | * @param string $method |
||
67 | */ |
||
68 | public function testGzip($method) |
||
69 | { |
||
70 | if (!function_exists('gzdeflate')) |
||
71 | { |
||
72 | $this->markTestSkipped('Zlib missing: cannot test gzip functionality'); |
||
73 | return; |
||
74 | } |
||
75 | |||
76 | $this->client->accepted_compression = array('gzip'); |
||
77 | $this->client->request_compression = 'gzip'; |
||
78 | |||
79 | $this->$method(); |
||
80 | } |
||
81 | |||
82 | public function testKeepAlives() |
||
98 | } |
||
99 | } |
||
100 | |||
101 | /** |
||
102 | * @dataProvider getSingleHttpTestMethods |
||
103 | * @param string $method |
||
104 | */ |
||
105 | public function testRedirects($method) |
||
106 | { |
||
107 | if (!function_exists('curl_init')) |
||
108 | { |
||
109 | $this->markTestSkipped('CURL missing: cannot test redirects'); |
||
110 | return; |
||
111 | } |
||
112 | |||
113 | $this->client->setUseCurl(\PhpXmlRpc\Client::USE_CURL_ALWAYS); |
||
114 | $this->client->setCurlOptions(array(CURLOPT_FOLLOWLOCATION => true, CURLOPT_POSTREDIR => 3)); |
||
115 | |||
116 | $this->$method(); |
||
117 | } |
||
118 | |||
119 | public function testAcceptCharset() |
||
120 | { |
||
121 | if (version_compare(PHP_VERSION, '5.6.0', '<')) |
||
122 | { |
||
123 | $this->markTestSkipped('cannot test accept-charset on php < 5.6'); |
||
124 | return; |
||
125 | } |
||
126 | if (!function_exists('mb_list_encodings')) |
||
127 | { |
||
128 | $this->markTestSkipped('mbstring missing: cannot test accept-charset'); |
||
129 | return; |
||
130 | } |
||
131 | |||
132 | $r = new \PhpXmlRpc\Request('examples.stringecho', array(new \PhpXmlRpc\Value('€'))); |
||
133 | //chr(164) |
||
134 | |||
135 | $originalEncoding = \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding; |
||
136 | \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding = 'UTF-8'; |
||
137 | |||
138 | $this->addQueryParams(array('RESPONSE_ENCODING' => 'auto')); |
||
139 | $this->client->accepted_charset_encodings = array( |
||
140 | 'utf-1234;q=0.1', |
||
141 | 'windows-1252;q=0.8' |
||
142 | ); |
||
143 | $v = $this->send($r, 0, true); |
||
144 | $h = $v->httpResponse(); |
||
145 | $this->assertEquals('text/xml; charset=Windows-1252', $h['headers']['content-type']); |
||
146 | if ($v) { |
||
147 | $this->assertEquals('€', $v->value()->scalarval()); |
||
|
|||
148 | } |
||
149 | \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding = $originalEncoding; |
||
150 | } |
||
151 | |||
152 | /** |
||
153 | * @dataProvider getSingleHttpTestMethods |
||
154 | * @param string $method |
||
155 | */ |
||
156 | public function testProxy($method) |
||
157 | { |
||
158 | if ($this->args['PROXYSERVER'] == '') |
||
159 | { |
||
160 | $this->markTestSkipped('PROXYSERVER definition missing: cannot test proxy'); |
||
161 | return; |
||
162 | } |
||
163 | |||
164 | $this->client->setProxy($this->args['PROXYSERVER'], $this->args['PROXYPORT']); |
||
165 | |||
166 | $this->$method(); |
||
167 | } |
||
168 | |||
169 | /** |
||
170 | * @dataProvider getSingleHttpTestMethods |
||
171 | * @param string $method |
||
172 | */ |
||
173 | public function testHttp11($method) |
||
174 | { |
||
175 | if (!function_exists('curl_init')) |
||
176 | { |
||
177 | $this->markTestSkipped('CURL missing: cannot test http 1.1'); |
||
178 | return; |
||
179 | } |
||
180 | |||
181 | $this->method = 'http11'; // not an error the double assignment! |
||
182 | $this->client->method = 'http11'; |
||
183 | $this->client->keepalive = false; |
||
184 | |||
185 | $this->$method(); |
||
186 | } |
||
187 | |||
188 | /** |
||
189 | * @dataProvider getSingleHttpTestMethods |
||
190 | * @param string $method |
||
191 | */ |
||
192 | public function testHttp10Curl($method) |
||
193 | { |
||
194 | if (!function_exists('curl_init')) |
||
195 | { |
||
196 | $this->markTestSkipped('CURL missing: cannot test http 1.1'); |
||
197 | return; |
||
198 | } |
||
199 | |||
200 | $this->method = 'http10'; // not an error the double assignment! |
||
201 | $this->client->method = 'http10'; |
||
202 | $this->client->keepalive = false; |
||
203 | $this->client->setUseCurl(\PhpXmlRpc\Client::USE_CURL_ALWAYS); |
||
204 | |||
205 | $this->$method(); |
||
206 | } |
||
207 | |||
208 | /** |
||
209 | * @dataProvider getSingleHttpTestMethods |
||
210 | * @param string $method |
||
211 | */ |
||
212 | public function testHttp11Gzip($method) |
||
213 | { |
||
214 | if (!function_exists('curl_init')) |
||
215 | { |
||
216 | $this->markTestSkipped('CURL missing: cannot test http 1.1'); |
||
217 | return; |
||
218 | } |
||
219 | $this->method = 'http11'; // not an error the double assignment! |
||
220 | $this->client->method = 'http11'; |
||
221 | $this->client->keepalive = false; |
||
222 | $this->client->accepted_compression = array('gzip'); |
||
223 | $this->client->request_compression = 'gzip'; |
||
224 | |||
225 | $this->$method(); |
||
226 | } |
||
227 | |||
228 | /** |
||
229 | * @dataProvider getSingleHttpTestMethods |
||
230 | * @param string $method |
||
231 | */ |
||
232 | public function testHttp11Deflate($method) |
||
233 | { |
||
234 | if (!function_exists('curl_init')) |
||
235 | { |
||
236 | $this->markTestSkipped('CURL missing: cannot test http 1.1'); |
||
237 | return; |
||
238 | } |
||
239 | $this->method = 'http11'; // not an error the double assignment! |
||
240 | $this->client->method = 'http11'; |
||
241 | $this->client->keepalive = false; |
||
242 | $this->client->accepted_compression = array('deflate'); |
||
243 | $this->client->request_compression = 'deflate'; |
||
244 | |||
245 | $this->$method(); |
||
246 | } |
||
247 | |||
248 | /** |
||
249 | * @dataProvider getSingleHttpTestMethods |
||
250 | * @param string $method |
||
251 | */ |
||
252 | public function testHttp11Proxy($method) |
||
253 | { |
||
254 | if (!function_exists('curl_init')) |
||
255 | { |
||
256 | $this->markTestSkipped('CURL missing: cannot test http 1.1 w. proxy'); |
||
257 | return; |
||
258 | } |
||
259 | else if ($this->args['PROXYSERVER'] == '') |
||
260 | { |
||
261 | $this->markTestSkipped('PROXYSERVER definition missing: cannot test proxy w. http 1.1'); |
||
262 | return; |
||
263 | } |
||
264 | |||
265 | $this->method = 'http11'; // not an error the double assignment! |
||
266 | $this->client->method = 'http11'; |
||
267 | $this->client->setProxy($this->args['PROXYSERVER'], $this->args['PROXYPORT']); |
||
268 | $this->client->keepalive = false; |
||
269 | |||
270 | $this->$method(); |
||
271 | } |
||
272 | |||
273 | /** |
||
274 | * @dataProvider getSingleHttpTestMethods |
||
275 | * @param string $method |
||
276 | */ |
||
277 | public function testHttps($method) |
||
278 | { |
||
279 | if (!function_exists('curl_init')) |
||
280 | { |
||
281 | $this->markTestSkipped('CURL missing: cannot test https functionality'); |
||
282 | return; |
||
283 | } |
||
284 | else if ($this->args['HTTPSSERVER'] == '') |
||
285 | { |
||
286 | $this->markTestSkipped('HTTPS SERVER definition missing: cannot test https'); |
||
287 | return; |
||
288 | } |
||
289 | |||
290 | $this->client->server = $this->args['HTTPSSERVER']; |
||
291 | $this->method = 'https'; |
||
292 | $this->client->method = 'https'; |
||
293 | $this->client->path = $this->args['HTTPSURI']; |
||
294 | $this->client->setSSLVerifyPeer(!$this->args['HTTPSIGNOREPEER']); |
||
295 | $this->client->setSSLVerifyHost($this->args['HTTPSVERIFYHOST']); |
||
296 | $this->client->setSSLVersion($this->args['SSLVERSION']); |
||
297 | |||
298 | $this->$method(); |
||
299 | } |
||
300 | |||
301 | /** |
||
302 | * @dataProvider getSingleHttpTestMethods |
||
303 | * @param string $method |
||
304 | */ |
||
305 | public function testHttpsSocket($method) |
||
306 | { |
||
307 | if ($this->args['HTTPSSERVER'] == '') |
||
308 | { |
||
309 | $this->markTestSkipped('HTTPS SERVER definition missing: cannot test https'); |
||
310 | return; |
||
311 | } |
||
312 | |||
313 | /// @todo investigate: can we make this work? |
||
314 | if (version_compare(PHP_VERSION, '7.2', '<')) |
||
315 | { |
||
316 | if (is_readable('/etc/os-release')) { |
||
317 | $output = file_get_contents('/etc/os-release'); |
||
318 | preg_match('/VERSION="?([0-9]+)/', $output, $matches); |
||
319 | $ubuntuVersion = @$matches[1]; |
||
320 | } else { |
||
321 | exec('uname -a', $output, $retval); |
||
322 | preg_match('/ubunutu([0-9]+)/', $output[0], $matches); |
||
323 | $ubuntuVersion = @$matches[1]; |
||
324 | } |
||
325 | if ($ubuntuVersion >= 20) { |
||
326 | $this->markTestSkipped('HTTPS via Socket known to fail on php less than 7.2 on Ubuntu 20 and higher'); |
||
327 | return; |
||
328 | } |
||
329 | } |
||
330 | |||
331 | $this->client->server = $this->args['HTTPSSERVER']; |
||
332 | $this->method = 'https'; |
||
333 | $this->client->method = 'https'; |
||
334 | $this->client->path = $this->args['HTTPSURI']; |
||
335 | $this->client->setSSLVerifyPeer(!$this->args['HTTPSIGNOREPEER']); |
||
336 | $this->client->setSSLVerifyHost($this->args['HTTPSVERIFYHOST']); |
||
337 | $this->client->setSSLVersion($this->args['SSLVERSION']); |
||
338 | $this->client->setUseCurl(\PhpXmlRpc\Client::USE_CURL_NEVER); |
||
339 | |||
340 | $this->$method(); |
||
341 | } |
||
342 | |||
343 | /** |
||
344 | * @dataProvider getSingleHttpTestMethods |
||
345 | * @param string $method |
||
346 | */ |
||
347 | public function testHttpsProxy($method) |
||
348 | { |
||
349 | if (!function_exists('curl_init')) |
||
350 | { |
||
351 | $this->markTestSkipped('CURL missing: cannot test https w. proxy'); |
||
352 | return; |
||
353 | } |
||
354 | else if ($this->args['PROXYSERVER'] == '') |
||
355 | { |
||
356 | $this->markTestSkipped('PROXYSERVER definition missing: cannot test proxy w. https'); |
||
357 | return; |
||
358 | } |
||
359 | else if ($this->args['HTTPSSERVER'] == '') |
||
360 | { |
||
361 | $this->markTestSkipped('HTTPS SERVER definition missing: cannot test https w. proxy'); |
||
362 | return; |
||
363 | } |
||
364 | |||
365 | $this->client->server = $this->args['HTTPSSERVER']; |
||
366 | $this->method = 'https'; |
||
367 | $this->client->method = 'https'; |
||
368 | $this->client->setProxy($this->args['PROXYSERVER'], $this->args['PROXYPORT']); |
||
369 | $this->client->path = $this->args['HTTPSURI']; |
||
370 | $this->client->setSSLVerifyPeer(!$this->args['HTTPSIGNOREPEER']); |
||
371 | $this->client->setSSLVerifyHost($this->args['HTTPSVERIFYHOST']); |
||
372 | $this->client->setSSLVersion($this->args['SSLVERSION']); |
||
373 | |||
374 | $this->$method(); |
||
375 | } |
||
376 | |||
377 | /** |
||
378 | * @dataProvider getSingleHttpTestMethods |
||
379 | * @param string $method |
||
380 | */ |
||
381 | public function testHttp2($method) |
||
382 | { |
||
383 | if (!function_exists('curl_init')) |
||
384 | { |
||
385 | $this->markTestSkipped('CURL missing: cannot test http/2'); |
||
386 | return; |
||
387 | } else if (!defined('CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE')) |
||
388 | { |
||
389 | $this->markTestSkipped('CURL http/2 support missing: cannot test http/2'); |
||
390 | return; |
||
391 | } |
||
392 | |||
393 | $this->method = 'h2c'; // not an error the double assignment! |
||
394 | $this->client->method = 'h2c'; |
||
395 | //$this->client->keepalive = false; // q: is this a good idea? |
||
396 | |||
397 | $this->expectHttp2 = true; |
||
398 | $this->$method(); |
||
399 | $this->expectHttp2 = false; |
||
400 | } |
||
401 | |||
402 | /** |
||
403 | * @dataProvider getSingleHttpTestMethods |
||
404 | * @param string $method |
||
405 | */ |
||
406 | public function testHttp2tls($method) |
||
407 | { |
||
408 | if (!function_exists('curl_init')) |
||
409 | { |
||
410 | $this->markTestSkipped('CURL missing: cannot test http/2 tls'); |
||
411 | return; |
||
412 | } else if ($this->args['HTTPSSERVER'] == '') |
||
413 | { |
||
414 | $this->markTestSkipped('HTTPS SERVER definition missing: cannot test http/2 tls'); |
||
415 | return; |
||
416 | } else if (!defined('CURL_HTTP_VERSION_2_0')) |
||
417 | { |
||
418 | $this->markTestSkipped('CURL http/2 support missing: cannot test http/2 tls'); |
||
419 | return; |
||
420 | } |
||
421 | |||
422 | $this->client->server = $this->args['HTTPSSERVER']; |
||
423 | $this->method = 'h2'; |
||
424 | $this->client->method = 'h2'; |
||
425 | $this->client->path = $this->args['HTTPSURI']; |
||
426 | $this->client->setSSLVerifyPeer(!$this->args['HTTPSIGNOREPEER']); |
||
427 | $this->client->setSSLVerifyHost($this->args['HTTPSVERIFYHOST']); |
||
428 | $this->client->setSSLVersion($this->args['SSLVERSION']); |
||
429 | |||
430 | $this->expectHttp2 = true; |
||
431 | $this->$method(); |
||
432 | $this->expectHttp2 = false; |
||
433 | } |
||
434 | |||
435 | /** |
||
436 | * @dataProvider getSingleHttpTestMethods |
||
437 | * @param string $method |
||
438 | */ |
||
439 | public function testUTF8Responses($method) |
||
440 | { |
||
441 | $this->addQueryParams(array('RESPONSE_ENCODING' => 'UTF-8')); |
||
442 | |||
443 | $this->$method(); |
||
444 | } |
||
445 | |||
446 | /** |
||
447 | * @dataProvider getSingleHttpTestMethods |
||
448 | * @param string $method |
||
449 | */ |
||
450 | public function testUTF8Requests($method) |
||
455 | } |
||
456 | |||
457 | /** |
||
458 | * @dataProvider getSingleHttpTestMethods |
||
459 | * @param string $method |
||
460 | */ |
||
461 | public function testISOResponses($method) |
||
462 | { |
||
463 | $this->addQueryParams(array('RESPONSE_ENCODING' => 'ISO-8859-1')); |
||
464 | |||
465 | $this->$method(); |
||
466 | } |
||
467 | |||
468 | /** |
||
469 | * @dataProvider getSingleHttpTestMethods |
||
470 | * @param string $method |
||
471 | */ |
||
472 | public function testISORequests($method) |
||
473 | { |
||
474 | $this->client->request_charset_encoding = 'ISO-8859-1'; |
||
475 | |||
476 | $this->$method(); |
||
477 | } |
||
478 | |||
479 | /** |
||
480 | * @dataProvider getSingleHttpTestMethods |
||
481 | * @param string $method |
||
482 | */ |
||
483 | public function testBasicAuth($method) |
||
484 | { |
||
485 | $this->client->setCredentials('test', 'test'); |
||
486 | $this->addQueryParams(array('FORCE_AUTH' => 'Basic')); |
||
487 | |||
488 | $this->$method(); |
||
489 | } |
||
490 | |||
491 | /** |
||
492 | * @dataProvider getSingleHttpTestMethods |
||
493 | * @param string $method |
||
494 | */ |
||
495 | public function testDigestAuth($method) |
||
509 | } |
||
510 | |||
511 | /** |
||
512 | * @param \PhpXmlRpc\Response $r |
||
513 | * @return void |
||
514 | */ |
||
515 | protected function validateResponse($r) |
||
521 | |||
522 | } |
||
523 | } |
||
524 | } |
||
525 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.