Completed
Push — master ( b37706...ce870f )
by Gaetano
04:10
created

LocalhostMultiTest   B

Complexity

Total Complexity 37

Size/Duplication

Total Lines 324
Duplicated Lines 23.46 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 76
loc 324
rs 8.6
c 0
b 0
f 0
wmc 37
lcom 1
cbo 2

17 Methods

Rating   Name   Duplication   Size   Complexity  
B getSingleHttpTestMethods() 0 21 5
A testDeflate() 13 13 2
A testGzip() 13 13 2
A testKeepAlives() 0 18 3
A testProxy() 0 12 2
A testHttp11() 0 14 2
A testHttp11Gzip() 15 15 2
A testHttp11Deflate() 15 15 2
A testHttp11Proxy() 10 20 3
A testHttps() 10 23 3
B testHttpsProxy() 0 29 4
A testUTF8Responses() 0 6 1
A testUTF8Requests() 0 6 1
A testISOResponses() 0 6 1
A testISORequests() 0 6 1
A testBasicAuth() 0 7 1
A testDigestAuth() 0 15 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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