| Total Complexity | 56 |
| Total Lines | 484 |
| Duplicated Lines | 0 % |
| Changes | 8 | ||
| Bugs | 1 | Features | 2 |
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 | public function testAcceptCharset() |
||
| 102 | { |
||
| 103 | if (!function_exists('mb_list_encodings')) |
||
| 104 | { |
||
| 105 | $this->markTestSkipped('mbstring missing: cannot test accept-charset'); |
||
| 106 | return; |
||
| 107 | } |
||
| 108 | |||
| 109 | $r = new \PhpXmlRpc\Request('examples.stringecho', array(new \PhpXmlRpc\Value('€'))); |
||
| 110 | //chr(164) |
||
| 111 | |||
| 112 | $originalEncoding = \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding; |
||
| 113 | \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding = 'UTF-8'; |
||
| 114 | |||
| 115 | $this->addQueryParams(array('RESPONSE_ENCODING' => 'auto')); |
||
| 116 | $this->client->accepted_charset_encodings = array( |
||
| 117 | 'utf-1234;q=0.1', |
||
| 118 | 'windows-1252;q=0.8' |
||
| 119 | ); |
||
| 120 | $v = $this->send($r, 0, true); |
||
| 121 | $h = $v->httpResponse(); |
||
| 122 | $this->assertEquals('text/xml; charset=Windows-1252', $h['headers']['content-type']); |
||
| 123 | if ($v) { |
||
| 124 | $this->assertEquals('€', $v->value()->scalarval()); |
||
|
|
|||
| 125 | } |
||
| 126 | \PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding = $originalEncoding; |
||
| 127 | } |
||
| 128 | |||
| 129 | /** |
||
| 130 | * @dataProvider getSingleHttpTestMethods |
||
| 131 | * @param string $method |
||
| 132 | */ |
||
| 133 | public function testProxy($method) |
||
| 134 | { |
||
| 135 | if ($this->args['PROXYSERVER'] == '') |
||
| 136 | { |
||
| 137 | $this->markTestSkipped('PROXYSERVER definition missing: cannot test proxy'); |
||
| 138 | return; |
||
| 139 | } |
||
| 140 | |||
| 141 | $this->client->setProxy($this->args['PROXYSERVER'], $this->args['PROXYPORT']); |
||
| 142 | |||
| 143 | $this->$method(); |
||
| 144 | } |
||
| 145 | |||
| 146 | /** |
||
| 147 | * @dataProvider getSingleHttpTestMethods |
||
| 148 | * @param string $method |
||
| 149 | */ |
||
| 150 | public function testHttp11($method) |
||
| 151 | { |
||
| 152 | if (!function_exists('curl_init')) |
||
| 153 | { |
||
| 154 | $this->markTestSkipped('CURL missing: cannot test http 1.1'); |
||
| 155 | return; |
||
| 156 | } |
||
| 157 | |||
| 158 | $this->method = 'http11'; // not an error the double assignment! |
||
| 159 | $this->client->method = 'http11'; |
||
| 160 | $this->client->keepalive = false; |
||
| 161 | |||
| 162 | $this->$method(); |
||
| 163 | } |
||
| 164 | |||
| 165 | /** |
||
| 166 | * @dataProvider getSingleHttpTestMethods |
||
| 167 | * @param string $method |
||
| 168 | */ |
||
| 169 | public function testHttp10Curl($method) |
||
| 170 | { |
||
| 171 | if (!function_exists('curl_init')) |
||
| 172 | { |
||
| 173 | $this->markTestSkipped('CURL missing: cannot test http 1.1'); |
||
| 174 | return; |
||
| 175 | } |
||
| 176 | |||
| 177 | $this->method = 'http10'; // not an error the double assignment! |
||
| 178 | $this->client->method = 'http10'; |
||
| 179 | $this->client->keepalive = false; |
||
| 180 | $this->client->setUseCurl(\PhpXmlRpc\Client::USE_CURL_ALWAYS); |
||
| 181 | |||
| 182 | $this->$method(); |
||
| 183 | } |
||
| 184 | |||
| 185 | /** |
||
| 186 | * @dataProvider getSingleHttpTestMethods |
||
| 187 | * @param string $method |
||
| 188 | */ |
||
| 189 | public function testHttp11Gzip($method) |
||
| 190 | { |
||
| 191 | if (!function_exists('curl_init')) |
||
| 192 | { |
||
| 193 | $this->markTestSkipped('CURL missing: cannot test http 1.1'); |
||
| 194 | return; |
||
| 195 | } |
||
| 196 | $this->method = 'http11'; // not an error the double assignment! |
||
| 197 | $this->client->method = 'http11'; |
||
| 198 | $this->client->keepalive = false; |
||
| 199 | $this->client->accepted_compression = array('gzip'); |
||
| 200 | $this->client->request_compression = 'gzip'; |
||
| 201 | |||
| 202 | $this->$method(); |
||
| 203 | } |
||
| 204 | |||
| 205 | /** |
||
| 206 | * @dataProvider getSingleHttpTestMethods |
||
| 207 | * @param string $method |
||
| 208 | */ |
||
| 209 | public function testHttp11Deflate($method) |
||
| 210 | { |
||
| 211 | if (!function_exists('curl_init')) |
||
| 212 | { |
||
| 213 | $this->markTestSkipped('CURL missing: cannot test http 1.1'); |
||
| 214 | return; |
||
| 215 | } |
||
| 216 | $this->method = 'http11'; // not an error the double assignment! |
||
| 217 | $this->client->method = 'http11'; |
||
| 218 | $this->client->keepalive = false; |
||
| 219 | $this->client->accepted_compression = array('deflate'); |
||
| 220 | $this->client->request_compression = 'deflate'; |
||
| 221 | |||
| 222 | $this->$method(); |
||
| 223 | } |
||
| 224 | |||
| 225 | /** |
||
| 226 | * @dataProvider getSingleHttpTestMethods |
||
| 227 | * @param string $method |
||
| 228 | */ |
||
| 229 | public function testHttp11Proxy($method) |
||
| 230 | { |
||
| 231 | if (!function_exists('curl_init')) |
||
| 232 | { |
||
| 233 | $this->markTestSkipped('CURL missing: cannot test http 1.1 w. proxy'); |
||
| 234 | return; |
||
| 235 | } |
||
| 236 | else if ($this->args['PROXYSERVER'] == '') |
||
| 237 | { |
||
| 238 | $this->markTestSkipped('PROXYSERVER definition missing: cannot test proxy w. http 1.1'); |
||
| 239 | return; |
||
| 240 | } |
||
| 241 | |||
| 242 | $this->method = 'http11'; // not an error the double assignment! |
||
| 243 | $this->client->method = 'http11'; |
||
| 244 | $this->client->setProxy($this->args['PROXYSERVER'], $this->args['PROXYPORT']); |
||
| 245 | $this->client->keepalive = false; |
||
| 246 | |||
| 247 | $this->$method(); |
||
| 248 | } |
||
| 249 | |||
| 250 | /** |
||
| 251 | * @dataProvider getSingleHttpTestMethods |
||
| 252 | * @param string $method |
||
| 253 | */ |
||
| 254 | public function testHttps($method) |
||
| 255 | { |
||
| 256 | if (!function_exists('curl_init')) |
||
| 257 | { |
||
| 258 | $this->markTestSkipped('CURL missing: cannot test https functionality'); |
||
| 259 | return; |
||
| 260 | } |
||
| 261 | else if ($this->args['HTTPSSERVER'] == '') |
||
| 262 | { |
||
| 263 | $this->markTestSkipped('HTTPS SERVER definition missing: cannot test https'); |
||
| 264 | return; |
||
| 265 | } |
||
| 266 | |||
| 267 | $this->client->server = $this->args['HTTPSSERVER']; |
||
| 268 | $this->method = 'https'; |
||
| 269 | $this->client->method = 'https'; |
||
| 270 | $this->client->path = $this->args['HTTPSURI']; |
||
| 271 | $this->client->setSSLVerifyPeer(!$this->args['HTTPSIGNOREPEER']); |
||
| 272 | $this->client->setSSLVerifyHost($this->args['HTTPSVERIFYHOST']); |
||
| 273 | $this->client->setSSLVersion($this->args['SSLVERSION']); |
||
| 274 | |||
| 275 | $this->$method(); |
||
| 276 | } |
||
| 277 | |||
| 278 | /** |
||
| 279 | * @dataProvider getSingleHttpTestMethods |
||
| 280 | * @param string $method |
||
| 281 | */ |
||
| 282 | public function testHttpsSocket($method) |
||
| 283 | { |
||
| 284 | if ($this->args['HTTPSSERVER'] == '') |
||
| 285 | { |
||
| 286 | $this->markTestSkipped('HTTPS SERVER definition missing: cannot test https'); |
||
| 287 | return; |
||
| 288 | } |
||
| 289 | |||
| 290 | /// @todo investigate: can we make this work? |
||
| 291 | if (version_compare(PHP_VERSION, '7.2', '<')) |
||
| 292 | { |
||
| 293 | if (is_readable('/etc/os-release')) { |
||
| 294 | $output = file_get_contents('/etc/os-release'); |
||
| 295 | preg_match('/VERSION="?([0-9]+)/', $output, $matches); |
||
| 296 | $ubuntuVersion = @$matches[1]; |
||
| 297 | } else { |
||
| 298 | exec('uname -a', $output, $retval); |
||
| 299 | preg_match('/ubunutu([0-9]+)/', $output[0], $matches); |
||
| 300 | $ubuntuVersion = @$matches[1]; |
||
| 301 | } |
||
| 302 | if ($ubuntuVersion >= 20) { |
||
| 303 | $this->markTestSkipped('HTTPS via Socket known to fail on php less than 7.2 on Ubuntu 20 and higher'); |
||
| 304 | return; |
||
| 305 | } |
||
| 306 | } |
||
| 307 | |||
| 308 | $this->client->server = $this->args['HTTPSSERVER']; |
||
| 309 | $this->method = 'https'; |
||
| 310 | $this->client->method = 'https'; |
||
| 311 | $this->client->path = $this->args['HTTPSURI']; |
||
| 312 | $this->client->setSSLVerifyPeer(!$this->args['HTTPSIGNOREPEER']); |
||
| 313 | $this->client->setSSLVerifyHost($this->args['HTTPSVERIFYHOST']); |
||
| 314 | $this->client->setSSLVersion($this->args['SSLVERSION']); |
||
| 315 | $this->client->setUseCurl(\PhpXmlRpc\Client::USE_CURL_NEVER); |
||
| 316 | |||
| 317 | $this->$method(); |
||
| 318 | } |
||
| 319 | |||
| 320 | /** |
||
| 321 | * @dataProvider getSingleHttpTestMethods |
||
| 322 | * @param string $method |
||
| 323 | */ |
||
| 324 | public function testHttpsProxy($method) |
||
| 325 | { |
||
| 326 | if (!function_exists('curl_init')) |
||
| 327 | { |
||
| 328 | $this->markTestSkipped('CURL missing: cannot test https w. proxy'); |
||
| 329 | return; |
||
| 330 | } |
||
| 331 | else if ($this->args['PROXYSERVER'] == '') |
||
| 332 | { |
||
| 333 | $this->markTestSkipped('PROXYSERVER definition missing: cannot test proxy w. https'); |
||
| 334 | return; |
||
| 335 | } |
||
| 336 | else if ($this->args['HTTPSSERVER'] == '') |
||
| 337 | { |
||
| 338 | $this->markTestSkipped('HTTPS SERVER definition missing: cannot test https w. proxy'); |
||
| 339 | return; |
||
| 340 | } |
||
| 341 | |||
| 342 | $this->client->server = $this->args['HTTPSSERVER']; |
||
| 343 | $this->method = 'https'; |
||
| 344 | $this->client->method = 'https'; |
||
| 345 | $this->client->setProxy($this->args['PROXYSERVER'], $this->args['PROXYPORT']); |
||
| 346 | $this->client->path = $this->args['HTTPSURI']; |
||
| 347 | $this->client->setSSLVerifyPeer(!$this->args['HTTPSIGNOREPEER']); |
||
| 348 | $this->client->setSSLVerifyHost($this->args['HTTPSVERIFYHOST']); |
||
| 349 | $this->client->setSSLVersion($this->args['SSLVERSION']); |
||
| 350 | |||
| 351 | $this->$method(); |
||
| 352 | } |
||
| 353 | |||
| 354 | /** |
||
| 355 | * @dataProvider getSingleHttpTestMethods |
||
| 356 | * @param string $method |
||
| 357 | */ |
||
| 358 | public function testHttp2($method) |
||
| 359 | { |
||
| 360 | if (!function_exists('curl_init')) |
||
| 361 | { |
||
| 362 | $this->markTestSkipped('CURL missing: cannot test http/2'); |
||
| 363 | return; |
||
| 364 | } else if (!defined('CURL_HTTP_VERSION_2_PRIOR_KNOWLEDGE')) |
||
| 365 | { |
||
| 366 | $this->markTestSkipped('CURL http/2 support missing: cannot test http/2'); |
||
| 367 | return; |
||
| 368 | } |
||
| 369 | |||
| 370 | $this->method = 'h2c'; // not an error the double assignment! |
||
| 371 | $this->client->method = 'h2c'; |
||
| 372 | //$this->client->keepalive = false; // q: is this a good idea? |
||
| 373 | |||
| 374 | $this->expectHttp2 = true; |
||
| 375 | $this->$method(); |
||
| 376 | $this->expectHttp2 = false; |
||
| 377 | } |
||
| 378 | |||
| 379 | /** |
||
| 380 | * @dataProvider getSingleHttpTestMethods |
||
| 381 | * @param string $method |
||
| 382 | */ |
||
| 383 | public function testHttp2tls($method) |
||
| 410 | } |
||
| 411 | |||
| 412 | /** |
||
| 413 | * @dataProvider getSingleHttpTestMethods |
||
| 414 | * @param string $method |
||
| 415 | */ |
||
| 416 | public function testUTF8Responses($method) |
||
| 417 | { |
||
| 418 | $this->addQueryParams(array('RESPONSE_ENCODING' => 'UTF-8')); |
||
| 419 | |||
| 420 | $this->$method(); |
||
| 421 | } |
||
| 422 | |||
| 423 | /** |
||
| 424 | * @dataProvider getSingleHttpTestMethods |
||
| 425 | * @param string $method |
||
| 426 | */ |
||
| 427 | public function testUTF8Requests($method) |
||
| 432 | } |
||
| 433 | |||
| 434 | /** |
||
| 435 | * @dataProvider getSingleHttpTestMethods |
||
| 436 | * @param string $method |
||
| 437 | */ |
||
| 438 | public function testISOResponses($method) |
||
| 439 | { |
||
| 440 | $this->addQueryParams(array('RESPONSE_ENCODING' => 'ISO-8859-1')); |
||
| 441 | |||
| 442 | $this->$method(); |
||
| 443 | } |
||
| 444 | |||
| 445 | /** |
||
| 446 | * @dataProvider getSingleHttpTestMethods |
||
| 447 | * @param string $method |
||
| 448 | */ |
||
| 449 | public function testISORequests($method) |
||
| 450 | { |
||
| 451 | $this->client->request_charset_encoding = 'ISO-8859-1'; |
||
| 452 | |||
| 453 | $this->$method(); |
||
| 454 | } |
||
| 455 | |||
| 456 | /** |
||
| 457 | * @dataProvider getSingleHttpTestMethods |
||
| 458 | * @param string $method |
||
| 459 | */ |
||
| 460 | public function testBasicAuth($method) |
||
| 461 | { |
||
| 462 | $this->client->setCredentials('test', 'test'); |
||
| 463 | $this->addQueryParams(array('FORCE_AUTH' => 'Basic')); |
||
| 464 | |||
| 465 | $this->$method(); |
||
| 466 | } |
||
| 467 | |||
| 468 | /** |
||
| 469 | * @dataProvider getSingleHttpTestMethods |
||
| 470 | * @param string $method |
||
| 471 | */ |
||
| 472 | public function testDigestAuth($method) |
||
| 486 | } |
||
| 487 | |||
| 488 | /** |
||
| 489 | * @param \PhpXmlRpc\Response $r |
||
| 490 | * @return void |
||
| 491 | */ |
||
| 492 | protected function validateResponse($r) |
||
| 498 | |||
| 499 | } |
||
| 500 | } |
||
| 501 | } |
||
| 502 |
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.