| Total Complexity | 50 |
| Total Lines | 438 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
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() |
||
| 83 | { |
||
| 84 | if (!function_exists('curl_init')) |
||
| 85 | { |
||
| 86 | $this->markTestSkipped('CURL missing: cannot test http 1.1'); |
||
| 87 | return; |
||
| 88 | } |
||
| 89 | |||
| 90 | $this->method = 'http11'; |
||
| 91 | $this->client->method = 'http11'; |
||
| 92 | $this->client->keepalive = true; |
||
| 93 | |||
| 94 | // to successfully test keepalive, we have to reuse the same client for all tests, we can not recreate one on setup/teardown... |
||
| 95 | foreach ($this->getSingleHttpTestMethods() as $methods) { |
||
| 96 | $method = $methods[0]; |
||
| 97 | $this->$method(); |
||
| 98 | } |
||
| 99 | } |
||
| 100 | |||
| 101 | /** |
||
| 102 | * @dataProvider getSingleHttpTestMethods |
||
| 103 | * @param string $method |
||
| 104 | */ |
||
| 105 | public function testProxy($method) |
||
| 106 | { |
||
| 107 | if ($this->args['PROXYSERVER'] == '') |
||
| 108 | { |
||
| 109 | $this->markTestSkipped('PROXYSERVER definition missing: cannot test proxy'); |
||
| 110 | return; |
||
| 111 | } |
||
| 112 | |||
| 113 | $this->client->setProxy($this->args['PROXYSERVER'], $this->args['PROXYPORT']); |
||
| 114 | |||
| 115 | $this->$method(); |
||
| 116 | } |
||
| 117 | |||
| 118 | /** |
||
| 119 | * @dataProvider getSingleHttpTestMethods |
||
| 120 | * @param string $method |
||
| 121 | */ |
||
| 122 | public function testHttp11($method) |
||
| 123 | { |
||
| 124 | if (!function_exists('curl_init')) |
||
| 125 | { |
||
| 126 | $this->markTestSkipped('CURL missing: cannot test http 1.1'); |
||
| 127 | return; |
||
| 128 | } |
||
| 129 | |||
| 130 | $this->method = 'http11'; // not an error the double assignment! |
||
| 131 | $this->client->method = 'http11'; |
||
| 132 | $this->client->keepalive = false; |
||
| 133 | |||
| 134 | $this->$method(); |
||
| 135 | } |
||
| 136 | |||
| 137 | /** |
||
| 138 | * @dataProvider getSingleHttpTestMethods |
||
| 139 | * @param string $method |
||
| 140 | */ |
||
| 141 | public function testHttp10Curl($method) |
||
| 142 | { |
||
| 143 | if (!function_exists('curl_init')) |
||
| 144 | { |
||
| 145 | $this->markTestSkipped('CURL missing: cannot test http 1.1'); |
||
| 146 | return; |
||
| 147 | } |
||
| 148 | |||
| 149 | $this->method = 'http10'; // not an error the double assignment! |
||
| 150 | $this->client->method = 'http10'; |
||
| 151 | $this->client->keepalive = false; |
||
| 152 | $this->client->setUseCurl(\PhpXmlRpc\Client::USE_CURL_ALWAYS); |
||
| 153 | |||
| 154 | $this->$method(); |
||
| 155 | } |
||
| 156 | |||
| 157 | /** |
||
| 158 | * @dataProvider getSingleHttpTestMethods |
||
| 159 | * @param string $method |
||
| 160 | */ |
||
| 161 | public function testHttp11Gzip($method) |
||
| 162 | { |
||
| 163 | if (!function_exists('curl_init')) |
||
| 164 | { |
||
| 165 | $this->markTestSkipped('CURL missing: cannot test http 1.1'); |
||
| 166 | return; |
||
| 167 | } |
||
| 168 | $this->method = 'http11'; // not an error the double assignment! |
||
| 169 | $this->client->method = 'http11'; |
||
| 170 | $this->client->keepalive = false; |
||
| 171 | $this->client->accepted_compression = array('gzip'); |
||
| 172 | $this->client->request_compression = 'gzip'; |
||
| 173 | |||
| 174 | $this->$method(); |
||
| 175 | } |
||
| 176 | |||
| 177 | /** |
||
| 178 | * @dataProvider getSingleHttpTestMethods |
||
| 179 | * @param string $method |
||
| 180 | */ |
||
| 181 | public function testHttp11Deflate($method) |
||
| 182 | { |
||
| 183 | if (!function_exists('curl_init')) |
||
| 184 | { |
||
| 185 | $this->markTestSkipped('CURL missing: cannot test http 1.1'); |
||
| 186 | return; |
||
| 187 | } |
||
| 188 | $this->method = 'http11'; // not an error the double assignment! |
||
| 189 | $this->client->method = 'http11'; |
||
| 190 | $this->client->keepalive = false; |
||
| 191 | $this->client->accepted_compression = array('deflate'); |
||
| 192 | $this->client->request_compression = 'deflate'; |
||
| 193 | |||
| 194 | $this->$method(); |
||
| 195 | } |
||
| 196 | |||
| 197 | /** |
||
| 198 | * @dataProvider getSingleHttpTestMethods |
||
| 199 | * @param string $method |
||
| 200 | */ |
||
| 201 | public function testHttp11Proxy($method) |
||
| 202 | { |
||
| 203 | if (!function_exists('curl_init')) |
||
| 204 | { |
||
| 205 | $this->markTestSkipped('CURL missing: cannot test http 1.1 w. proxy'); |
||
| 206 | return; |
||
| 207 | } |
||
| 208 | else if ($this->args['PROXYSERVER'] == '') |
||
| 209 | { |
||
| 210 | $this->markTestSkipped('PROXYSERVER definition missing: cannot test proxy w. http 1.1'); |
||
| 211 | return; |
||
| 212 | } |
||
| 213 | |||
| 214 | $this->method = 'http11'; // not an error the double assignment! |
||
| 215 | $this->client->method = 'http11'; |
||
| 216 | $this->client->setProxy($this->args['PROXYSERVER'], $this->args['PROXYPORT']); |
||
| 217 | $this->client->keepalive = false; |
||
| 218 | |||
| 219 | $this->$method(); |
||
| 220 | } |
||
| 221 | |||
| 222 | /** |
||
| 223 | * @dataProvider getSingleHttpTestMethods |
||
| 224 | * @param string $method |
||
| 225 | */ |
||
| 226 | public function testHttps($method) |
||
| 227 | { |
||
| 228 | if (!function_exists('curl_init')) |
||
| 229 | { |
||
| 230 | $this->markTestSkipped('CURL missing: cannot test https functionality'); |
||
| 231 | return; |
||
| 232 | } |
||
| 233 | else if ($this->args['HTTPSSERVER'] == '') |
||
| 234 | { |
||
| 235 | $this->markTestSkipped('HTTPS SERVER definition missing: cannot test https'); |
||
| 236 | return; |
||
| 237 | } |
||
| 238 | |||
| 239 | $this->client->server = $this->args['HTTPSSERVER']; |
||
| 240 | $this->method = 'https'; |
||
| 241 | $this->client->method = 'https'; |
||
| 242 | $this->client->path = $this->args['HTTPSURI']; |
||
| 243 | $this->client->setSSLVerifyPeer(!$this->args['HTTPSIGNOREPEER']); |
||
| 244 | $this->client->setSSLVerifyHost($this->args['HTTPSVERIFYHOST']); |
||
| 245 | $this->client->setSSLVersion($this->args['SSLVERSION']); |
||
| 246 | |||
| 247 | $this->$method(); |
||
| 248 | } |
||
| 249 | |||
| 250 | /** |
||
| 251 | * @dataProvider getSingleHttpTestMethods |
||
| 252 | * @param string $method |
||
| 253 | */ |
||
| 254 | public function testHttpsSocket($method) |
||
| 255 | { |
||
| 256 | if ($this->args['HTTPSSERVER'] == '') |
||
| 257 | { |
||
| 258 | $this->markTestSkipped('HTTPS SERVER definition missing: cannot test https'); |
||
| 259 | return; |
||
| 260 | } |
||
| 261 | |||
| 262 | $this->client->server = $this->args['HTTPSSERVER']; |
||
| 263 | $this->method = 'https'; |
||
| 264 | $this->client->method = 'https'; |
||
| 265 | $this->client->path = $this->args['HTTPSURI']; |
||
| 266 | $this->client->setSSLVerifyPeer(!$this->args['HTTPSIGNOREPEER']); |
||
| 267 | $this->client->setSSLVerifyHost($this->args['HTTPSVERIFYHOST']); |
||
| 268 | $this->client->setSSLVersion($this->args['SSLVERSION']); |
||
| 269 | $this->client->setUseCurl(\PhpXmlRpc\Client::USE_CURL_NEVER); |
||
| 270 | |||
| 271 | $this->$method(); |
||
| 272 | } |
||
| 273 | |||
| 274 | /** |
||
| 275 | * @dataProvider getSingleHttpTestMethods |
||
| 276 | * @param string $method |
||
| 277 | */ |
||
| 278 | public function testHttpsProxy($method) |
||
| 279 | { |
||
| 280 | if (!function_exists('curl_init')) |
||
| 281 | { |
||
| 282 | $this->markTestSkipped('CURL missing: cannot test https w. proxy'); |
||
| 283 | return; |
||
| 284 | } |
||
| 285 | else if ($this->args['PROXYSERVER'] == '') |
||
| 286 | { |
||
| 287 | $this->markTestSkipped('PROXYSERVER definition missing: cannot test proxy w. https'); |
||
| 288 | return; |
||
| 289 | } |
||
| 290 | else if ($this->args['HTTPSSERVER'] == '') |
||
| 291 | { |
||
| 292 | $this->markTestSkipped('HTTPS SERVER definition missing: cannot test https w. proxy'); |
||
| 293 | return; |
||
| 294 | } |
||
| 295 | |||
| 296 | $this->client->server = $this->args['HTTPSSERVER']; |
||
| 297 | $this->method = 'https'; |
||
| 298 | $this->client->method = 'https'; |
||
| 299 | $this->client->setProxy($this->args['PROXYSERVER'], $this->args['PROXYPORT']); |
||
| 300 | $this->client->path = $this->args['HTTPSURI']; |
||
| 301 | $this->client->setSSLVerifyPeer(!$this->args['HTTPSIGNOREPEER']); |
||
| 302 | $this->client->setSSLVerifyHost($this->args['HTTPSVERIFYHOST']); |
||
| 303 | $this->client->setSSLVersion($this->args['SSLVERSION']); |
||
| 304 | |||
| 305 | $this->$method(); |
||
| 306 | } |
||
| 307 | |||
| 308 | /** |
||
| 309 | * @dataProvider getSingleHttpTestMethods |
||
| 310 | * @param string $method |
||
| 311 | */ |
||
| 312 | public function testHttp2($method) |
||
| 313 | { |
||
| 314 | if (!function_exists('curl_init')) |
||
| 315 | { |
||
| 316 | $this->markTestSkipped('CURL missing: cannot test http/2'); |
||
| 317 | return; |
||
| 318 | } else if (!defined('CURL_HTTP_VERSION_2')) |
||
| 319 | { |
||
| 320 | $this->markTestSkipped('CURL http/2 support missing: cannot test http/2'); |
||
| 321 | return; |
||
| 322 | } |
||
| 323 | |||
| 324 | $this->method = 'http2'; // not an error the double assignment! |
||
| 325 | $this->client->method = 'http2'; |
||
| 326 | //$this->client->keepalive = false; // q: is this a good idea? |
||
| 327 | |||
| 328 | $this->expectHttp2 = true; |
||
| 329 | $this->$method(); |
||
| 330 | $this->expectHttp2 = false; |
||
| 331 | } |
||
| 332 | |||
| 333 | /** |
||
| 334 | * @dataProvider getSingleHttpTestMethods |
||
| 335 | * @param string $method |
||
| 336 | */ |
||
| 337 | public function testHttp2tls($method) |
||
| 364 | } |
||
| 365 | |||
| 366 | /** |
||
| 367 | * @dataProvider getSingleHttpTestMethods |
||
| 368 | * @param string $method |
||
| 369 | */ |
||
| 370 | public function testUTF8Responses($method) |
||
| 371 | { |
||
| 372 | $this->addQueryParams(array('RESPONSE_ENCODING' => 'UTF-8')); |
||
| 373 | |||
| 374 | $this->$method(); |
||
| 375 | } |
||
| 376 | |||
| 377 | /** |
||
| 378 | * @dataProvider getSingleHttpTestMethods |
||
| 379 | * @param string $method |
||
| 380 | */ |
||
| 381 | public function testUTF8Requests($method) |
||
| 386 | } |
||
| 387 | |||
| 388 | /** |
||
| 389 | * @dataProvider getSingleHttpTestMethods |
||
| 390 | * @param string $method |
||
| 391 | */ |
||
| 392 | public function testISOResponses($method) |
||
| 393 | { |
||
| 394 | $this->addQueryParams(array('RESPONSE_ENCODING' => 'ISO-8859-1')); |
||
| 395 | |||
| 396 | $this->$method(); |
||
| 397 | } |
||
| 398 | |||
| 399 | /** |
||
| 400 | * @dataProvider getSingleHttpTestMethods |
||
| 401 | * @param string $method |
||
| 402 | */ |
||
| 403 | public function testISORequests($method) |
||
| 404 | { |
||
| 405 | $this->client->request_charset_encoding = 'ISO-8859-1'; |
||
| 406 | |||
| 407 | $this->$method(); |
||
| 408 | } |
||
| 409 | |||
| 410 | /** |
||
| 411 | * @dataProvider getSingleHttpTestMethods |
||
| 412 | * @param string $method |
||
| 413 | */ |
||
| 414 | public function testBasicAuth($method) |
||
| 415 | { |
||
| 416 | $this->client->setCredentials('test', 'test'); |
||
| 417 | $this->addQueryParams(array('FORCE_AUTH' => 'Basic')); |
||
| 418 | |||
| 419 | $this->$method(); |
||
| 420 | } |
||
| 421 | |||
| 422 | /** |
||
| 423 | * @dataProvider getSingleHttpTestMethods |
||
| 424 | * @param string $method |
||
| 425 | */ |
||
| 426 | public function testDigestAuth($method) |
||
| 440 | } |
||
| 441 | |||
| 442 | /** |
||
| 443 | * @param \PhpXmlRpc\Response $r |
||
| 444 | * @return void |
||
| 445 | */ |
||
| 446 | protected function validateResponse($r) |
||
| 452 | |||
| 453 | } |
||
| 454 | } |
||
| 455 | } |
||
| 456 |