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 testSrvNotFound() |
31
|
|
|
{ |
32
|
|
|
$m = new xmlrpcmsg('examples.echo', array( |
33
|
|
|
new xmlrpcval('hello', 'string'), |
34
|
|
|
)); |
35
|
|
|
$this->client->server .= 'XXX'; |
36
|
|
|
$dnsinfo = @dns_get_record($this->client->server); |
37
|
|
|
if ($dnsinfo) { |
38
|
|
|
$this->markTestSkipped('Seems like there is a catchall DNS in effect: host ' . $this->client->server . ' found'); |
39
|
|
|
} else { |
40
|
|
|
$r = $this->client->send($m, 5); |
41
|
|
|
// make sure there's no freaking catchall DNS in effect |
42
|
|
|
$this->assertEquals(5, $r->faultCode()); |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function testCurlKAErr() |
47
|
|
|
{ |
48
|
|
|
if (!function_exists('curl_init')) { |
49
|
|
|
$this->markTestSkipped('CURL missing: cannot test curl keepalive errors'); |
50
|
|
|
|
51
|
|
|
return; |
52
|
|
|
} |
53
|
|
|
$m = new xmlrpcmsg('examples.stringecho', array( |
54
|
|
|
new xmlrpcval('hello', 'string'), |
55
|
|
|
)); |
56
|
|
|
// test 2 calls w. keepalive: 1st time connection ko, second time ok |
57
|
|
|
$this->client->server .= 'XXX'; |
58
|
|
|
$this->client->keepalive = true; |
59
|
|
|
$r = $this->client->send($m, 5, 'http11'); |
60
|
|
|
// in case we have a "universal dns resolver" getting in the way, we might get a 302 instead of a 404 |
61
|
|
|
$this->assertTrue($r->faultCode() === 8 || $r->faultCode() == 5); |
62
|
|
|
|
63
|
|
|
// now test a successful connection |
64
|
|
|
$server = explode(':', $this->args['HTTPSERVER']); |
65
|
|
|
if (count($server) > 1) { |
66
|
|
|
$this->client->port = $server[1]; |
|
|
|
|
67
|
|
|
} |
68
|
|
|
$this->client->server = $server[0]; |
69
|
|
|
$this->client->path = $this->args['HTTPURI']; |
70
|
|
|
|
71
|
|
|
$r = $this->client->send($m, 5, 'http11'); |
72
|
|
|
$this->assertEquals(0, $r->faultCode()); |
73
|
|
|
$ro = $r->value(); |
74
|
|
|
is_object($ro) && $this->assertEquals('hello', $ro->scalarVal()); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
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.