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

LocalhostTest::tearDown()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 11
Code Lines 8

Duplication

Lines 11
Ratio 100 %

Importance

Changes 0
Metric Value
cc 4
eloc 8
nc 3
nop 0
dl 11
loc 11
rs 9.2
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 12 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
/**
9
 * Tests which involve interaction between the client and the server.
10
 * They are run against the server found in demo/server.php
11
 */
12
class LocalhostTest extends PHPUnit_Framework_TestCase
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...
13
{
14
    /** @var xmlrpc_client $client */
15
    protected $client = null;
16
    protected $method = 'http';
17
    protected $timeout = 10;
18
    protected $request_compression = null;
19
    protected $accepted_compression = '';
20
    protected $args = array();
21
22
    protected static $failed_tests = array();
23
24
    protected $testId;
25
    /** @var boolean $collectCodeCoverageInformation */
26
    protected $collectCodeCoverageInformation;
27
    protected $coverageScriptUrl;
28
29
    public static function fail($message = '')
30
    {
31
        // save in a static var that this particular test has failed
32
        // (but only if not called from subclass objects / multitests)
33
        if (function_exists('debug_backtrace') && strtolower(get_called_class()) == 'localhosttests') {
34
            $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
35
            for ($i = 0; $i < count($trace); $i++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
36
                if (strpos($trace[$i]['function'], 'test') === 0) {
37
                    self::$failed_tests[$trace[$i]['function']] = true;
38
                    break;
39
                }
40
            }
41
        }
42
43
        parent::fail($message);
44
    }
45
46
    /**
47
     * Reimplemented to allow us to collect code coverage info from the target server.
48
     * Code taken from PHPUnit_Extensions_Selenium2TestCase
49
     *
50
     * @param PHPUnit_Framework_TestResult $result
51
     * @return PHPUnit_Framework_TestResult
52
     * @throws Exception
53
     */
54 View Code Duplication
    public function run(PHPUnit_Framework_TestResult $result = NULL)
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...
55
    {
56
        $this->testId = get_class($this) . '__' . $this->getName();
57
58
        if ($result === NULL) {
59
            $result = $this->createResult();
60
        }
61
62
        $this->collectCodeCoverageInformation = $result->getCollectCodeCoverageInformation();
63
64
        parent::run($result);
65
66
        if ($this->collectCodeCoverageInformation) {
67
            $coverage = new PHPUnit_Extensions_SeleniumCommon_RemoteCoverage(
68
                $this->coverageScriptUrl,
69
                $this->testId
70
            );
71
            $result->getCodeCoverage()->append(
72
                $coverage->get(), $this
73
            );
74
        }
75
76
        // do not call this before to give the time to the Listeners to run
77
        //$this->getStrategy()->endOfTest($this->session);
0 ignored issues
show
Unused Code Comprehensibility introduced by
77% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
78
79
        return $result;
80
    }
81
82
    public function setUp()
83
    {
84
        $this->args = argParser::getArgs();
85
86
        $server = explode(':', $this->args['LOCALSERVER']);
87
        if (count($server) > 1) {
88
            $this->client = new xmlrpc_client($this->args['URI'], $server[0], $server[1]);
89
        } else {
90
            $this->client = new xmlrpc_client($this->args['URI'], $this->args['LOCALSERVER']);
91
        }
92
93
        $this->client->setDebug($this->args['DEBUG']);
94
        $this->client->request_compression = $this->request_compression;
95
        $this->client->accepted_compression = $this->accepted_compression;
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->accepted_compression of type string is incompatible with the declared type array of property $accepted_compression.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
96
97
        $this->coverageScriptUrl = 'http://' . $this->args['LOCALSERVER'] . '/' . str_replace( '/demo/server/server.php', 'tests/phpunit_coverage.php', $this->args['URI'] );
98
99
        if ($this->args['DEBUG'] == 1)
100
            ob_start();
101
    }
102
103 View Code Duplication
    protected function tearDown()
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...
104
    {
105
        if ($this->args['DEBUG'] != 1)
106
            return;
107
        $out = ob_get_clean();
108
        $status = $this->getStatus();
109
        if ($status == PHPUnit_Runner_BaseTestRunner::STATUS_ERROR
110
            || $status == PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE) {
111
            echo $out;
112
        }
113
    }
114
115
    /**
116
     * @param PhpXmlRpc\Request|array $msg
117
     * @param int|array $errorCode
118
     * @param bool $returnResponse
119
     * @return mixed|\PhpXmlRpc\Response|\PhpXmlRpc\Response[]|\PhpXmlRpc\Value|string|null
120
     */
121
    protected function send($msg, $errorCode = 0, $returnResponse = false)
122
    {
123
        if ($this->collectCodeCoverageInformation) {
124
            $this->client->setCookie('PHPUNIT_SELENIUM_TEST_ID', $this->testId);
125
        }
126
127
        $r = $this->client->send($msg, $this->timeout, $this->method);
0 ignored issues
show
Bug introduced by
It seems like $msg defined by parameter $msg on line 121 can also be of type array; however, PhpXmlRpc\Client::send() does only seem to accept object<PhpXmlRpc\Request...XmlRpc\Request>>|string, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
128
        // for multicall, return directly array of responses
129
        if (is_array($r)) {
130
            return $r;
131
        }
132
        if (is_array($errorCode)) {
133
            $this->assertContains($r->faultCode(), $errorCode, 'Error ' . $r->faultCode() . ' connecting to server: ' . $r->faultString());
134
        } else {
135
            $this->assertEquals($errorCode, $r->faultCode(), 'Error ' . $r->faultCode() . ' connecting to server: ' . $r->faultString());
136
        }
137
        if (!$r->faultCode()) {
138
            if ($returnResponse) {
139
                return $r;
140
            } else {
141
                return $r->value();
142
            }
143
        } else {
144
            return null;
145
        }
146
    }
147
148
    /**
149
     * Adds (and replaces) query params to the url currently used by the client
150
     * @param array $data
151
     */
152
    protected function addQueryParams($data)
153
    {
154
        $query = parse_url($this->client->path, PHP_URL_QUERY);
155
        parse_str($query, $vars);
156
        $query = http_build_query(array_merge($vars, $data));
157
        $this->client->path = parse_url($this->client->path, PHP_URL_PATH) . '?' . $query;
158
    }
159
160
    public function testString()
161
    {
162
        $sendString = "here are 3 \"entities\": < > & " .
163
            "and here's a dollar sign: \$pretendvarname and a backslash too: " . chr(92) .
164
            " - isn't that great? \\\"hackery\\\" at it's best " .
165
            " also don't want to miss out on \$item[0]. " .
166
            "The real weird stuff follows: CRLF here" . chr(13) . chr(10) .
167
            "a simple CR here" . chr(13) .
168
            "a simple LF here" . chr(10) .
169
            "and then LFCR" . chr(10) . chr(13) .
170
            "last but not least weird names: G" . chr(252) . "nter, El" . chr(232) . "ne, and an xml comment closing tag: -->";
171
        $m = new xmlrpcmsg('examples.stringecho', array(
172
            new xmlrpcval($sendString, 'string'),
173
        ));
174
        $v = $this->send($m);
175
        if ($v) {
176
            // when sending/receiving non-US-ASCII encoded strings, XML says cr-lf can be normalized.
177
            // so we relax our tests...
178
            $l1 = strlen($sendString);
179
            $l2 = strlen($v->scalarval());
0 ignored issues
show
Bug introduced by
The method scalarval() does not seem to exist on object<PhpXmlRpc\Response>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
180 View Code Duplication
            if ($l1 == $l2) {
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...
181
                $this->assertEquals($sendString, $v->scalarval());
0 ignored issues
show
Bug introduced by
The method scalarval() does not seem to exist on object<PhpXmlRpc\Response>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
182
            } else {
183
                $this->assertEquals(str_replace(array("\r\n", "\r"), array("\n", "\n"), $sendString), $v->scalarval());
0 ignored issues
show
Bug introduced by
The method scalarval() does not seem to exist on object<PhpXmlRpc\Response>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
184
            }
185
        }
186
    }
187
188
    public function testLatin1String()
189
    {
190
        $sendString =
191
            "last but not least weird names: G" . chr(252) . "nter, El" . chr(232) . "ne";
192
        $x = '<?xml version="1.0" encoding="ISO-8859-1"?><methodCall><methodName>examples.stringecho</methodName><params><param><value>'.
193
            $sendString.
194
            '</value></param></params></methodCall>';
195
        $v = $this->send($x);
0 ignored issues
show
Documentation introduced by
$x is of type string, but the function expects a object<PhpXmlRpc\Request>|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
196
        if ($v) {
197
            $this->assertEquals($sendString, $v->scalarval());
0 ignored issues
show
Bug introduced by
The method scalarval() does not seem to exist on object<PhpXmlRpc\Response>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
198
        }
199
    }
200
201
    public function testExoticCharsetsRequests()
202
    {
203
        // note that we should disable this call also when mbstring is missing server-side
204
        if (!function_exists('mb_convert_encoding')) {
205
            $this->markTestSkipped('Miss mbstring extension to test exotic charsets');
206
            return;
207
        }
208
        $sendString = 'κόσμε'; // Greek word 'kosme'. NB: NOT a valid ISO8859 string!
209
        $str = '<?xml version="1.0" encoding="_ENC_"?>
210
<methodCall>
211
    <methodName>examples.stringecho</methodName>
212
    <params>
213
        <param>
214
        <value><string>'.$sendString.'</string></value>
215
        </param>
216
    </params>
217
</methodCall>';
218
219
        PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding = 'UTF-8';
220
        // we have to set the encoding declaration either in the http header or xml prolog, as mb_detect_encoding
221
        // (used on the server side) will fail recognizing these 2 charsets
222
        $v = $this->send(mb_convert_encoding(str_replace('_ENC_', 'UCS-4', $str), 'UCS-4', 'UTF-8'));
0 ignored issues
show
Documentation introduced by
mb_convert_encoding(str_...str), 'UCS-4', 'UTF-8') is of type string, but the function expects a object<PhpXmlRpc\Request>|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
223
        $this->assertEquals($sendString, $v->scalarval());
0 ignored issues
show
Bug introduced by
The method scalarval() does not seem to exist on object<PhpXmlRpc\Response>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
224
        $v = $this->send(mb_convert_encoding(str_replace('_ENC_', 'UTF-16', $str), 'UTF-16', 'UTF-8'));
0 ignored issues
show
Documentation introduced by
mb_convert_encoding(str_...tr), 'UTF-16', 'UTF-8') is of type string, but the function expects a object<PhpXmlRpc\Request>|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
225
        $this->assertEquals($sendString, $v->scalarval());
