Completed
Pull Request — master (#53)
by
unknown
09:15
created

LocalhostTest   F

Complexity

Total Complexity 113

Size/Duplication

Total Lines 944
Duplicated Lines 14.41 %

Coupling/Cohesion

Components 1
Dependencies 11

Importance

Changes 0
Metric Value
dl 136
loc 944
rs 3.9999
c 0
b 0
f 0
wmc 113
lcom 1
cbo 11

43 Methods

Rating   Name   Duplication   Size   Complexity  
B fail() 0 16 5
B run() 27 27 3
A setUp() 0 20 3
A tearDown() 11 11 4
B send() 0 26 6
B testString() 5 27 3
A testLatin1String() 0 12 2
B testExoticCharsetsRequests() 0 27 2
B testExoticCharsetsRequests2() 0 26 2
B testExoticCharsetsRequests3() 0 24 2
A testUtf8Method() 0 12 2
A testAddingDoubles() 0 15 2
A testAdding() 11 11 2
A testInvalidNumber() 13 13 2
B testBoolean() 0 27 4
A testBase64() 5 23 3
A testDateTime() 0 15 3
A testCountEntities() 0 18 3
A _multicall_msg() 0 7 1
A testServerMulticall() 0 56 4
B testClientMulticall1() 11 42 5
B testClientMulticall2() 10 36 5
B testClientMulticall3() 9 36 4
A testCatchWarnings() 10 10 2
A testCatchExceptions() 0 13 1
A testZeroParams() 0 5 1
A testNullParams() 0 23 3
A testCodeInjectionServerSide() 0 9 2
A testServerWrappedFunction() 0 22 1
A testServerWrappedFunctionAsSource() 0 14 1
B testServerWrappedObjectMethods() 0 38 1
A testServerWrappedObjectMethodsAsSource() 0 20 1
A testServerClosure() 8 8 1
A testServerWrappedClosure() 8 8 1
A testServerWrappedClass() 8 8 1
A testWrappedMethod() 0 15 2
A testWrappedMethodAsSource() 0 17 2
A testWrappedClass() 0 17 2
A testTransferOfObjectViaWrapping() 0 14 2
D testGetCookies() 0 43 9
B testSetCookies() 0 29 4
A testServerComments() 0 8 1
A testSendTwiceSameMsg() 0 11 3

How to fix   Duplicated Code    Complexity   

Duplicated Code

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

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like LocalhostTest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use LocalhostTest, and based on these observations, apply Extract Interface, too.

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|void
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;
145
        }
146
    }
147
148
    public function testString()
149
    {
150
        $sendString = "here are 3 \"entities\": < > & " .
151
            "and here's a dollar sign: \$pretendvarname and a backslash too: " . chr(92) .
152
            " - isn't that great? \\\"hackery\\\" at it's best " .
153
            " also don't want to miss out on \$item[0]. " .
154
            "The real weird stuff follows: CRLF here" . chr(13) . chr(10) .
155
            "a simple CR here" . chr(13) .
156
            "a simple LF here" . chr(10) .
157
            "and then LFCR" . chr(10) . chr(13) .
158
            "last but not least weird names: G" . chr(252) . "nter, El" . chr(232) . "ne, and an xml comment closing tag: -->";
159
        $m = new xmlrpcmsg('examples.stringecho', array(
160
            new xmlrpcval($sendString, 'string'),
161
        ));
162
        $v = $this->send($m);
163
        if ($v) {
164
            // when sending/receiving non-US-ASCII encoded strings, XML says cr-lf can be normalized.
165
            // so we relax our tests...
166
            $l1 = strlen($sendString);
167
            $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...
168 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...
169
                $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...
170
            } else {
171
                $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...
172
            }
173
        }
174
    }
175
176
    public function testLatin1String()
