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 the Client class.
13 * So far: only tests requests sent to non-existing servers
15 class ClientTest extends PhpXmlRpc_PolyfillTestCase
17 /** @var xmlrpc_client $client */
18 public $client = null;
19 public $args = array();
21 public function set_up()
23 $this->args = argParser::getArgs();
25 $this->client = new xmlrpc_client('/NOTEXIST.php', $this->args['HTTPSERVER'], 80);
26 $this->client->setDebug($this->args['DEBUG']);
28 if ($this->args['DEBUG'] == 1)
32 protected function tear_down()
34 if ($this->args['DEBUG'] != 1)
36 $out = ob_get_clean();
37 $status = $this->getStatus();
38 if ($status == BaseTestRunner::STATUS_ERROR
39 || $status == BaseTestRunner::STATUS_FAILURE) {
44 public function test404()
46 $m = new xmlrpcmsg('examples.echo', array(
47 new xmlrpcval('hello', 'string'),
49 $r = $this->client->send($m, 5);
50 $this->assertEquals(5, $r->faultCode());
53 public function testSrvNotFound()
55 $m = new xmlrpcmsg('examples.echo', array(
56 new xmlrpcval('hello', 'string'),
58 $this->client->server .= 'XXX';
59 $dnsinfo = @dns_get_record($this->client->server);
61 $this->markTestSkipped('Seems like there is a catchall DNS in effect: host ' . $this->client->server . ' found');
63 $r = $this->client->send($m, 5);
64 // make sure there's no freaking catchall DNS in effect
65 $this->assertEquals(5, $r->faultCode());
69 public function testCurlKAErr()
71 if (!function_exists('curl_init')) {
72 $this->markTestSkipped('CURL missing: cannot test curl keepalive errors');
76 $m = new xmlrpcmsg('examples.stringecho', array(
77 new xmlrpcval('hello', 'string'),
79 // test 2 calls w. keepalive: 1st time connection ko, second time ok
80 $this->client->server .= 'XXX';
81 $this->client->keepalive = true;
82 $r = $this->client->send($m, 5, 'http11');
83 // in case we have a "universal dns resolver" getting in the way, we might get a 302 instead of a 404
84 $this->assertTrue($r->faultCode() === 8 || $r->faultCode() == 5);
86 // now test a successful connection
87 $server = explode(':', $this->args['HTTPSERVER']);
88 if (count($server) > 1) {
89 $this->client->port = $server[1];
91 $this->client->server = $server[0];
92 $this->client->path = $this->args['HTTPURI'];
94 $r = $this->client->send($m, 5, 'http11');
95 $this->assertEquals(0, $r->faultCode());
97 is_object($ro) && $this->assertEquals('hello', $ro->scalarVal());