0 ignored issues
show
Bug introduced by
The method scalarval() does not seem to exist on object<PhpXmlRpc\Response>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
226
        PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding = 'ISO-8859-1';
227
    }
228
229
    public function testExoticCharsetsRequests2()
230
    {
231
        // note that we should disable this call also when mbstring is missing server-side
232
        if (!function_exists('mb_convert_encoding')) {
233
            $this->markTestSkipped('Miss mbstring extension to test exotic charsets');
234
            return;
235
        }
236
        $sendString = '安室奈美恵'; // No idea what this means :-) NB: NOT a valid ISO8859 string!
237
        $str = '<?xml version="1.0"?>
238
<methodCall>
239
    <methodName>examples.stringecho</methodName>
240
    <params>
241
        <param>
242
        <value><string>'.$sendString.'</string></value>
243
        </param>
244
    </params>
245
</methodCall>';
246
247
        PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding = 'UTF-8';
248
        // no encoding declaration either in the http header or xml prolog, let mb_detect_encoding
249
        // (used on the server side) sort it out
250
        $this->addQueryParams(array('DETECT_ENCODINGS' => array('EUC-JP', 'UTF-8')));
251
        $v = $this->send(mb_convert_encoding($str, 'EUC-JP', 'UTF-8'));
0 ignored issues
show
Documentation introduced by
mb_convert_encoding($str, 'EUC-JP', 'UTF-8') is of type string, but the function expects a object<PhpXmlRpc\Request>|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
252
        $this->assertEquals($sendString, $v->scalarval());
0 ignored issues
show
Bug introduced by
The method scalarval() does not seem to exist on object<PhpXmlRpc\Response>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
253
        PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding = 'ISO-8859-1';
254
    }