177
    {
178
        $sendString =
179
            "last but not least weird names: G" . chr(252) . "nter, El" . chr(232) . "ne";
180
        $x = '<?xml version="1.0" encoding="ISO-8859-1"?><methodCall><methodName>examples.stringecho</methodName><params><param><value>'.
181
            $sendString.
182
            '</value></param></params></methodCall>';
183
        $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...
184
        if ($v) {
185
            $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...
186
        }
187
    }
188
189
    public function testExoticCharsetsRequests()
190
    {
191
        // note that we should disable this call also when mbstring is missing server-side
192
        if (!function_exists('mb_convert_encoding')) {
193
            $this->markTestSkipped('Miss mbstring extension to test exotic charsets');
194
            return;
195
        }
196
        $sendString = 'κόσμε'; // Greek word 'kosme'. NB: NOT a valid ISO8859 string!
197
        $str = '<?xml version="1.0" encoding="_ENC_"?>
198
<methodCall>
199
    <methodName>examples.stringecho</methodName>
200
    <params>
201
        <param>
202
        <value><string>'.$sendString.'</string></value>
203
        </param>
204
    </params>
205
</methodCall>';
206
207
        PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding = 'UTF-8';
208
        // we have to set the encoding declaration either in the http header or xml prolog, as mb_detect_encoding
209
        // (used on the server side) will fail recognizing these 2 charsets
210
        $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...
211
        $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...
212
        $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...
213
        $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...
214
        PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding = 'ISO-8859-1';
215
    }
216
217
    public function testExoticCharsetsRequests2()
218
    {
219
        // note that we should disable this call also when mbstring is missing server-side
220
        if (!function_exists('mb_convert_encoding')) {
221
            $this->markTestSkipped('Miss mbstring extension to test exotic charsets');
222
            return;
223
        }
224
        $sendString = '安室奈美恵'; // No idea what this means :-) NB: NOT a valid ISO8859 string!
225
        $str = '<?xml version="1.0"?>
226
<methodCall>
227
    <methodName>examples.stringecho</methodName>
228
    <params>
229
        <param>
230
        <value><string>'.$sendString.'</string></value>
231
        </param>
232
    </params>
233
</methodCall>';
234
235
        PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding = 'UTF-8';
236
        // no encoding declaration either in the http header or xml prolog, let mb_detect_encoding
237
        // (used on the server side) sort it out
238
        $this->client->path = $this->args['URI'].'?DETECT_ENCODINGS[]=EUC-JP&DETECT_ENCODINGS[]=UTF-8';
239
        $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...
240
        $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...
241
        PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding = 'ISO-8859-1';
242
    }
243
244
    public function testExoticCharsetsRequests3()
245
    {
246
        // note that we should disable this call also when mbstring is missing server-side
247
        if (!function_exists('mb_convert_encoding')) {
248
            $this->markTestSkipped('Miss mbstring extension to test exotic charsets');
249
            return;
250
        }
251
        $sendString = utf8_decode('élève');
252
        $str = '<?xml version="1.0"?>
253
<methodCall>
254
    <methodName>examples.stringecho</methodName>
255
    <params>
256
        <param>
257
        <value><string>'.$sendString.'</string></value>
258
        </param>
259
    </params>
260
</methodCall>';
261
262
        // no encoding declaration either in the http header or xml prolog, let mb_detect_encoding
263
        // (used on the server side) sort it out
264
        $this->client->path = $this->args['URI'].'?DETECT_ENCODINGS[]=ISO-8859-1&DETECT_ENCODINGS[]=UTF-8';
265
        $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...
266
        $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...
267
    }
268
269
    /*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...
270
    {
271
        $f = new xmlrpcmsg("tests.iso88591methodname." . chr(224) . chr(252) . chr(232), array(
272
            new xmlrpcval('hello')
273
        ));
274
        $v = $this->send($f);
275
        if ($v) {
276
            $this->assertEquals('hello', $v->scalarval());
277
        }
278
    }*/
279
280
    public function testUtf8Method()
