Completed
Push — master ( 081f49...6be6c0 )
by Gaetano
03:29
created

LocalhostMultiTest::testDeflate()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13

Duplication

Lines 13
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 1
dl 13
loc 13
rs 9.8333
c 0
b 0
f 0
1
<?php
2
3
include_once __DIR__ . '/../lib/xmlrpc.inc';
4
include_once __DIR__ . '/../lib/xmlrpc_wrappers.inc';
5
6
include_once __DIR__ . '/parse_args.php';
7
8
include_once __DIR__ . '/3LocalhostTest.php';
9
10
/**
11
 * Tests which stress http features of the library.
12
 * Each of these tests iterates over (almost) all of the 'localhost' tests
13
 */
14
class LocalhostMultiTest extends LocalhostTest
15
{
16
    /**
17
     * Returns all test methods from the base class, except the ones which failed already
18
     *
19
     * @todo reintroduce skipping of tests which failed when executed individually 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('LocalhostTest') 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 View Code Duplication
    public function testDeflate($method)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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 View Code Duplication
    public function testGzip($method)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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('PROXY 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 View Code Duplication
    public function testHttp11($method)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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 View Code Duplication
    public function testHttp10Curl($method)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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 View Code Duplication
    public function testHttp11Gzip($method)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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 View Code Duplication
    public function testHttp11Deflate($method)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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 View Code Duplication
        if(!function_exists('curl_init'))
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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('PROXY 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 View Code Duplication
        if(!function_exists('curl_init'))
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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('PROXY 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)
321
    {
322
        $this->client->request_charset_encoding = 'UTF-8';
323
324
        $this->$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)
366
    {
367
        if (!function_exists('curl_init'))
368
        {
369
            $this->markTestSkipped('CURL missing: cannot test digest auth functionality');
370
            return;
371
        }
372
373
        $this->client->setCredentials('test', 'test', CURLAUTH_DIGEST);
374
        $this->addQueryParams(array('FORCE_AUTH' => 'Digest'));
375
        $this->method = 'http11';
376
        $this->client->method = 'http11';
377
378
        $this->$method();
379
    }
380
}
381