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