281
    {
282
        PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding = 'UTF-8';
283
        $m = new xmlrpcmsg("tests.utf8methodname." . 'κόσμε', array(
284
            new xmlrpcval('hello')
285
        ));
286
        $v = $this->send($m);
287
        if ($v) {
288
            $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...
289
        }
290
        PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding = 'ISO-8859-1';
291
    }
292
293
    public function testAddingDoubles()
294
    {
295
        // note that rounding errors mean we
296
        // keep precision to sensible levels here ;-)
297
        $a = 12.13;
298
        $b = -23.98;
299
        $m = new xmlrpcmsg('examples.addtwodouble', array(
300
            new xmlrpcval($a, 'double'),
301
            new xmlrpcval($b, 'double'),
302
        ));
303
        $v = $this->send($m);
304
        if ($v) {
305
            $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...
306
        }
307
    }
308
309 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...
310
    {
311
        $m = new xmlrpcmsg('examples.addtwo', array(
312
            new xmlrpcval(12, 'int'),
313
            new xmlrpcval(-23, 'int'),
314
        ));
315
        $v = $this->send($m);
316
        if ($v) {
317
            $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...
318
        }
319
    }
320
321 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...
322
    {
323
        $m = new xmlrpcmsg('examples.addtwo', array(
324
            new xmlrpcval('fred', 'int'),
325
            new xmlrpcval("\"; exec('ls')", 'int'),
326
        ));
327
        $v = $this->send($m);
328
        /// @todo a fault condition should be generated here
329
        /// by the server, which we pick up on
330
        if ($v) {
331
            $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...
332
        }
333
    }
334
335
    public function testBoolean()
336
    {
337
        $m = new xmlrpcmsg('examples.invertBooleans', array(
338
            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...
339
                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...
340
                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...
341
                new xmlrpcval(1, 'boolean'),
342
                new xmlrpcval(0, 'boolean')
343
            ),
344
                'array'
345
            ),));
346
        $answer = '0101';
347
        $v = $this->send($m);
348
        if ($v) {
349
            $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...
350
            $got = '';
351
            for ($i = 0; $i < $sz; $i++) {
352
                $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...
353
                if ($b->scalarval()) {
354
                    $got .= '1';
355
                } else {
356
                    $got .= '0';
357
                }
358
            }
359
            $this->assertEquals($answer, $got);
360
        }
361
    }
362
363
    public function testBase64()
364
    {
365
        $sendString = 'Mary had a little lamb,
366
Whose fleece was white as snow,
367
And everywhere that Mary went
368
the lamb was sure to go.
369
370
Mary had a little lamb
371
She tied it to a pylon
372
Ten thousand volts went down its back
373
And turned it into nylon';
374
        $m = new xmlrpcmsg('examples.decode64', array(
375
            new xmlrpcval($sendString, 'base64'),
376
        ));
377
        $v = $this->send($m);
378
        if ($v) {
379 View Code Duplication
            if (strlen($sendString) == strlen($v->scalarval())) {
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...
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...
380
                $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...
381
            } else {
382
                $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...
383
            }
384
        }
385
    }
386
387
    public function testDateTime()
388
    {
389
        $time = time();
390
        $t1 = new xmlrpcval($time, 'dateTime.iso8601');
391
        $t2 = new xmlrpcval(iso8601_encode($time), 'dateTime.iso8601');
392
        $this->assertEquals($t1->serialize(), $t2->serialize());
393
        if (class_exists('DateTime')) {
394
            $datetime = new DateTime();
395
            // skip this test for php 5.2. It is a bit harder there to build a DateTime from unix timestamp with proper TZ info
396
            if (is_callable(array($datetime, 'setTimestamp'))) {
397
                $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...
398
                $this->assertEquals($t1->serialize(), $t3->serialize());
399
            }
400
        }
401
    }
402
403
    public function testCountEntities()