255
256
    public function testExoticCharsetsRequests3()
257
    {
258
        // note that we should disable this call also when mbstring is missing server-side
259
        if (!function_exists('mb_convert_encoding')) {
260
            $this->markTestSkipped('Miss mbstring extension to test exotic charsets');
261
            return;
262
        }
263
        $sendString = utf8_decode('élève');
264
        $str = '<?xml version="1.0"?>
265
<methodCall>
266
    <methodName>examples.stringecho</methodName>
267
    <params>
268
        <param>
269
        <value><string>'.$sendString.'</string></value>
270
        </param>
271
    </params>
272
</methodCall>';
273
274
        // no encoding declaration either in the http header or xml prolog, let mb_detect_encoding
275
        // (used on the server side) sort it out
276
        $this->addQueryParams(array('DETECT_ENCODINGS' => array('ISO-8859-1', 'UTF-8')));
277
        $v = $this->send($str);
0 ignored issues
show
Documentation introduced by
$str is of type string, but the function expects a object<PhpXmlRpc\Request>|array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
278
        $this->assertEquals($sendString, $v->scalarval());
0 ignored issues
show
Bug introduced by
The method scalarval() does not seem to exist on object<PhpXmlRpc\Response>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
279
    }
280
281
    /*public function testLatin1Method()
0 ignored issues
show
Unused Code Comprehensibility introduced by
57% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
282
    {
283
        $f = new xmlrpcmsg("tests.iso88591methodname." . chr(224) . chr(252) . chr(232), array(
284
            new xmlrpcval('hello')
285
        ));
286
        $v = $this->send($f);
287
        if ($v) {
288
            $this->assertEquals('hello', $v->scalarval());
289
        }
290
    }*/
291
292
    public function testUtf8Method()
293
    {
294
        PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding = 'UTF-8';
295
        $m = new xmlrpcmsg("tests.utf8methodname." . 'κόσμε', array(
296
            new xmlrpcval('hello')
297
        ));
298
        $v = $this->send($m);
299
        if ($v) {
300
            $this->assertEquals('hello', $v->scalarval());
0 ignored issues
show
Bug introduced by
The method scalarval() does not seem to exist on object<PhpXmlRpc\Response>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
301
        }
302
        PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding = 'ISO-8859-1';
303
    }
304
305
    public function testAddingDoubles()
306
    {
307
        // note that rounding errors mean we
308
        // keep precision to sensible levels here ;-)
309
        $a = 12.13;
310
        $b = -23.98;
311
        $m = new xmlrpcmsg('examples.addtwodouble', array(
312
            new xmlrpcval($a, 'double'),
313
            new xmlrpcval($b, 'double'),
314
        ));
315
        $v = $this->send($m);
316
        if ($v) {
317
            $this->assertEquals($a + $b, $v->scalarval());
0 ignored issues
show
Bug introduced by
The method scalarval() does not seem to exist on object<PhpXmlRpc\Response>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
318
        }
319
    }
320
321 View Code Duplication
    public function testAdding()
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...
322
    {
323
        $m = new xmlrpcmsg('examples.addtwo', array(
324
            new xmlrpcval(12, 'int'),
325
            new xmlrpcval(-23, 'int'),
326
        ));
327
        $v = $this->send($m);
328
        if ($v) {
329
            $this->assertEquals(12 - 23, $v->scalarval());
0 ignored issues
show
Bug introduced by
The method scalarval() does not seem to exist on object<PhpXmlRpc\Response>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
330
        }
331
    }
332
333 View Code Duplication
    public function testInvalidNumber()
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...
334
    {
335
        $m = new xmlrpcmsg('examples.addtwo', array(
336
            new xmlrpcval('fred', 'int'),
337
            new xmlrpcval("\"; exec('ls')", 'int'),
338
        ));
339
        $v = $this->send($m);
340
        /// @todo a fault condition should be generated here
341
        /// by the server, which we pick up on
342
        if ($v) {
343
            $this->assertEquals(0, $v->scalarval());
0 ignored issues
show
Bug introduced by
The method scalarval() does not seem to exist on object<PhpXmlRpc\Response>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
344
        }
345
    }
346
347
    public function testBoolean()
