1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
include_once __DIR__ . '/../lib/xmlrpc.inc'; |
4
|
|
|
|
5
|
|
|
include_once __DIR__ . '/parse_args.php'; |
6
|
|
|
|
7
|
|
|
include_once __DIR__ . '/PolyfillTestCase.php'; |
8
|
|
|
|
9
|
|
|
use PHPUnit\Runner\BaseTestRunner; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Tests involving the Client class (and no server). |
13
|
|
|
*/ |
14
|
|
|
class ClientTes extends PhpXmlRpc_PolyfillTestCase |
15
|
|
|
{ |
16
|
|
|
/** @var xmlrpc_client $client */ |
17
|
|
|
public $client = null; |
18
|
|
|
public $args = array(); |
19
|
|
|
|
20
|
|
|
public function set_up() |
21
|
|
|
{ |
22
|
|
|
$this->args = argParser::getArgs(); |
23
|
|
|
|
24
|
|
|
$this->client = new xmlrpc_client('/NOTEXIST.php', $this->args['HTTPSERVER'], 80); |
25
|
|
|
$this->client->setDebug($this->args['DEBUG']); |
26
|
|
|
|
27
|
|
|
// in debug mode, the client will be very verbose. Avoid showing its output unless there are errors |
28
|
|
|
if ($this->args['DEBUG'] >= 1) |
29
|
|
|
ob_start(); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
protected function tear_down() |
33
|
|
|
{ |
34
|
|
|
if ($this->args['DEBUG'] < 1) |
35
|
|
|
return; |
36
|
|
|
$out = ob_get_clean(); |
37
|
|
|
$status = $this->getStatus(); |
38
|
|
|
if ($status == BaseTestRunner::STATUS_ERROR |
39
|
|
|
|| $status == BaseTestRunner::STATUS_FAILURE) { |
40
|
|
|
echo $out; |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function test404() |
45
|
|
|
{ |
46
|
|
|
$m = new xmlrpcmsg('examples.echo', array( |
47
|
|
|
new xmlrpcval('hello', 'string'), |
48
|
|
|
)); |
49
|
|
|
$r = $this->client->send($m, 5); |
50
|
|
|
$this->assertEquals(5, $r->faultCode()); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function testSrvNotFound() |
54
|
|
|
{ |
55
|
|
|
$m = new xmlrpcmsg('examples.echo', array( |
56
|
|
|
new xmlrpcval('hello', 'string'), |
57
|
|
|
)); |
58
|
|
|
$this->client->server .= 'XXX'; |
59
|
|
|
$dnsinfo = @dns_get_record($this->client->server); |
60
|
|
|
if ($dnsinfo) { |
61
|
|
|
$this->markTestSkipped('Seems like there is a catchall DNS in effect: host ' . $this->client->server . ' found'); |
62
|
|
|
} else { |
63
|
|
|
$r = $this->client->send($m, 5); |
64
|
|
|
// make sure there's no freaking catchall DNS in effect |
65
|
|
|
$this->assertEquals(5, $r->faultCode()); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function testCurlKAErr() |
70
|
|
|
{ |
71
|
|
|
if (!function_exists('curl_init')) { |
72
|
|
|
$this->markTestSkipped('CURL missing: cannot test curl keepalive errors'); |
73
|
|
|
|
74
|
|
|
return; |
75
|
|
|
} |
76
|
|
|
$m = new xmlrpcmsg('examples.stringecho', array( |
77
|
|
|
new xmlrpcval('hello', 'string'), |
78
|
|
|
)); |
79
|
|
|
// test 2 calls w. keepalive: 1st time connection ko, second time ok |
80
|
|
|
$this->client->server .= 'XXX'; |
81
|
|
|
$this->client->keepalive = true; |
82
|
|
|
$r = $this->client->send($m, 5, 'http11'); |
83
|
|
|
// in case we have a "universal dns resolver" getting in the way, we might get a 302 instead of a 404 |
84
|
|
|
$this->assertTrue($r->faultCode() === 8 || $r->faultCode() == 5); |
85
|
|
|
|
86
|
|
|
// now test a successful connection |
87
|
|
|
$server = explode(':', $this->args['HTTPSERVER']); |
88
|
|
|
if (count($server) > 1) { |
89
|
|
|
$this->client->port = $server[1]; |
|
|
|
|
90
|
|
|
} |
91
|
|
|
$this->client->server = $server[0]; |
92
|
|
|
$this->client->path = $this->args['HTTPURI']; |
93
|
|
|
|
94
|
|
|
$r = $this->client->send($m, 5, 'http11'); |
95
|
|
|
$this->assertEquals(0, $r->faultCode()); |
96
|
|
|
$ro = $r->value(); |
97
|
|
|
is_object($ro) && $this->assertEquals('hello', $ro->scalarVal()); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.