404
    {
405
        $sendString = "h'fd>onc>>l>>rw&bpu>q>e<v&gxs<ytjzkami<";
406
        $m = new xmlrpcmsg('validator1.countTheEntities', array(
407
            new xmlrpcval($sendString, 'string'),
408
        ));
409
        $v = $this->send($m);
410
        if ($v) {
411
            $got = '';
412
            $expected = '37210';
413
            $expect_array = array('ctLeftAngleBrackets', 'ctRightAngleBrackets', 'ctAmpersands', 'ctApostrophes', 'ctQuotes');
414
            while (list(, $val) = each($expect_array)) {
415
                $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...
416
                $got .= $b->me['int'];
417
            }
418
            $this->assertEquals($expected, $got);
419
        }
420
    }
421
422
    public function _multicall_msg($method, $params)
423
    {
424
        $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...
425
        $struct['params'] = new xmlrpcval($params, 'array');
426
427
        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...
428
    }
429
430
    public function testServerMulticall()
431
    {
432
        // We manually construct a system.multicall() call to ensure
433
        // that the server supports it.
434
435
        // NB: This test will NOT pass if server does not support system.multicall.
436
437
        // Based on http://xmlrpc-c.sourceforge.net/hacks/test_multicall.py
438
        $good1 = $this->_multicall_msg(
439
            'system.methodHelp',
440
            array(php_xmlrpc_encode('system.listMethods')));
441
        $bad = $this->_multicall_msg(
442
            'test.nosuch',
443
            array(php_xmlrpc_encode(1), php_xmlrpc_encode(2)));
444
        $recursive = $this->_multicall_msg(
445
            'system.multicall',
446
            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...
447
        $good2 = $this->_multicall_msg(
448
            'system.methodSignature',
449
            array(php_xmlrpc_encode('system.listMethods')));
450
        $arg = new xmlrpcval(
451
            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...
452
            'array'
453
        );
454
455
        $m = new xmlrpcmsg('system.multicall', array($arg));
456
        $v = $this->send($m);
457
        if ($v) {
458
            //$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...
459
            $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...
460
461
            $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...
462
            $this->assertTrue(
463
                $r1->kindOf() == 'array' && $r1->arraysize() == 1,
464
                "did not get array of size 1 from good1"
465
            );
466
467
            $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...
468
            $this->assertTrue(
469
                $r2->kindOf() == 'struct',
470
                "no fault from bad"
471
            );
472
473
            $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...
474
            $this->assertTrue(
475
                $r3->kindOf() == 'struct',
476
                "recursive system.multicall did not fail"
477
            );
478
479
            $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...
480
            $this->assertTrue(
481
                $r4->kindOf() == 'array' && $r4->arraysize() == 1,
482
                "did not get array of size 1 from good2"
483
            );
484
        }
485
    }
486
487
    public function testClientMulticall1()
488
    {
489
        // NB: This test will NOT pass if server does not support system.multicall.
490
491
        $this->client->no_multicall = false;
492
493
        $good1 = new xmlrpcmsg('system.methodHelp',
494
            array(php_xmlrpc_encode('system.listMethods')));
495
        $bad = new xmlrpcmsg('test.nosuch',
496
            array(php_xmlrpc_encode(1), php_xmlrpc_encode(2)));
497
        $recursive = new xmlrpcmsg('system.multicall',
498
            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...
499
        $good2 = new xmlrpcmsg('system.methodSignature',
500
            array(php_xmlrpc_encode('system.listMethods'))
501
        );
502
503
        $r = $this->send(array($good1, $bad, $recursive, $good2));
504
        if ($r) {
505
            $this->assertTrue(count($r) == 4, "wrong number of return values");
506
        }
507
508
        $this->assertTrue($r[0]->faultCode() == 0, "fault from good1");
509 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...
510
            $val = $r[0]->value();
511
            $this->assertTrue(
512
                $val->kindOf() == 'scalar' && $val->scalartyp() == 'string',
513
                "good1 did not return string"
514
            );
515
        }
516
        $this->assertTrue($r[1]->faultCode() != 0, "no fault from bad");
517
        $this->assertTrue($r[2]->faultCode() != 0, "no fault from recursive system.multicall");
518
        $this->assertTrue($r[3]->faultCode() == 0, "fault from good2");
519 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...
520
            $val = $r[3]->value();
521
            $this->assertTrue($val->kindOf() == 'array', "good2 did not return array");
522
        }
523
        // This is the only assert in this test which should fail
524
        // if the test server does not support system.multicall.
525
        $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...
526
            "server does not support system.multicall"
527
        );
