3 include_once __DIR__ . '/../lib/xmlrpc.inc';
5 include_once __DIR__ . '/parse_args.php';
7 include_once __DIR__ . '/PolyfillTestCase.php';
10 * Tests involving requests sent to non-existing servers
12 class InvalidHostTest extends PhpXmlRpc_PolyfillTestCase
14 /** @var xmlrpc_client $client */
15 public $client = null;
16 public $args = array();
18 public function set_up()
20 $this->args = argParser::getArgs();
22 $this->client = new xmlrpc_client('/NOTEXIST.php', $this->args['HTTPSERVER'], 80);
23 $this->client->setDebug($this->args['DEBUG']);
25 if ($this->args['DEBUG'] == 1)
29 protected function tear_down()
31 if ($this->args['DEBUG'] != 1)
33 $out = ob_get_clean();
34 $status = $this->getStatus();
35 if ($status == PHPUnit_Runner_BaseTestRunner::STATUS_ERROR
36 || $status == PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE) {
41 public function test404()
43 $m = new xmlrpcmsg('examples.echo', array(
44 new xmlrpcval('hello', 'string'),
46 $r = $this->client->send($m, 5);
47 $this->assertEquals(5, $r->faultCode());
50 public function testSrvNotFound()
52 $m = new xmlrpcmsg('examples.echo', array(
53 new xmlrpcval('hello', 'string'),
55 $this->client->server .= 'XXX';
56 $r = $this->client->send($m, 5);
57 // make sure there's no freaking catchall DNS in effect
58 $dnsinfo = dns_get_record($this->client->server);
60 $this->markTestSkipped('Seems like there is a catchall DNS in effect: host ' . $this->client->server . ' found');
62 $this->assertEquals(5, $r->faultCode());
66 public function testCurlKAErr()
68 if (!function_exists('curl_init')) {
69 $this->markTestSkipped('CURL missing: cannot test curl keepalive errors');
73 $m = new xmlrpcmsg('examples.stringecho', array(
74 new xmlrpcval('hello', 'string'),
76 // test 2 calls w. keepalive: 1st time connection ko, second time ok
77 $this->client->server .= 'XXX';
78 $this->client->keepalive = true;
79 $r = $this->client->send($m, 5, 'http11');
80 // in case we have a "universal dns resolver" getting in the way, we might get a 302 instead of a 404
81 $this->assertTrue($r->faultCode() === 8 || $r->faultCode() == 5);
83 // now test a successful connection
84 $server = explode(':', $this->args['HTTPSERVER']);
85 if (count($server) > 1) {
86 $this->client->port = $server[1];
88 $this->client->server = $server[0];
89 $this->client->path = $this->args['HTTPURI'];
91 $r = $this->client->send($m, 5, 'http11');
92 $this->assertEquals(0, $r->faultCode());
94 is_object($ro) && $this->assertEquals('hello', $ro->scalarVal());