Completed
Push — master ( c4596e...19d9e6 )
by Gaetano
03:28
created

LocalhostMultiTest::getSingleHttpTestMethods()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 20
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 10
nc 4
nop 0
dl 0
loc 20
rs 8.8571
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 14 and the first side effect is on line 3.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
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
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
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('testHttps', 'testCatchExceptions', 'testUtf8Method', 'testServerComments', 'testExoticCharsetsRequests',
25
            'testExoticCharsetsRequests2', 'testExoticCharsetsRequests3',
26
            // @todo the following are currently not compatible w Digest Auth (most likely because of client copy) and should be fixed
27
            'testcatchWarnings', 'testWrappedMethodAsSource', 'testTransferOfObjectViaWrapping');
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 View Code Duplication
    public function testKeepAlives()
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...
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 $method) {
93
            $this->$method;
94
        }
95
    }
96
97
    /**
98
     * @dataProvider getSingleHttpTestMethods
99
     * @param string $method
100
     */
101
    public function testProxy($method)
102
    {
103
        if (!$this->args['PROXYSERVER'])
104
        {
105
            $this->markTestSkipped('PROXY definition missing: cannot test proxy');
106
            return;
107
        }
108
109
        $this->client->setProxy($this->args['PROXYSERVER'], $this->args['PROXYPORT']);
110
111
        $this->$method();
112
    }
113
114
    /**
115
     * @dataProvider getSingleHttpTestMethods
116
     * @param string $method
117
     */
118 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...
119
    {
120
        if(!function_exists('curl_init'))
121
        {
122
            $this->markTestSkipped('CURL missing: cannot test http 1.1');
123
            return;
124
        }
125
126
        $this->method = 'http11'; // not an error the double assignment!
127
        $this->client->method = 'http11';
128
        $this->client->keepalive = false;
129
130
        $this->$method();
131
    }
132
133
    /**
134
     * @dataProvider getSingleHttpTestMethods
135
     * @param string $method
136
     */
137 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...
138
    {
139
        if(!function_exists('curl_init'))
140
        {
141
            $this->markTestSkipped('CURL missing: cannot test http 1.1');
142
            return;
143
        }
144
        $this->method = 'http11'; // not an error the double assignment!
145
        $this->client->method = 'http11';
146
        $this->client->keepalive = false;
147
        $this->client->accepted_compression = array('gzip');
148
        $this->client->request_compression = 'gzip';
149
150
        $this->$method();
151
    }
152
153
    /**
154
     * @dataProvider getSingleHttpTestMethods
155
     * @param string $method
156
     */
157 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...
158
    {
159
        if(!function_exists('curl_init'))
160
        {
161
            $this->markTestSkipped('CURL missing: cannot test http 1.1');
162
            return;
163
        }
164
        $this->method = 'http11'; // not an error the double assignment!
165
        $this->client->method = 'http11';
166
        $this->client->keepalive = false;
167
        $this->client->accepted_compression = array('deflate');
168
        $this->client->request_compression = 'deflate';
169
170
        $this->$method();
171
    }
172
173
    /**
174
     * @dataProvider getSingleHttpTestMethods
175
     * @param string $method
176
     */
177
    public function testHttp11Proxy($method)
178
    {
179 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...
180
        {
181
            $this->markTestSkipped('CURL missing: cannot test http 1.1 w. proxy');
182
            return;
183
        }
184
        else if ($this->args['PROXYSERVER'] == '')
185
        {
186
            $this->markTestSkipped('PROXY definition missing: cannot test proxy w. http 1.1');
187
            return;
188
        }
189
190
        $this->method = 'http11'; // not an error the double assignment!
191
        $this->client->method = 'http11';
192
        $this->client->setProxy($this->args['PROXYSERVER'], $this->args['PROXYPORT']);
193
        $this->client->keepalive = false;
194
195
        $this->$method();
196
    }
197
198
    /**
199
     * @dataProvider getSingleHttpTestMethods
200
     * @param string $method
201
     */
202
    public function testHttps($method)