528
    }
529
530
    public function testClientMulticall2()
531
    {
532
        // NB: This test will NOT pass if server does not support system.multicall.
533
534
        $this->client->no_multicall = true;
535
536
        $good1 = new xmlrpcmsg('system.methodHelp',
537
            array(php_xmlrpc_encode('system.listMethods')));
538
        $bad = new xmlrpcmsg('test.nosuch',
539
            array(php_xmlrpc_encode(1), php_xmlrpc_encode(2)));
540
        $recursive = new xmlrpcmsg('system.multicall',
541
            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...
542
        $good2 = new xmlrpcmsg('system.methodSignature',
543
            array(php_xmlrpc_encode('system.listMethods'))
544
        );
545
546
        $r = $this->send(array($good1, $bad, $recursive, $good2));
547
        if ($r) {
548
            $this->assertTrue(count($r) == 4, "wrong number of return values");
549
        }
550
551
        $this->assertTrue($r[0]->faultCode() == 0, "fault from good1");
552 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...
553
            $val = $r[0]->value();
554
            $this->assertTrue(
555
                $val->kindOf() == 'scalar' && $val->scalartyp() == 'string',
556
                "good1 did not return string");
557
        }
558
        $this->assertTrue($r[1]->faultCode() != 0, "no fault from bad");
559
        $this->assertTrue($r[2]->faultCode() == 0, "fault from (non recursive) system.multicall");
560
        $this->assertTrue($r[3]->faultCode() == 0, "fault from good2");
561 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...
562
            $val = $r[3]->value();
563
            $this->assertTrue($val->kindOf() == 'array', "good2 did not return array");
564
        }
565
    }
566
567
    public function testClientMulticall3()
568
    {
569
        // NB: This test will NOT pass if server does not support system.multicall.
570
571
        $this->client->return_type = 'phpvals';
572
        $this->client->no_multicall = false;
573
574
        $good1 = new xmlrpcmsg('system.methodHelp',
575
            array(php_xmlrpc_encode('system.listMethods')));
576
        $bad = new xmlrpcmsg('test.nosuch',
577
            array(php_xmlrpc_encode(1), php_xmlrpc_encode(2)));
578
        $recursive = new xmlrpcmsg('system.multicall',
579
            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...
580
        $good2 = new xmlrpcmsg('system.methodSignature',
581
            array(php_xmlrpc_encode('system.listMethods'))
582
        );
583
584
        $r = $this->send(array($good1, $bad, $recursive, $good2));
585
        if ($r) {
586
            $this->assertTrue(count($r) == 4, "wrong number of return values");
587
        }
588
        $this->assertTrue($r[0]->faultCode() == 0, "fault from good1");
589 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...
590
            $val = $r[0]->value();
591
            $this->assertTrue(
592
                is_string($val), "good1 did not return string");
593
        }
594
        $this->assertTrue($r[1]->faultCode() != 0, "no fault from bad");
595
        $this->assertTrue($r[2]->faultCode() != 0, "no fault from recursive system.multicall");
596
        $this->assertTrue($r[3]->faultCode() == 0, "fault from good2");
597 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...
598
            $val = $r[3]->value();
599
            $this->assertTrue(is_array($val), "good2 did not return array");
600
        }
601
        $this->client->return_type = 'xmlrpcvals';
602
    }
603
604 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...
605
    {
606
        $m = new xmlrpcmsg('tests.generatePHPWarning', array(
607
            new xmlrpcval('whatever', 'string'),
608
        ));
609
        $v = $this->send($m);
610
        if ($v) {
611
            $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...
612
        }
613
    }
