Total Complexity | 41 |
Total Lines | 365 |
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 | /** |
||
17 | * Returns all test methods from the base class, except the ones which failed already |
||
18 | * |
||
19 | * @todo (re)introduce skipping of tests which failed when executed individually even if test runs happen as separate processes |
||
20 | * @todo reintroduce skipping of tests within the loop |
||
21 | */ |
||
22 | public function getSingleHttpTestMethods() |
||
23 | { |
||
24 | $unsafeMethods = array( |
||
25 | 'testCatchExceptions', 'testUtf8Method', 'testServerComments', |
||
26 | 'testExoticCharsetsRequests', 'testExoticCharsetsRequests2', 'testExoticCharsetsRequests3', |
||
27 | ); |
||
28 | |||
29 | $methods = array(); |
||
30 | foreach(get_class_methods('ServerTest') as $method) |
||
31 | { |
||
32 | if (strpos($method, 'test') === 0 && !in_array($method, $unsafeMethods)) |
||
33 | { |
||
34 | if (!isset(self::$failed_tests[$method])) { |
||
35 | $methods[$method] = array($method); |
||
36 | } |
||
37 | } |
||
38 | } |
||
39 | |||
40 | return $methods; |
||
41 | } |
||
42 | |||
43 | /** |
||
44 | * @dataProvider getSingleHttpTestMethods |
||
45 | * @param string $method |
||
46 | */ |
||
47 | public function testDeflate($method) |
||
48 | { |
||
49 | if (!function_exists('gzdeflate')) |
||
50 | { |
||
51 | $this->markTestSkipped('Zlib missing: cannot test deflate functionality'); |
||
52 | return; |
||
53 | } |
||
54 | |||
55 | $this->client->accepted_compression = array('deflate'); |
||
56 | $this->client->request_compression = 'deflate'; |
||
57 | |||
58 | $this->$method(); |
||
59 | } |
||
60 | |||
61 | /** |
||
62 | * @dataProvider getSingleHttpTestMethods |
||
63 | * @param string $method |
||
64 | */ |
||
65 | public function testGzip($method) |
||
66 | { |
||
67 | if (!function_exists('gzdeflate')) |
||
68 | { |
||
69 | $this->markTestSkipped('Zlib missing: cannot test gzip functionality'); |
||
70 | return; |
||
71 | } |
||
72 | |||
73 | $this->client->accepted_compression = array('gzip'); |
||
74 | $this->client->request_compression = 'gzip'; |
||
75 | |||
76 | $this->$method(); |
||
77 | } |
||
78 | |||
79 | public function testKeepAlives() |
||
80 | { |
||
81 | if (!function_exists('curl_init')) |
||
82 | { |
||
83 | $this->markTestSkipped('CURL missing: cannot test http 1.1'); |
||
84 | return; |
||
85 | } |
||
86 | |||
87 | $this->method = 'http11'; |
||
88 | $this->client->method = 'http11'; |
||
89 | $this->client->keepalive = true; |
||
90 | |||
91 | // to successfully test keepalive, we have to reuse the same client for all tests, we can not recreate one on setup/teardown... |
||
92 | foreach ($this->getSingleHttpTestMethods() as $methods) { |
||
93 | $method = $methods[0]; |
||
94 | $this->$method(); |
||
95 | } |
||
96 | } |
||
97 | |||
98 | /** |
||
99 | * @dataProvider getSingleHttpTestMethods |
||
100 | * @param string $method |
||
101 | */ |
||
102 | public function testProxy($method) |
||
103 | { |
||
104 | if ($this->args['PROXYSERVER'] == '') |
||
105 | { |
||
106 | $this->markTestSkipped('PROXYSERVER definition missing: cannot test proxy'); |
||
107 | return; |
||
108 | } |
||
109 | |||
110 | $this->client->setProxy($this->args['PROXYSERVER'], $this->args['PROXYPORT']); |
||
111 | |||
112 | $this->$method(); |
||
113 | } |
||
114 | |||
115 | /** |
||
116 | * @dataProvider getSingleHttpTestMethods |
||
117 | * @param string $method |
||
118 | */ |
||
119 | public function testHttp11($method) |
||
120 | { |
||
121 | if (!function_exists('curl_init')) |
||
122 | { |
||
123 | $this->markTestSkipped('CURL missing: cannot test http 1.1'); |
||
124 | return; |
||
125 | } |
||
126 | |||
127 | $this->method = 'http11'; // not an error the double assignment! |
||
128 | $this->client->method = 'http11'; |
||
129 | $this->client->keepalive = false; |
||
130 | |||
131 | $this->$method(); |
||
132 | } |
||
133 | |||
134 | /** |
||
135 | * @dataProvider getSingleHttpTestMethods |
||
136 | * @param string $method |
||
137 | */ |
||
138 | public function testHttp10Curl($method) |
||
139 | { |
||
140 | if (!function_exists('curl_init')) |
||
141 | { |
||
142 | $this->markTestSkipped('CURL missing: cannot test http 1.1'); |
||
143 | return; |
||
144 | } |
||
145 | |||
146 | $this->method = 'http10'; // not an error the double assignment! |
||
147 | $this->client->method = 'http10'; |
||
148 | $this->client->keepalive = false; |
||
149 | $this->client->setUseCurl(\PhpXmlRpc\Client::USE_CURL_ALWAYS); |
||
150 | |||
151 | $this->$method(); |
||
152 | } |
||
153 | |||
154 | /** |
||
155 | * @dataProvider getSingleHttpTestMethods |
||
156 | * @param string $method |
||
157 | */ |
||
158 | public function testHttp11Gzip($method) |
||
159 | { |
||
160 | if (!function_exists('curl_init')) |
||
161 | { |
||
162 | $this->markTestSkipped('CURL missing: cannot test http 1.1'); |
||
163 | return; |
||
164 | } |
||
165 | $this->method = 'http11'; // not an error the double assignment! |
||
166 | $this->client->method = 'http11'; |
||
167 | $this->client->keepalive = false; |
||
168 | $this->client->accepted_compression = array('gzip'); |
||
169 | $this->client->request_compression = 'gzip'; |
||
170 | |||
171 | $this->$method(); |
||
172 | } |
||
173 | |||
174 | /** |
||
175 | * @dataProvider getSingleHttpTestMethods |
||
176 | * @param string $method |
||
177 | */ |
||
178 | public function testHttp11Deflate($method) |
||
179 | { |
||
180 | if (!function_exists('curl_init')) |
||
181 | { |
||
182 | $this->markTestSkipped('CURL missing: cannot test http 1.1'); |
||
183 | return; |
||
184 | } |
||
185 | $this->method = 'http11'; // not an error the double assignment! |
||
186 | $this->client->method = 'http11'; |
||
187 | $this->client->keepalive = false; |
||
188 | $this->client->accepted_compression = array('deflate'); |
||
189 | $this->client->request_compression = 'deflate'; |
||
190 | |||
191 | $this->$method(); |
||
192 | } |
||
193 | |||
194 | /** |
||
195 | * @dataProvider getSingleHttpTestMethods |
||
196 | * @param string $method |
||
197 | */ |
||
198 | public function testHttp11Proxy($method) |
||
199 | { |
||
200 | if (!function_exists('curl_init')) |
||
201 | { |
||
202 | $this->markTestSkipped('CURL missing: cannot test http 1.1 w. proxy'); |
||
203 | return; |
||
204 | } |
||
205 | else if ($this->args['PROXYSERVER'] == '') |
||
206 | { |
||
207 | $this->markTestSkipped('PROXYSERVER definition missing: cannot test proxy w. http 1.1'); |
||
208 | return; |
||
209 | } |
||
210 | |||
211 | $this->method = 'http11'; // not an error the double assignment! |
||
212 | $this->client->method = 'http11'; |
||
213 | $this->client->setProxy($this->args['PROXYSERVER'], $this->args['PROXYPORT']); |
||
214 | $this->client->keepalive = false; |
||
215 | |||
216 | $this->$method(); |
||
217 | } |
||
218 | |||
219 | /** |
||
220 | * @dataProvider getSingleHttpTestMethods |
||
221 | * @param string $method |
||
222 | */ |
||
223 | public function testHttps($method) |
||
224 | { |
||
225 | if (!function_exists('curl_init')) |
||
226 | { |
||
227 | $this->markTestSkipped('CURL missing: cannot test https functionality'); |
||
228 | return; |
||
229 | } |
||
230 | else if ($this->args['HTTPSSERVER'] == '') |
||
231 | { |
||
232 | $this->markTestSkipped('HTTPS SERVER definition missing: cannot test https'); |
||
233 | return; |
||
234 | } |
||
235 | |||
236 | $this->client->server = $this->args['HTTPSSERVER']; |
||
237 | $this->method = 'https'; |
||
238 | $this->client->method = 'https'; |
||
239 | $this->client->path = $this->args['HTTPSURI']; |
||
240 | $this->client->setSSLVerifyPeer(!$this->args['HTTPSIGNOREPEER']); |
||
241 | $this->client->setSSLVerifyHost($this->args['HTTPSVERIFYHOST']); |
||
242 | $this->client->setSSLVersion($this->args['SSLVERSION']); |
||
243 | |||
244 | $this->$method(); |
||
245 | } |
||
246 | |||
247 | /** |
||
248 | * @dataProvider getSingleHttpTestMethods |
||
249 | * @param string $method |
||
250 | */ |
||
251 | public function testHttpsSocket($method) |
||
252 | { |
||
253 | if ($this->args['HTTPSSERVER'] == '') |
||
254 | { |
||
255 | $this->markTestSkipped('HTTPS SERVER definition missing: cannot test https'); |
||
256 | return; |
||
257 | } |
||
258 | |||
259 | $this->client->server = $this->args['HTTPSSERVER']; |
||
260 | $this->method = 'https'; |
||
261 | $this->client->method = 'https'; |
||
262 | $this->client->path = $this->args['HTTPSURI']; |
||
263 | $this->client->setSSLVerifyPeer(!$this->args['HTTPSIGNOREPEER']); |
||
264 | $this->client->setSSLVerifyHost($this->args['HTTPSVERIFYHOST']); |
||
265 | $this->client->setSSLVersion($this->args['SSLVERSION']); |
||
266 | $this->client->setUseCurl(\PhpXmlRpc\Client::USE_CURL_NEVER); |
||
267 | |||
268 | $this->$method(); |
||
269 | } |
||
270 | |||
271 | /** |
||
272 | * @dataProvider getSingleHttpTestMethods |
||
273 | * @param string $method |
||
274 | */ |
||
275 | public function testHttpsProxy($method) |
||
276 | { |
||
277 | if (!function_exists('curl_init')) |
||
278 | { |
||
279 | $this->markTestSkipped('CURL missing: cannot test https w. proxy'); |
||
280 | return; |
||
281 | } |
||
282 | else if ($this->args['PROXYSERVER'] == '') |
||
283 | { |
||
284 | $this->markTestSkipped('PROXYSERVER definition missing: cannot test proxy w. https'); |
||
285 | return; |
||
286 | } |
||
287 | else if ($this->args['HTTPSSERVER'] == '') |
||
288 | { |
||
289 | $this->markTestSkipped('HTTPS SERVER definition missing: cannot test https w. proxy'); |
||
290 | return; |
||
291 | } |
||
292 | |||
293 | $this->client->server = $this->args['HTTPSSERVER']; |
||
294 | $this->method = 'https'; |
||
295 | $this->client->method = 'https'; |
||
296 | $this->client->setProxy($this->args['PROXYSERVER'], $this->args['PROXYPORT']); |
||
297 | $this->client->path = $this->args['HTTPSURI']; |
||
298 | $this->client->setSSLVerifyPeer(!$this->args['HTTPSIGNOREPEER']); |
||
299 | $this->client->setSSLVerifyHost($this->args['HTTPSVERIFYHOST']); |
||
300 | $this->client->setSSLVersion($this->args['SSLVERSION']); |
||
301 | |||
302 | $this->$method(); |
||
303 | } |
||
304 | |||
305 | /** |
||
306 | * @dataProvider getSingleHttpTestMethods |
||
307 | * @param string $method |
||
308 | */ |
||
309 | public function testUTF8Responses($method) |
||
310 | { |
||
311 | $this->addQueryParams(array('RESPONSE_ENCODING' => 'UTF-8')); |
||
312 | |||
313 | $this->$method(); |
||
314 | } |
||
315 | |||
316 | /** |
||
317 | * @dataProvider getSingleHttpTestMethods |
||
318 | * @param string $method |
||
319 | */ |
||
320 | public function testUTF8Requests($method) |
||
325 | } |
||
326 | |||
327 | /** |
||
328 | * @dataProvider getSingleHttpTestMethods |
||
329 | * @param string $method |
||
330 | */ |
||
331 | public function testISOResponses($method) |
||
332 | { |
||
333 | $this->addQueryParams(array('RESPONSE_ENCODING' => 'ISO-8859-1')); |
||
334 | |||
335 | $this->$method(); |
||
336 | } |
||
337 | |||
338 | /** |
||
339 | * @dataProvider getSingleHttpTestMethods |
||
340 | * @param string $method |
||
341 | */ |
||
342 | public function testISORequests($method) |
||
343 | { |
||
344 | $this->client->request_charset_encoding = 'ISO-8859-1'; |
||
345 | |||
346 | $this->$method(); |
||
347 | } |
||
348 | |||
349 | /** |
||
350 | * @dataProvider getSingleHttpTestMethods |
||
351 | * @param string $method |
||
352 | */ |
||
353 | public function testBasicAuth($method) |
||
354 | { |
||
355 | $this->client->setCredentials('test', 'test'); |
||
356 | $this->addQueryParams(array('FORCE_AUTH' => 'Basic')); |
||
357 | |||
358 | $this->$method(); |
||
359 | } |
||
360 | |||
361 | /** |
||
362 | * @dataProvider getSingleHttpTestMethods |
||
363 | * @param string $method |
||
364 | */ |
||
365 | public function testDigestAuth($method) |
||
379 | } |
||
380 | } |
||
381 |