203
    {
204
        if(!function_exists('curl_init'))
205
        {
206
            $this->markTestSkipped('CURL missing: cannot test https functionality');
207
            return;
208
        }
209
210
        $this->client->server = $this->args['HTTPSSERVER'];
211
        $this->method = 'https';
212
        $this->client->method = 'https';
213
        $this->client->path = $this->args['HTTPSURI'];
214
        $this->client->setSSLVerifyPeer(!$this->args['HTTPSIGNOREPEER']);
215
        $this->client->setSSLVerifyHost($this->args['HTTPSVERIFYHOST']);
216
        $this->client->setSSLVersion($this->args['SSLVERSION']);
217
218
        $this->$method();
219
    }
220
221
    /**
222
     * @dataProvider getSingleHttpTestMethods
223
     * @param string $method
224
     */
225
    public function testHttpsProxy($method)
226
    {
227 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...
228
        {
229
            $this->markTestSkipped('CURL missing: cannot test https functionality');
230
            return;
231
        }
232
        else if ($this->args['PROXYSERVER'] == '')
233
        {
234
            $this->markTestSkipped('PROXY definition missing: cannot test proxy w. http 1.1');
235
            return;
236
        }
237
        $this->client->server = $this->args['HTTPSSERVER'];
238
        $this->method = 'https';
239
        $this->client->method = 'https';
240
        $this->client->setProxy($this->args['PROXYSERVER'], $this->args['PROXYPORT']);
241
        $this->client->path = $this->args['HTTPSURI'];
242
        $this->client->setSSLVerifyPeer(!$this->args['HTTPSIGNOREPEER']);
243
        $this->client->setSSLVerifyHost($this->args['HTTPSVERIFYHOST']);
244
        $this->client->setSSLVersion($this->args['SSLVERSION']);
245
246
        $this->$method();
247
    }
248
249
    /**
250
     * @dataProvider getSingleHttpTestMethods
251
     * @param string $method
252
     */
253
    public function testUTF8Responses($method)
254
    {
255
        $this->addQueryParams(array('RESPONSE_ENCODING' => 'UTF-8'));
256
257
        $this->$method();
258
    }
259
260
    /**
261
     * @dataProvider getSingleHttpTestMethods
262
     * @param string $method
263
     */
264
    public function testUTF8Requests($method)
265
    {
266
        $this->client->request_charset_encoding = 'UTF-8';
267
268
        $this->$method();
269
    }
270
271
    /**
272
     * @dataProvider getSingleHttpTestMethods
273
     * @param string $method
274
     */
275
    public function testISOResponses($method)
276
    {
277
        $this->addQueryParams(array('RESPONSE_ENCODING' => 'ISO-8859-1'));
278
279
        $this->$method();
280
    }
281
282
    /**
283
     * @dataProvider getSingleHttpTestMethods
284
     * @param string $method
285
     */
286
    public function testISORequests($method)
287
    {
288
        $this->client->request_charset_encoding = 'ISO-8859-1';
289
290
        $this->$method();
291
    }
292
293
    /**
294
     * @dataProvider getSingleHttpTestMethods
295
     * @param string $method
296
     */
297
    public function testBasicAuth($method)
298
    {
299
        $this->client->setCredentials('test', 'test');
300
        $this->addQueryParams(array('FORCE_AUTH' => 'Basic'));
301
302
        $this->$method();
303
    }
304
305
    /**
306
     * @dataProvider getSingleHttpTestMethods
307
     * @param string $method
308
     */
309
    public function testDigestAuth($method)
310
    {
311
        if (!function_exists('curl_init'))
312
        {
313
            $this->markTestSkipped('CURL missing: cannot test digest auth functionality');
314
            return;
315
        }
316
317
        $this->client->setCredentials('test', 'test', CURLAUTH_DIGEST);
318
        $this->addQueryParams(array('FORCE_AUTH' => 'Digest'));
319
        $this->method = 'http11';
320
        $this->client->method = 'http11';
321
322
        $this->$method();
323
    }
324
}
325