614
615
    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...
616
    {
617
        $m = new xmlrpcmsg('tests.raiseException', array(
618
            new xmlrpcval('whatever', 'string'),
619
        ));
620
        $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...
621
        $this->client->path = $this->args['URI'] . '?EXCEPTION_HANDLING=1';
622
        $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...
623
        $this->client->path = $this->args['URI'] . '?EXCEPTION_HANDLING=2';
624
        // depending on whether display_errors is ON or OFF on the server, we will get back a different error here,
625
        // as php will generate an http status code of either 200 or 500...
626
        $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...
627
    }
628
629
    public function testZeroParams()
630
    {
631
        $m = new xmlrpcmsg('system.listMethods');
632
        $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...
633
    }
634
635
    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...
636
    {
637
        $m = new xmlrpcmsg('tests.getStateName.12', array(
638
            new xmlrpcval('whatever', 'null'),
639
            new xmlrpcval(23, 'int'),
640
        ));
641
        $v = $this->send($m);
642
        if ($v) {
643
            $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...
644
        }
645
        $m = new xmlrpcmsg('tests.getStateName.12', array(
646
            new xmlrpcval(23, 'int'),
647
            new xmlrpcval('whatever', 'null'),
648
        ));
649
        $v = $this->send($m);
650
        if ($v) {
651
            $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...
652
        }
653
        $m = new xmlrpcmsg('tests.getStateName.12', array(
654
            new xmlrpcval(23, 'int')
655
        ));
656
        $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...
657
    }
658
659
    public function testCodeInjectionServerSide()
660
    {
661
        $m = new xmlrpcmsg('system.MethodHelp');
662
        $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>";
663
        $v = $this->send($m);
664
        if ($v) {
665
            $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...
666
        }
667
    }
668
669
    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...
670
    {
671
        $m = new xmlrpcmsg('tests.getStateName.2', array(
672
            new xmlrpcval(23, 'int'),
673
        ));
674
        $v = $this->send($m);
675
        $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...
676
677
        // this generates an exception in the function which was wrapped, which is by default wrapped in a known error response
678
        $m = new xmlrpcmsg('tests.getStateName.2', array(
679
            new xmlrpcval(0, 'int'),
680
        ));
681
        $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...
682
683
        // check if the generated function dispatch map is fine, by checking if the server registered it
684
        $m = new xmlrpcmsg('system.methodSignature', array(
685
            new xmlrpcval('tests.getStateName.2'),
686
        ));
687
        $v = $this->send($m);
688
        $encoder = new \PhpXmlRpc\Encoder();
689
        $this->assertEquals(array(array('string', 'int')), $encoder->decode($v));
690
    }
691
692
    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...
693
    {
694
        $m = new xmlrpcmsg('tests.getStateName.6', array(
695
            new xmlrpcval(23, 'int'),
696
        ));
697
        $v = $this->send($m);
698
        $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...
699
700
        // this generates an exception in the function which was wrapped, which is by default wrapped in a known error response
701
        $m = new xmlrpcmsg('tests.getStateName.6', array(
702
            new xmlrpcval(0, 'int'),
703
        ));
704
        $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...
705
    }
706
707
    public function testServerWrappedObjectMethods()
