3 include_once __DIR__ . '/../lib/xmlrpc.inc';
5 include_once __DIR__ . '/parse_args.php';
8 * Tests involving requests sent to non-existing servers
10 class InvalidHostTest extends PHPUnit_Framework_TestCase
12 /** @var xmlrpc_client $client */
13 public $client = null;
14 public $args = array();
16 public function setUp()
18 $this->args = argParser::getArgs();
20 $this->client = new xmlrpc_client('/NOTEXIST.php', $this->args['LOCALSERVER'], 80);
21 $this->client->setDebug($this->args['DEBUG']);
23 if ($this->args['DEBUG'] == 1)
27 protected function tearDown()
29 if ($this->args['DEBUG'] != 1)
31 $out = ob_get_clean();
32 $status = $this->getStatus();
33 if ($status == PHPUnit_Runner_BaseTestRunner::STATUS_ERROR
34 || $status == PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE) {
39 public function test404()
41 $f = new xmlrpcmsg('examples.echo', array(
42 new xmlrpcval('hello', 'string'),
44 $r = $this->client->send($f, 5);
45 $this->assertEquals(5, $r->faultCode());
48 public function testSrvNotFound()
50 $f = new xmlrpcmsg('examples.echo', array(
51 new xmlrpcval('hello', 'string'),
53 $this->client->server .= 'XXX';
54 $r = $this->client->send($f, 5);
55 // make sure there's no freaking catchall DNS in effect
56 $dnsinfo = dns_get_record($this->client->server);
58 $this->markTestSkipped('Seems like there is a catchall DNS in effect: host ' . $this->client->server . ' found');
60 $this->assertEquals(5, $r->faultCode());
64 public function testCurlKAErr()
66 if (!function_exists('curl_init')) {
67 $this->markTestSkipped('CURL missing: cannot test curl keepalive errors');
71 $f = new xmlrpcmsg('examples.stringecho', array(
72 new xmlrpcval('hello', 'string'),
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($f, 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);
81 // now test a successful connection
82 $server = explode(':', $this->args['LOCALSERVER']);
83 if (count($server) > 1) {
84 $this->client->port = $server[1];
86 $this->client->server = $server[0];
87 $this->client->path = $this->args['URI'];
89 $r = $this->client->send($f, 5, 'http11');
90 $this->assertEquals(0, $r->faultCode());
92 is_object($ro) && $this->assertEquals('hello', $ro->scalarVal());