|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
include_once __DIR__ . '/LoggerAwareTestCase.php'; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Tests involving the Client class (and no server). |
|
7
|
|
|
*/ |
|
8
|
|
|
class ClientTest extends PhpXmlRpc_LoggerAwareTestCase |
|
9
|
|
|
{ |
|
10
|
|
|
/** @var xmlrpc_client $client */ |
|
11
|
|
|
public $client = null; |
|
12
|
|
|
|
|
13
|
|
|
public function set_up() |
|
14
|
|
|
{ |
|
15
|
|
|
parent::set_up(); |
|
16
|
|
|
|
|
17
|
|
|
$this->client = new xmlrpc_client('/NOTEXIST.php', $this->args['HTTPSERVER'], 80); |
|
18
|
|
|
$this->client->setDebug($this->args['DEBUG']); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
public function test404() |
|
22
|
|
|
{ |
|
23
|
|
|
$m = new xmlrpcmsg('examples.echo', array( |
|
24
|
|
|
new xmlrpcval('hello', 'string'), |
|
25
|
|
|
)); |
|
26
|
|
|
$r = $this->client->send($m, 5); |
|
27
|
|
|
$this->assertEquals(5, $r->faultCode()); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function test404Interop() |
|
31
|
|
|
{ |
|
32
|
|
|
$m = new xmlrpcmsg('examples.echo', array( |
|
33
|
|
|
new xmlrpcval('hello', 'string'), |
|
34
|
|
|
)); |
|
35
|
|
|
$orig = \PhpXmlRpc\PhpXmlRpc::$xmlrpcerr; |
|
36
|
|
|
\PhpXmlRpc\PhpXmlRpc::useInteropFaults(); |
|
37
|
|
|
$r = $this->client->send($m, 5); |
|
38
|
|
|
$this->assertEquals(-32300, $r->faultCode()); |
|
39
|
|
|
\PhpXmlRpc\PhpXmlRpc::$xmlrpcerr = $orig; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function testSrvNotFound() |
|
43
|
|
|
{ |
|
44
|
|
|
$m = new xmlrpcmsg('examples.echo', array( |
|
45
|
|
|
new xmlrpcval('hello', 'string'), |
|
46
|
|
|
)); |
|
47
|
|
|
$this->client->server .= 'XXX'; |
|
48
|
|
|
$dnsinfo = @dns_get_record($this->client->server); |
|
49
|
|
|
if ($dnsinfo) { |
|
50
|
|
|
$this->markTestSkipped('Seems like there is a catchall DNS in effect: host ' . $this->client->server . ' found'); |
|
51
|
|
|
} else { |
|
52
|
|
|
$r = $this->client->send($m, 5); |
|
53
|
|
|
// make sure there's no freaking catchall DNS in effect |
|
54
|
|
|
$this->assertEquals(5, $r->faultCode()); |
|
55
|
|
|
} |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
public function testCurlKAErr() |
|
59
|
|
|
{ |
|
60
|
|
|
if (!function_exists('curl_init')) { |
|
61
|
|
|
$this->markTestSkipped('CURL missing: cannot test curl keepalive errors'); |
|
62
|
|
|
|
|
63
|
|
|
return; |
|
64
|
|
|
} |
|
65
|
|
|
$m = new xmlrpcmsg('examples.stringecho', array( |
|
66
|
|
|
new xmlrpcval('hello', 'string'), |
|
67
|
|
|
)); |
|
68
|
|
|
// test 2 calls w. keepalive: 1st time connection ko, second time ok |
|
69
|
|
|
$this->client->server .= 'XXX'; |
|
70
|
|
|
$this->client->keepalive = true; |
|
71
|
|
|
$r = $this->client->send($m, 5, 'http11'); |
|
72
|
|
|
// in case we have a "universal dns resolver" getting in the way, we might get a 302 instead of a 404 |
|
73
|
|
|
$this->assertTrue($r->faultCode() === 8 || $r->faultCode() == 5); |
|
74
|
|
|
|
|
75
|
|
|
// now test a successful connection |
|
76
|
|
|
$server = explode(':', $this->args['HTTPSERVER']); |
|
77
|
|
|
if (count($server) > 1) { |
|
78
|
|
|
$this->client->port = $server[1]; |
|
|
|
|
|
|
79
|
|
|
} |
|
80
|
|
|
$this->client->server = $server[0]; |
|
81
|
|
|
$this->client->path = $this->args['HTTPURI']; |
|
82
|
|
|
|
|
83
|
|
|
$r = $this->client->send($m, 5, 'http11'); |
|
84
|
|
|
$this->assertEquals(0, $r->faultCode()); |
|
85
|
|
|
$ro = $r->value(); |
|
86
|
|
|
is_object($ro) && $this->assertEquals('hello', $ro->scalarVal()); |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
public function testgetUrl() |
|
90
|
|
|
{ |
|
91
|
|
|
$m = $this->client->getUrl(PHP_URL_SCHEME); |
|
92
|
|
|
$this->assertEquals($m, $this->client->method); |
|
93
|
|
|
$h = $this->client->getUrl(PHP_URL_HOST); |
|
94
|
|
|
$this->assertEquals($h, $this->client->server); |
|
95
|
|
|
$p = $this->client->getUrl(PHP_URL_PORT); |
|
96
|
|
|
$this->assertEquals($p, $this->client->port); |
|
97
|
|
|
$p = $this->client->getUrl(PHP_URL_PATH); |
|
98
|
|
|
$this->assertEquals($p, $this->client->path); |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|
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.