708
    {
709
        $m = new xmlrpcmsg('tests.getStateName.3', array(
710
            new xmlrpcval(23, 'int'),
711
        ));
712
        $v = $this->send($m);
713
        $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...
714
715
        $m = new xmlrpcmsg('tests.getStateName.4', array(
716
            new xmlrpcval(23, 'int'),
717
        ));
718
        $v = $this->send($m);
719
        $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...
720
721
        $m = new xmlrpcmsg('tests.getStateName.5', 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.7', 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.8', 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.9', 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
746
    public function testServerWrappedObjectMethodsAsSource()
747
    {
748
        $m = new xmlrpcmsg('tests.getStateName.7', array(
749
            new xmlrpcval(23, 'int'),
750
        ));
751
        $v = $this->send($m);
752
        $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...
753
754
        $m = new xmlrpcmsg('tests.getStateName.8', array(
755
            new xmlrpcval(23, 'int'),
756
        ));
757
        $v = $this->send($m);
758
        $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...
759
760
        $m = new xmlrpcmsg('tests.getStateName.9', 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
767 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...
768
    {
769
        $m = new xmlrpcmsg('tests.getStateName.10', array(
770
            new xmlrpcval(23, 'int'),
771
        ));
772
        $v = $this->send($m);
773
        $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...
774
    }
775
776 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...
777
    {
778
        $m = new xmlrpcmsg('tests.getStateName.11', array(
779
            new xmlrpcval(23, 'int'),
780
        ));
781
        $v = $this->send($m);
782
        $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...
783
    }
784
785 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...
786
    {
787
        $m = new xmlrpcmsg('tests.xmlrpcServerMethodsContainer.findState', array(
788
            new xmlrpcval(23, 'int'),
789
        ));
790
        $v = $this->send($m);
791
        $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...
792
    }
793
794
    public function testWrappedMethod()
795
    {
796
        // make a 'deep client copy' as the original one might have many properties set
797
        $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...
798
        if ($func == false) {
799
            $this->fail('Registration of examples.getStateName failed');
800
        } else {
801
            $v = $func(23);
802
            // work around bug in current (or old?) version of phpunit when reporting the error
803
            /*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...
804
                $v = var_export($v, true);
805
            }*/
806
            $this->assertEquals('Michigan', $v);
807
        }
808
    }
809
810
    public function testWrappedMethodAsSource()
811
    {
812
        // make a 'deep client copy' as the original one might have many properties set
813
        $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...
814
        if ($func == false) {
815
            $this->fail('Registration of examples.getStateName failed');
816
        } else {
817
            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...
818
            $func = $func['function'];
819
            $v = $func(23);
820
            // work around bug in current (or old?) version of phpunit when reporting the error
821
            /*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...
822
                $v = var_export($v, true);
823
            }*/
824
            $this->assertEquals('Michigan', $v);
825
        }
826
    }
827
828
    public function testWrappedClass()
829
    {
830
        // make a 'deep client copy' as the original one might have many properties set
831
        // also for speed only wrap one method of the whole server
832
        $class = wrap_xmlrpc_server($this->client, array('simple_client_copy' => 0, 'method_filter' => '/examples\.getStateName/' ));
833
        if ($class == '') {
834
            $this->fail('Registration of remote server failed');
835
        } else {
836
            $obj = new $class();
837
            $v = $obj->examples_getStateName(23);
838
            // work around bug in current (or old?) version of phpunit when reporting the error
839
            /*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...
840
                $v = var_export($v, true);
841
            }*/
842
            $this->assertEquals('Michigan', $v);
843
        }
844
    }
845
846
    public function testTransferOfObjectViaWrapping()
847
    {
848
        // make a 'deep client copy' as the original one might have many properties set
849
        $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...
850
            'decode_php_objs' => true));
851
        if ($func == false) {
852
            $this->fail('Registration of tests.returnPhpObject failed');
853
        } else {
854
            $v = $func();
855
            $obj = new stdClass();
856
            $obj->hello = 'world';
857
            $this->assertEquals($obj, $v);
858
        }
859
    }
860
861
    public function testGetCookies()
862
    {
863
        // let server set to us some cookies we tell it
864
        $cookies = array(
865
            //'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...
866
            'c2' => array('value' => 'c2'),
867
            'c3' => array('value' => 'c3', 'expires' => time() + 60 * 60 * 24 * 30),
868
            'c4' => array('value' => 'c4', 'expires' => time() + 60 * 60 * 24 * 30, 'path' => '/'),
869
            'c5' => array('value' => 'c5', 'expires' => time() + 60 * 60 * 24 * 30, 'path' => '/', 'domain' => 'localhost'),
870
        );
871
        $cookiesval = php_xmlrpc_encode($cookies);
872
        $m = new xmlrpcmsg('examples.setcookies', array($cookiesval));
873
        $r = $this->send($m, 0, true);
874
        if ($r) {
875
            $v = $r->value();
876
            $this->assertEquals(1, $v->scalarval());
877
            // now check if we decoded the cookies as we had set them
878
            $rcookies = $r->cookies();
879
            // remove extra cookies which might have been set by proxies
880
            foreach ($rcookies as $c => $v) {
881
                if (!in_array($c, array('c2', 'c3', 'c4', 'c5'))) {
882
                    unset($rcookies[$c]);
883
                }
884
                // Seems like we get this when using php-fpm and php 5.5+ ...
885
                if (isset($rcookies[$c]['Max-Age'])) {
886
                    unset($rcookies[$c]['Max-Age']);
887
                }
888
            }
889
            foreach ($cookies as $c => $v) {
890
                // format for date string in cookies: 'Mon, 31 Oct 2005 13:50:56 GMT'
891
                // but PHP versions differ on that, some use 'Mon, 31-Oct-2005 13:50:56 GMT'...
892
                if (isset($v['expires'])) {
893
                    if (isset($rcookies[$c]['expires']) && strpos($rcookies[$c]['expires'], '-')) {
894
                        $cookies[$c]['expires'] = gmdate('D, d\-M\-Y H:i:s \G\M\T', $cookies[$c]['expires']);
895
                    } else {
896
                        $cookies[$c]['expires'] = gmdate('D, d M Y H:i:s \G\M\T', $cookies[$c]['expires']);
897
                    }
898
                }
899
            }
900
901
            $this->assertEquals($cookies, $rcookies);
902
        }
903
    }
904
905
    public function testSetCookies()
906
    {
907
        // let server set to us some cookies we tell it
908
        $cookies = array(
909
            'c0' => null,
910
            'c1' => 1,
911
            'c2' => '2 3',
912
            'c3' => '!@#$%^&*()_+|}{":?><,./\';[]\\=-',
913
        );
914
        $m = new xmlrpcmsg('examples.getcookies', array());
915
        foreach ($cookies as $cookie => $val) {
916
            $this->client->setCookie($cookie, $val);
917
            $cookies[$cookie] = (string)$cookies[$cookie];
918
        }
919
        $r = $this->client->send($m, $this->timeout, $this->method);
920
        $this->assertEquals(0, $r->faultCode(), 'Error ' . $r->faultCode() . ' connecting to server: ' . $r->faultString());
921
        if (!$r->faultCode()) {
922
            $v = $r->value();
923
            $v = php_xmlrpc_decode($v);
924
925
            // take care for the extra cookie used for coverage collection
926
            if (isset($v['PHPUNIT_SELENIUM_TEST_ID'])) {
927
                unset($v['PHPUNIT_SELENIUM_TEST_ID']);
928
            }
929
930
            // on IIS and Apache getallheaders returns something slightly different...
931
            $this->assertEquals($cookies, $v);
932
        }
933
    }
934
935
    public function testServerComments()
936
    {
937
        $m = new xmlrpcmsg('tests.xmlrpcServerMethodsContainer.debugMessageGenerator', array(
938
            new xmlrpcval('hello world', 'string'),
939
        ));
940
        $r = $this->send($m, 0, true);
941
        $this->assertContains('hello world', $r->raw_data);
942
    }
943
944
    public function testSendTwiceSameMsg()
945
    {
946
        $m = new xmlrpcmsg('examples.stringecho', array(
947
            new xmlrpcval('hello world', 'string'),
948
        ));
949
        $v1 = $this->send($m);
950
        $v2 = $this->send($m);
951
        if ($v1 && $v2) {
952
            $this->assertEquals($v1, $v2);
953
        }
954
    }
955
}
956