3 include_once __DIR__ . '/../lib/xmlrpc.inc';
5 include_once __DIR__ . '/parse_args.php';
7 class InvalidHostTest extends PHPUnit_Framework_TestCase
10 public $args = array();
12 public function setUp()
14 $this->args = argParser::getArgs();
16 $this->client = new xmlrpc_client('/NOTEXIST.php', $this->args['LOCALSERVER'], 80);
17 if ($this->args['DEBUG']) {
18 $this->client->setDebug($this->args['DEBUG']);
22 public function test404()
24 $f = new xmlrpcmsg('examples.echo', array(
25 new xmlrpcval('hello', 'string'),
27 $r = $this->client->send($f, 5);
28 $this->assertEquals(5, $r->faultCode());
31 public function testSrvNotFound()
33 $f = new xmlrpcmsg('examples.echo', array(
34 new xmlrpcval('hello', 'string'),
36 $this->client->server .= 'XXX';
37 $r = $this->client->send($f, 5);
38 // make sure there's no freaking catchall DNS in effect
39 $dnsinfo = dns_get_record($this->client->server);
41 $this->markTestSkipped('Seems like there is a catchall DNS in effect: host ' . $this->client->server . ' found');
43 $this->assertEquals(5, $r->faultCode());
47 public function testCurlKAErr()
49 if (!function_exists('curl_init')) {
50 $this->markTestSkipped('CURL missing: cannot test curl keepalive errors');
54 $f = new xmlrpcmsg('examples.stringecho', array(
55 new xmlrpcval('hello', 'string'),
57 // test 2 calls w. keepalive: 1st time connection ko, second time ok
58 $this->client->server .= 'XXX';
59 $this->client->keepalive = true;
60 $r = $this->client->send($f, 5, 'http11');
61 // in case we have a "universal dns resolver" getting in the way, we might get a 302 instead of a 404
62 $this->assertTrue($r->faultCode() === 8 || $r->faultCode() == 5);
64 // now test a successful connection
65 $server = explode(':', $this->args['LOCALSERVER']);
66 if (count($server) > 1) {
67 $this->client->port = $server[1];
69 $this->client->server = $server[0];
70 $this->client->path = $this->args['URI'];
72 $r = $this->client->send($f, 5, 'http11');
73 $this->assertEquals(0, $r->faultCode());
75 is_object($ro) && $this->assertEquals('hello', $ro->scalarVal());