348
    {
349
        $m = new xmlrpcmsg('examples.invertBooleans', array(
350
            new xmlrpcval(array(
0 ignored issues
show
Documentation introduced by
array(new \xmlrpcval(tru...mlrpcval(0, 'boolean')) is of type array<integer,object<xml...":"object<xmlrpcval>"}>, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
351
                new xmlrpcval(true, 'boolean'),
0 ignored issues
show
Documentation introduced by
true is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
352
                new xmlrpcval(false, 'boolean'),
0 ignored issues
show
Documentation introduced by
false is of type boolean, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
353
                new xmlrpcval(1, 'boolean'),
354
                new xmlrpcval(0, 'boolean')
355
            ),
356
                'array'
357
            ),));
358
        $answer = '0101';
359
        $v = $this->send($m);
360
        if ($v) {
361
            $sz = $v->arraysize();
0 ignored issues
show
Bug introduced by
The method arraysize() does not seem to exist on object<PhpXmlRpc\Response>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
362
            $got = '';
363
            for ($i = 0; $i < $sz; $i++) {
364
                $b = $v->arraymem($i);
0 ignored issues
show
Bug introduced by
The method arraymem() does not seem to exist on object<PhpXmlRpc\Response>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
365
                if ($b->scalarval()) {
366
                    $got .= '1';
367
                } else {
368
                    $got .= '0';
369
                }
370
            }
371
            $this->assertEquals($answer, $got);
372
        }
373
    }
374
375
    public function testBase64()
376
    {
377
        $sendString = 'Mary had a little lamb,
378
Whose fleece was white as snow,
379
And everywhere that Mary went
380
the lamb was sure to go.
381
382
Mary had a little lamb
383
She tied it to a pylon
384
Ten thousand volts went down its back
385
And turned it into nylon';
386
        $m = new xmlrpcmsg('examples.decode64', array(
387
            new xmlrpcval($sendString, 'base64'),
388
        ));
389
        $v = $this->send($m);
390
        if ($v) {
391 View Code Duplication
            if (strlen($sendString) == strlen($v->scalarval())) {
0 ignored issues
show
Bug introduced by
The method scalarval() does not seem to exist on object<PhpXmlRpc\Response>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
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...
392
                $this->assertEquals($sendString, $v->scalarval());
0 ignored issues
show
Bug introduced by
The method scalarval() does not seem to exist on object<PhpXmlRpc\Response>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
393
            } else {
394
                $this->assertEquals(str_replace(array("\r\n", "\r"), array("\n", "\n"), $sendString), $v->scalarval());
0 ignored issues
show
Bug introduced by
The method scalarval() does not seem to exist on object<PhpXmlRpc\Response>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
395
            }
396
        }
397
    }
398
399
    public function testDateTime()
400
    {
401
        $time = time();
402
        $t1 = new xmlrpcval($time, 'dateTime.iso8601');
403
        $t2 = new xmlrpcval(iso8601_encode($time), 'dateTime.iso8601');
404
        $this->assertEquals($t1->serialize(), $t2->serialize());
405
        if (class_exists('DateTime')) {
406
            $datetime = new DateTime();
407
            // skip this test for php 5.2. It is a bit harder there to build a DateTime from unix timestamp with proper TZ info
408
            if (is_callable(array($datetime, 'setTimestamp'))) {
409
                $t3 = new xmlrpcval($datetime->setTimestamp($time), 'dateTime.iso8601');
0 ignored issues
show
Documentation introduced by
$datetime->setTimestamp($time) is of type object<DateTime>, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
410
                $this->assertEquals($t1->serialize(), $t3->serialize());
411
            }
412
        }
413
    }
414
415
    public function testCountEntities()
416
    {
417
        $sendString = "h'fd>onc>>l>>rw&bpu>q>e<v&gxs<ytjzkami<";
418
        $m = new xmlrpcmsg('validator1.countTheEntities', array(
419
            new xmlrpcval($sendString, 'string'),
420
        ));
421
        $v = $this->send($m);
422
        if ($v) {
423
            $got = '';
424
            $expected = '37210';
425
            $expect_array = array('ctLeftAngleBrackets', 'ctRightAngleBrackets', 'ctAmpersands', 'ctApostrophes', 'ctQuotes');
426
            foreach($expect_array as $val) {
427
                $b = $v->structmem($val);
0 ignored issues
show
Bug introduced by
The method structmem() does not seem to exist on object<PhpXmlRpc\Response>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
428
                $got .= $b->me['int'];
429
            }
430
            $this->assertEquals($expected, $got);
431
        }
432
    }
433
434
    public function _multicall_msg($method, $params)
435
    {
436
        $struct['methodName'] = new xmlrpcval($method, 'string');
0 ignored issues
show
Coding Style Comprehensibility introduced by
$struct was never initialized. Although not strictly required by PHP, it is generally a good practice to add $struct = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
437
        $struct['params'] = new xmlrpcval($params, 'array');
438
439
        return new xmlrpcval($struct, 'struct');
0 ignored issues
show
Documentation introduced by
$struct is of type array<string,object<xmlr...":"object<xmlrpcval>"}>, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
440
    }
441
442
    public function testServerMulticall()
443
    {
444
        // We manually construct a system.multicall() call to ensure
445
        // that the server supports it.
446
447
        // NB: This test will NOT pass if server does not support system.multicall.
448
449
        // Based on http://xmlrpc-c.sourceforge.net/hacks/test_multicall.py
450
        $good1 = $this->_multicall_msg(
451
            'system.methodHelp',
452
            array(php_xmlrpc_encode('system.listMethods')));
453
        $bad = $this->_multicall_msg(
454
            'test.nosuch',
455
            array(php_xmlrpc_encode(1), php_xmlrpc_encode(2)));
456
        $recursive = $this->_multicall_msg(
457
            'system.multicall',
458
            array(new xmlrpcval(array(), 'array')));
0 ignored issues
show
Documentation introduced by
array() is of type array, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
459
        $good2 = $this->_multicall_msg(
460
            'system.methodSignature',
461
            array(php_xmlrpc_encode('system.listMethods')));
462
        $arg = new xmlrpcval(
463
            array($good1, $bad, $recursive, $good2),
0 ignored issues
show
Documentation introduced by
array($good1, $bad, $recursive, $good2) is of type array<integer,object<xml...":"object<xmlrpcval>"}>, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
464
            'array'
465
        );
466
467
        $m = new xmlrpcmsg('system.multicall', array($arg));
468
        $v = $this->send($m);
469
        if ($v) {
470
            //$this->assertTrue($r->faultCode() == 0, "fault from system.multicall");
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
471
            $this->assertTrue($v->arraysize() == 4, "bad number of return values");
0 ignored issues
show
Bug introduced by
The method arraysize() does not seem to exist on object<PhpXmlRpc\Response>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
472
473
            $r1 = $v->arraymem(0);
0 ignored issues
show
Bug introduced by
The method arraymem() does not seem to exist on object<PhpXmlRpc\Response>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
474
            $this->assertTrue(
475
                $r1->kindOf() == 'array' && $r1->arraysize() == 1,
476
                "did not get array of size 1 from good1"
477
            );
478
479
            $r2 = $v->arraymem(1);
0 ignored issues
show
Bug introduced by
The method arraymem() does not seem to exist on object<PhpXmlRpc\Response>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
480
            $this->assertTrue(
481
                $r2->kindOf() == 'struct',
482
                "no fault from bad"
483
            );
484
485
            $r3 = $v->arraymem(2);
0 ignored issues
show
Bug introduced by
The method arraymem() does not seem to exist on object<PhpXmlRpc\Response>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
486
            $this->assertTrue(
487
                $r3->kindOf() == 'struct',
488
                "recursive system.multicall did not fail"
489
            );
490
491
            $r4 = $v->arraymem(3);
0 ignored issues
show
Bug introduced by
The method arraymem() does not seem to exist on object<PhpXmlRpc\Response>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
492
            $this->assertTrue(
493
                $r4->kindOf() == 'array' && $r4->arraysize() == 1,
494
                "did not get array of size 1 from good2"
495
            );
496
        }
497
    }
498
499
    public function testClientMulticall1()
500
    {
501
        // NB: This test will NOT pass if server does not support system.multicall.
502
503
        $this->client->no_multicall = false;
504
505
        $good1 = new xmlrpcmsg('system.methodHelp',
506
            array(php_xmlrpc_encode('system.listMethods')));
507
        $bad = new xmlrpcmsg('test.nosuch',
508
            array(php_xmlrpc_encode(1), php_xmlrpc_encode(2)));
509
        $recursive = new xmlrpcmsg('system.multicall',
510
            array(new xmlrpcval(array(), 'array')));
0 ignored issues
show
Documentation introduced by
array() is of type array, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
511
        $good2 = new xmlrpcmsg('system.methodSignature',
512
            array(php_xmlrpc_encode('system.listMethods'))
513
        );
514
515
        $r = $this->send(array($good1, $bad, $recursive, $good2));
516
        if ($r) {
517
            $this->assertTrue(count($r) == 4, "wrong number of return values");
518
        }
519
520
        $this->assertTrue($r[0]->faultCode() == 0, "fault from good1");
521 View Code Duplication
        if (!$r[0]->faultCode()) {
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...
522
            $val = $r[0]->value();
523
            $this->assertTrue(
524
                $val->kindOf() == 'scalar' && $val->scalartyp() == 'string',
525
                "good1 did not return string"
526
            );
527
        }
528
        $this->assertTrue($r[1]->faultCode() != 0, "no fault from bad");
529
        $this->assertTrue($r[2]->faultCode() != 0, "no fault from recursive system.multicall");
530
        $this->assertTrue($r[3]->faultCode() == 0, "fault from good2");
531 View Code Duplication
        if (!$r[3]->faultCode()) {
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...
532
            $val = $r[3]->value();
533
            $this->assertTrue($val->kindOf() == 'array', "good2 did not return array");
534
        }
535
        // This is the only assert in this test which should fail
536
        // if the test server does not support system.multicall.
537
        $this->assertTrue($this->client->no_multicall == false,
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
538
            "server does not support system.multicall"
539
        );
540
    }
541
542
    public function testClientMulticall2()
543
    {
544
        // NB: This test will NOT pass if server does not support system.multicall.
545
546
        $this->client->no_multicall = true;
547
548
        $good1 = new xmlrpcmsg('system.methodHelp',
549
            array(php_xmlrpc_encode('system.listMethods')));
550
        $bad = new xmlrpcmsg('test.nosuch',
551
            array(php_xmlrpc_encode(1), php_xmlrpc_encode(2)));
552
        $recursive = new xmlrpcmsg('system.multicall',
553
            array(new xmlrpcval(array(), 'array')));
0 ignored issues
show
Documentation introduced by
array() is of type array, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
554
        $good2 = new xmlrpcmsg('system.methodSignature',
555
            array(php_xmlrpc_encode('system.listMethods'))
556
        );
557
558
        $r = $this->send(array($good1, $bad, $recursive, $good2));
559
        if ($r) {
560
            $this->assertTrue(count($r) == 4, "wrong number of return values");
561
        }
562
563
        $this->assertTrue($r[0]->faultCode() == 0, "fault from good1");
564 View Code Duplication
        if (!$r[0]->faultCode()) {
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...
565
            $val = $r[0]->value();
566
            $this->assertTrue(
567
                $val->kindOf() == 'scalar' && $val->scalartyp() == 'string',
568
                "good1 did not return string");
569
        }
570
        $this->assertTrue($r[1]->faultCode() != 0, "no fault from bad");
571
        $this->assertTrue($r[2]->faultCode() == 0, "fault from (non recursive) system.multicall");
572
        $this->assertTrue($r[3]->faultCode() == 0, "fault from good2");
573 View Code Duplication
        if (!$r[3]->faultCode()) {
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...
574
            $val = $r[3]->value();
575
            $this->assertTrue($val->kindOf() == 'array', "good2 did not return array");
576
        }
577
    }
578
579
    public function testClientMulticall3()
580
    {
581
        // NB: This test will NOT pass if server does not support system.multicall.
582
583
        $this->client->return_type = 'phpvals';
584
        $this->client->no_multicall = false;
585
586
        $good1 = new xmlrpcmsg('system.methodHelp',
587
            array(php_xmlrpc_encode('system.listMethods')));
588
        $bad = new xmlrpcmsg('test.nosuch',
589
            array(php_xmlrpc_encode(1), php_xmlrpc_encode(2)));
590
        $recursive = new xmlrpcmsg('system.multicall',
591
            array(new xmlrpcval(array(), 'array')));
0 ignored issues
show
Documentation introduced by
array() is of type array, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
592
        $good2 = new xmlrpcmsg('system.methodSignature',
593
            array(php_xmlrpc_encode('system.listMethods'))
594
        );
595
596
        $r = $this->send(array($good1, $bad, $recursive, $good2));
597
        if ($r) {
598
            $this->assertTrue(count($r) == 4, "wrong number of return values");
599
        }
600
        $this->assertTrue($r[0]->faultCode() == 0, "fault from good1");
601 View Code Duplication
        if (!$r[0]->faultCode()) {
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...
602
            $val = $r[0]->value();
603
            $this->assertTrue(
604
                is_string($val), "good1 did not return string");
605
        }
606
        $this->assertTrue($r[1]->faultCode() != 0, "no fault from bad");
607
        $this->assertTrue($r[2]->faultCode() != 0, "no fault from recursive system.multicall");
608
        $this->assertTrue($r[3]->faultCode() == 0, "fault from good2");
609 View Code Duplication
        if (!$r[3]->faultCode()) {
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...
610
            $val = $r[3]->value();
611
            $this->assertTrue(is_array($val), "good2 did not return array");
612
        }
613
        //$this->client->return_type = 'xmlrpcvals';
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
614
    }
615
616 View Code Duplication
    public function testCatchWarnings()
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...
617
    {
618
        $m = new xmlrpcmsg('tests.generatePHPWarning', array(
619
            new xmlrpcval('whatever', 'string'),
620
        ));
621
        $v = $this->send($m);
622
        if ($v) {
623
            $this->assertEquals(true, $v->scalarval());
0 ignored issues
show
Bug introduced by
The method scalarval() does not seem to exist on object<PhpXmlRpc\Response>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
624
        }
625
    }
626
627
    public function testCatchExceptions()
0 ignored issues
show
Coding Style introduced by
testCatchExceptions uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
628
    {
629
        $m = new xmlrpcmsg('tests.raiseException', array(
630
            new xmlrpcval('whatever', 'string'),
631
        ));
632
        $v = $this->send($m, $GLOBALS['xmlrpcerr']['server_error']);
0 ignored issues
show
Unused Code introduced by
$v is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
633
        $this->addQueryParams(array('EXCEPTION_HANDLING' => 1));
634
        $v = $this->send($m, 1); // the error code of the expected exception
0 ignored issues
show
Unused Code introduced by
$v is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
635
        $this->addQueryParams(array('EXCEPTION_HANDLING' => 2));
636
        // depending on whether display_errors is ON or OFF on the server, we will get back a different error here,
637
        // as php will generate an http status code of either 200 or 500...
638
        $v = $this->send($m, array($GLOBALS['xmlrpcerr']['invalid_return'], $GLOBALS['xmlrpcerr']['http_error']));
0 ignored issues
show
Documentation introduced by
array($GLOBALS['xmlrpcer...rpcerr']['http_error']) is of type array<integer,?,{"0":"?","1":"?"}>, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Unused Code introduced by
$v is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
639
    }
640
641
    public function testZeroParams()
642
    {
643
        $m = new xmlrpcmsg('system.listMethods');
644
        $v = $this->send($m);
0 ignored issues
show
Unused Code introduced by
$v is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
645
    }
646
647
    public function testNullParams()
0 ignored issues
show
Coding Style introduced by
testNullParams uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
648
    {
649
        $m = new xmlrpcmsg('tests.getStateName.12', array(
650
            new xmlrpcval('whatever', 'null'),
651
            new xmlrpcval(23, 'int'),
652
        ));
653
        $v = $this->send($m);
654
        if ($v) {
655
            $this->assertEquals('Michigan', $v->scalarval());
0 ignored issues
show
Bug introduced by
The method scalarval() does not seem to exist on object<PhpXmlRpc\Response>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
656
        }
657
        $m = new xmlrpcmsg('tests.getStateName.12', array(
658
            new xmlrpcval(23, 'int'),
659
            new xmlrpcval('whatever', 'null'),
660
        ));
661
        $v = $this->send($m);
662
        if ($v) {
663
            $this->assertEquals('Michigan', $v->scalarval());
0 ignored issues
show
Bug introduced by
The method scalarval() does not seem to exist on object<PhpXmlRpc\Response>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
664
        }
665
        $m = new xmlrpcmsg('tests.getStateName.12', array(
666
            new xmlrpcval(23, 'int')
667
        ));
668
        $v = $this->send($m, array($GLOBALS['xmlrpcerr']['incorrect_params']));
0 ignored issues
show
Documentation introduced by
array($GLOBALS['xmlrpcerr']['incorrect_params']) is of type array<integer,?,{"0":"?"}>, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Unused Code introduced by
$v is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
669
    }
670
671
    public function testCodeInjectionServerSide()
672
    {
673
        $m = new xmlrpcmsg('system.MethodHelp');
674
        $m->payload = "<?xml version=\"1.0\"?><methodCall><methodName>validator1.echoStructTest</methodName><params><param><value><struct><member><name>','')); echo('gotcha!'); die(); //</name></member></struct></value></param></params></methodCall>";
675
        $v = $this->send($m);
676
        if ($v) {
677
            $this->assertEquals(0, $v->structsize());
0 ignored issues
show
Bug introduced by
The method structsize() does not seem to exist on object<PhpXmlRpc\Response>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
678
        }
679
    }
680
681
    public function testServerWrappedFunction()
0 ignored issues
show
Coding Style introduced by
testServerWrappedFunction uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
682
    {
683
        $m = new xmlrpcmsg('tests.getStateName.2', array(
684
            new xmlrpcval(23, 'int'),
685
        ));
686
        $v = $this->send($m);
687
        $this->assertEquals('Michigan', $v->scalarval());
0 ignored issues
show
Bug introduced by
The method scalarval() does not seem to exist on object<PhpXmlRpc\Response>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
688
689
        // this generates an exception in the function which was wrapped, which is by default wrapped in a known error response
690
        $m = new xmlrpcmsg('tests.getStateName.2', array(
691
            new xmlrpcval(0, 'int'),
692
        ));
693
        $v = $this->send($m, $GLOBALS['xmlrpcerr']['server_error']);
0 ignored issues
show
Unused Code introduced by
$v is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
694
695
        // check if the generated function dispatch map is fine, by checking if the server registered it
696
        $m = new xmlrpcmsg('system.methodSignature', array(
697
            new xmlrpcval('tests.getStateName.2'),
698
        ));
699
        $v = $this->send($m);
700
        $encoder = new \PhpXmlRpc\Encoder();
701
        $this->assertEquals(array(array('string', 'int')), $encoder->decode($v));
702
    }
703
704
    public function testServerWrappedFunctionAsSource()
0 ignored issues
show
Coding Style introduced by
testServerWrappedFunctionAsSource uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
705
    {
706
        $m = new xmlrpcmsg('tests.getStateName.6', array(
707
            new xmlrpcval(23, 'int'),
708
        ));
709
        $v = $this->send($m);
710
        $this->assertEquals('Michigan', $v->scalarval());
0 ignored issues
show
Bug introduced by
The method scalarval() does not seem to exist on object<PhpXmlRpc\Response>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
711
712
        // this generates an exception in the function which was wrapped, which is by default wrapped in a known error response
713
        $m = new xmlrpcmsg('tests.getStateName.6', array(
714
            new xmlrpcval(0, 'int'),
715
        ));
716
        $v = $this->send($m, $GLOBALS['xmlrpcerr']['server_error']);
0 ignored issues
show
Unused Code introduced by
$v is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
717
    }
718
719
    public function testServerWrappedObjectMethods()
720
    {
721
        $m = new xmlrpcmsg('tests.getStateName.3', array(
722
            new xmlrpcval(23, 'int'),
723
        ));
724
        $v = $this->send($m);
725
        $this->assertEquals('Michigan', $v->scalarval());
0 ignored issues
show
Bug introduced by
The method scalarval() does not seem to exist on object<PhpXmlRpc\Response>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
726
727
        $m = new xmlrpcmsg('tests.getStateName.4', array(
728
            new xmlrpcval(23, 'int'),
729
        ));
730
        $v = $this->send($m);
731
        $this->assertEquals('Michigan', $v->scalarval());
0 ignored issues
show
Bug introduced by
The method scalarval() does not seem to exist on object<PhpXmlRpc\Response>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
732
733
        $m = new xmlrpcmsg('tests.getStateName.5', array(
734
            new xmlrpcval(23, 'int'),
735
        ));
736
        $v = $this->send($m);
737
        $this->assertEquals('Michigan', $v->scalarval());
0 ignored issues
show
Bug introduced by
The method scalarval() does not seem to exist on object<PhpXmlRpc\Response>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
738
739
        $m = new xmlrpcmsg('tests.getStateName.7', array(
740
            new xmlrpcval(23, 'int'),
741
        ));
742
        $v = $this->send($m);
743
        $this->assertEquals('Michigan', $v->scalarval());
0 ignored issues
show
Bug introduced by
The method scalarval() does not seem to exist on object<PhpXmlRpc\Response>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
744
745
        $m = new xmlrpcmsg('tests.getStateName.8', array(
746
            new xmlrpcval(23, 'int'),
747
        ));
748
        $v = $this->send($m);
749
        $this->assertEquals('Michigan', $v->scalarval());
0 ignored issues
show
Bug introduced by
The method scalarval() does not seem to exist on object<PhpXmlRpc\Response>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
750
751
        $m = new xmlrpcmsg('tests.getStateName.9', array(
752
            new xmlrpcval(23, 'int'),
753
        ));
754
        $v = $this->send($m);
755
        $this->assertEquals('Michigan', $v->scalarval());
0 ignored issues
show
Bug introduced by
The method scalarval() does not seem to exist on object<PhpXmlRpc\Response>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
756
    }
757
758
    public function testServerWrappedObjectMethodsAsSource()
759
    {
760
        $m = new xmlrpcmsg('tests.getStateName.7', array(
761
            new xmlrpcval(23, 'int'),
762
        ));
763
        $v = $this->send($m);
764
        $this->assertEquals('Michigan', $v->scalarval());
0 ignored issues
show
Bug introduced by
The method scalarval() does not seem to exist on object<PhpXmlRpc\Response>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
765
766
        $m = new xmlrpcmsg('tests.getStateName.8', array(
767
            new xmlrpcval(23, 'int'),
768
        ));
769
        $v = $this->send($m);
770
        $this->assertEquals('Michigan', $v->scalarval());
0 ignored issues
show
Bug introduced by
The method scalarval() does not seem to exist on object<PhpXmlRpc\Response>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
771
772
        $m = new xmlrpcmsg('tests.getStateName.9', array(
773
            new xmlrpcval(23, 'int'),
774
        ));
775
        $v = $this->send($m);
776
        $this->assertEquals('Michigan', $v->scalarval());
0 ignored issues
show
Bug introduced by
The method scalarval() does not seem to exist on object<PhpXmlRpc\Response>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
777
    }
778
779 View Code Duplication
    public function testServerClosure()
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...
780
    {
781
        $m = new xmlrpcmsg('tests.getStateName.10', array(
782
            new xmlrpcval(23, 'int'),
783
        ));
784
        $v = $this->send($m);
785
        $this->assertEquals('Michigan', $v->scalarval());
0 ignored issues
show
Bug introduced by
The method scalarval() does not seem to exist on object<PhpXmlRpc\Response>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
786
    }
787
788 View Code Duplication
    public function testServerWrappedClosure()
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...
789
    {
790
        $m = new xmlrpcmsg('tests.getStateName.11', array(
791
            new xmlrpcval(23, 'int'),
792
        ));
793
        $v = $this->send($m);
794
        $this->assertEquals('Michigan', $v->scalarval());
0 ignored issues
show
Bug introduced by
The method scalarval() does not seem to exist on object<PhpXmlRpc\Response>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
795
    }
796
797 View Code Duplication
    public function testServerWrappedClass()
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...
798
    {
799
        $m = new xmlrpcmsg('tests.xmlrpcServerMethodsContainer.findState', array(
800
            new xmlrpcval(23, 'int'),
801
        ));
802
        $v = $this->send($m);
803
        $this->assertEquals('Michigan', $v->scalarval());
0 ignored issues
show
Bug introduced by
The method scalarval() does not seem to exist on object<PhpXmlRpc\Response>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
804
    }
805
806
    public function testWrappedMethod()
807
    {
808
        // make a 'deep client copy' as the original one might have many properties set
809
        $func = wrap_xmlrpc_method($this->client, 'examples.getStateName', array('simple_client_copy' => 0));
0 ignored issues
show
Documentation introduced by
array('simple_client_copy' => 0) is of type array<string,integer,{"s...lient_copy":"integer"}>, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
810
        if ($func == false) {
811
            $this->fail('Registration of examples.getStateName failed');
812
        } else {
813
            $v = $func(23);
814
            // work around bug in current (or old?) version of phpunit when reporting the error
815
            /*if (is_object($v)) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
816
                $v = var_export($v, true);
817
            }*/
818
            $this->assertEquals('Michigan', $v);
819
        }
820
    }
821
822
    public function testWrappedMethodAsSource()
823
    {
824
        // make a 'deep client copy' as the original one might have many properties set
825
        $func = wrap_xmlrpc_method($this->client, 'examples.getStateName', array('simple_client_copy' => 0, 'return_source' => true));
0 ignored issues
show
Documentation introduced by
array('simple_client_cop...return_source' => true) is of type array<string,integer|boo...urn_source":"boolean"}>, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
826
        if ($func == false) {
827
            $this->fail('Registration of examples.getStateName failed');
828
        } else {
829
            eval($func['source']);
0 ignored issues
show
Coding Style introduced by
It is generally not recommended to use eval unless absolutely required.

On one hand, eval might be exploited by malicious users if they somehow manage to inject dynamic content. On the other hand, with the emergence of faster PHP runtimes like the HHVM, eval prevents some optimization that they perform.

Loading history...
830
            $func = $func['function'];
831
            $v = $func(23);
832
            // work around bug in current (or old?) version of phpunit when reporting the error
833
            /*if (is_object($v)) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
834
                $v = var_export($v, true);
835
            }*/
836
            $this->assertEquals('Michigan', $v);
837
        }
838
    }
839
840
    public function testWrappedClass()
841
    {
842
        // make a 'deep client copy' as the original one might have many properties set
843
        // also for speed only wrap one method of the whole server
844
        $class = wrap_xmlrpc_server($this->client, array('simple_client_copy' => 0, 'method_filter' => '/examples\.getStateName/' ));
845
        if ($class == '') {
846
            $this->fail('Registration of remote server failed');
847
        } else {
848
            $obj = new $class();
849
            $v = $obj->examples_getStateName(23);
850
            // work around bug in current (or old?) version of phpunit when reporting the error
851
            /*if (is_object($v)) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
852
                $v = var_export($v, true);
853
            }*/
854
            $this->assertEquals('Michigan', $v);
855
        }
856
    }
857
858
    public function testTransferOfObjectViaWrapping()
859
    {
860
        // make a 'deep client copy' as the original one might have many properties set
861
        $func = wrap_xmlrpc_method($this->client, 'tests.returnPhpObject', array('simple_client_copy' => true,
0 ignored issues
show
Documentation introduced by
array('simple_client_cop...code_php_objs' => true) is of type array<string,boolean,{"s...e_php_objs":"boolean"}>, but the function expects a integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
862
            'decode_php_objs' => true));
863
        if ($func == false) {
864
            $this->fail('Registration of tests.returnPhpObject failed');
865
        } else {
866
            $v = $func();
867
            $obj = new stdClass();
868
            $obj->hello = 'world';
869
            $this->assertEquals($obj, $v);
870
        }
871
    }
872
873
    public function testGetCookies()
874
    {
875
        // let server set to us some cookies we tell it
876
        $cookies = array(
877
            //'c1' => array(),
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
878
            'c2' => array('value' => 'c2'),
879
            'c3' => array('value' => 'c3', 'expires' => time() + 60 * 60 * 24 * 30),
880
            'c4' => array('value' => 'c4', 'expires' => time() + 60 * 60 * 24 * 30, 'path' => '/'),
881
            'c5' => array('value' => 'c5', 'expires' => time() + 60 * 60 * 24 * 30, 'path' => '/', 'domain' => 'localhost'),
882
        );
883
        $cookiesval = php_xmlrpc_encode($cookies);
884
        $m = new xmlrpcmsg('examples.setcookies', array($cookiesval));
885
        $r = $this->send($m, 0, true);
886
        if ($r) {
887
            $v = $r->value();
888
            $this->assertEquals(1, $v->scalarval());
889
            // now check if we decoded the cookies as we had set them
890
            $rcookies = $r->cookies();
891
            // remove extra cookies which might have been set by proxies
892
            foreach ($rcookies as $c => $v) {
893
                if (!in_array($c, array('c2', 'c3', 'c4', 'c5'))) {
894
                    unset($rcookies[$c]);
895
                }
896
                // Seems like we get this when using php-fpm and php 5.5+ ...
897
                if (isset($rcookies[$c]['Max-Age'])) {
898
                    unset($rcookies[$c]['Max-Age']);
899
                }
900
            }
901
            foreach ($cookies as $c => $v) {
902
                // format for date string in cookies: 'Mon, 31 Oct 2005 13:50:56 GMT'
903
                // but PHP versions differ on that, some use 'Mon, 31-Oct-2005 13:50:56 GMT'...
904
                if (isset($v['expires'])) {
905
                    if (isset($rcookies[$c]['expires']) && strpos($rcookies[$c]['expires'], '-')) {
906
                        $cookies[$c]['expires'] = gmdate('D, d\-M\-Y H:i:s \G\M\T', $cookies[$c]['expires']);
907
                    } else {
908
                        $cookies[$c]['expires'] = gmdate('D, d M Y H:i:s \G\M\T', $cookies[$c]['expires']);
909
                    }
910
                }
911
            }
912
913
            $this->assertEquals($cookies, $rcookies);
914
        }
915
    }
916
917
    public function testSetCookies()
918
    {
919
        // let server set to us some cookies we tell it
920
        $cookies = array(
921
            'c0' => null,
922
            'c1' => 1,
923
            'c2' => '2 3',
924
            'c3' => '!@#$%^&*()_+|}{":?><,./\';[]\\=-',
925
        );
926
        $m = new xmlrpcmsg('examples.getcookies', array());
927
        foreach ($cookies as $cookie => $val) {
928
            $this->client->setCookie($cookie, $val);
929
            $cookies[$cookie] = (string)$cookies[$cookie];
930
        }
931
        $r = $this->client->send($m, $this->timeout, $this->method);
932
        $this->assertEquals(0, $r->faultCode(), 'Error ' . $r->faultCode() . ' connecting to server: ' . $r->faultString());
933
        if (!$r->faultCode()) {
934
            $v = $r->value();
935
            $v = php_xmlrpc_decode($v);
936
937
            // take care for the extra cookie used for coverage collection
938
            if (isset($v['PHPUNIT_SELENIUM_TEST_ID'])) {
939
                unset($v['PHPUNIT_SELENIUM_TEST_ID']);
940
            }
941
942
            // on IIS and Apache getallheaders returns something slightly different...
943
            $this->assertEquals($cookies, $v);
944
        }
945
    }
946
947
    public function testServerComments()
948
    {
949
        $m = new xmlrpcmsg('tests.xmlrpcServerMethodsContainer.debugMessageGenerator', array(
950
            new xmlrpcval('hello world', 'string'),
951
        ));
952
        $r = $this->send($m, 0, true);
953
        $this->assertContains('hello world', $r->raw_data);
954
    }
955
956
    public function testSendTwiceSameMsg()
957
    {
958
        $m = new xmlrpcmsg('examples.stringecho', array(
959
            new xmlrpcval('hello world', 'string'),
960
        ));
961
        $v1 = $this->send($m);
962
        $v2 = $this->send($m);
963
        if ($v1 && $v2) {
964
            $this->assertEquals($v1, $v2);
965
        }
966
    }
967
}
968