1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
include_once __DIR__ . '/../lib/xmlrpc.inc'; |
4
|
|
|
|
5
|
|
|
include_once __DIR__ . '/parse_args.php'; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Tests involving requests sent to non-existing servers |
9
|
|
|
*/ |
10
|
|
|
class InvalidHostTest extends PHPUnit_Framework_TestCase |
11
|
|
|
{ |
12
|
|
|
/** @var xmlrpc_client $client */ |
13
|
|
|
public $client = null; |
14
|
|
|
public $args = array(); |
15
|
|
|
|
16
|
|
|
public function setUp() |
17
|
|
|
{ |
18
|
|
|
$this->args = argParser::getArgs(); |
19
|
|
|
|
20
|
|
|
$this->client = new xmlrpc_client('/NOTEXIST.php', $this->args['LOCALSERVER'], 80); |
21
|
|
|
$this->client->setDebug($this->args['DEBUG']); |
22
|
|
|
|
23
|
|
|
if ($this->args['DEBUG'] == 1) |
24
|
|
|
ob_start(); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
protected function tearDown() |
28
|
|
|
{ |
29
|
|
|
if ($this->args['DEBUG'] != 1) |
30
|
|
|
return; |
31
|
|
|
$out = ob_get_clean(); |
32
|
|
|
$status = $this->getStatus(); |
33
|
|
|
if ($status == PHPUnit_Runner_BaseTestRunner::STATUS_ERROR |
34
|
|
|
|| $status == PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE) { |
35
|
|
|
echo $out; |
36
|
|
|
} |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function test404() |
40
|
|
|
{ |
41
|
|
|
$m = new xmlrpcmsg('examples.echo', array( |
42
|
|
|
new xmlrpcval('hello', 'string'), |
43
|
|
|
)); |
44
|
|
|
$r = $this->client->send($m, 5); |
45
|
|
|
$this->assertEquals(5, $r->faultCode()); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function testSrvNotFound() |
49
|
|
|
{ |
50
|
|
|
$m = new xmlrpcmsg('examples.echo', array( |
51
|
|
|
new xmlrpcval('hello', 'string'), |
52
|
|
|
)); |
53
|
|
|
$this->client->server .= 'XXX'; |
54
|
|
|
$r = $this->client->send($m, 5); |
55
|
|
|
// make sure there's no freaking catchall DNS in effect |
56
|
|
|
$dnsinfo = dns_get_record($this->client->server); |
57
|
|
|
if ($dnsinfo) { |
|
|
|
|
58
|
|
|
$this->markTestSkipped('Seems like there is a catchall DNS in effect: host ' . $this->client->server . ' found'); |
59
|
|
|
} else { |
60
|
|
|
$this->assertEquals(5, $r->faultCode()); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function testCurlKAErr() |
65
|
|
|
{ |
66
|
|
|
if (!function_exists('curl_init')) { |
67
|
|
|
$this->markTestSkipped('CURL missing: cannot test curl keepalive errors'); |
68
|
|
|
|
69
|
|
|
return; |
70
|
|
|
} |
71
|
|
|
$m = new xmlrpcmsg('examples.stringecho', array( |
72
|
|
|
new xmlrpcval('hello', 'string'), |
73
|
|
|
)); |
74
|
|
|
// test 2 calls w. keepalive: 1st time connection ko, second time ok |
75
|
|
|
$this->client->server .= 'XXX'; |
76
|
|
|
$this->client->keepalive = true; |
77
|
|
|
$r = $this->client->send($m, 5, 'http11'); |
78
|
|
|
// in case we have a "universal dns resolver" getting in the way, we might get a 302 instead of a 404 |
79
|
|
|
$this->assertTrue($r->faultCode() === 8 || $r->faultCode() == 5); |
80
|
|
|
|
81
|
|
|
// now test a successful connection |
82
|
|
|
$server = explode(':', $this->args['LOCALSERVER']); |
83
|
|
|
if (count($server) > 1) { |
84
|
|
|
$this->client->port = $server[1]; |
85
|
|
|
} |
86
|
|
|
$this->client->server = $server[0]; |
87
|
|
|
$this->client->path = $this->args['URI']; |
88
|
|
|
|
89
|
|
|
$r = $this->client->send($m, 5, 'http11'); |
90
|
|
|
$this->assertEquals(0, $r->faultCode()); |
91
|
|
|
$ro = $r->value(); |
92
|
|
|
is_object($ro) && $this->assertEquals('hello', $ro->scalarVal()); |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.