Move travis config in a subdir of tests; enable debug to help with travis/php5.6
[plcapi.git] / tests / InvalidHostTest.php
1 <?php
2
3 include_once __DIR__ . '/../lib/xmlrpc.inc';
4
5 include_once __DIR__ . '/parse_args.php';
6
7 class InvalidHostTest extends PHPUnit_Framework_TestCase
8 {
9     public $client = null;
10     public $args = array();
11
12     public function setUp()
13     {
14         $this->args = argParser::getArgs();
15
16         $this->client = new xmlrpc_client('/NOTEXIST.php', $this->args['LOCALSERVER'], 80);
17         if ($this->args['DEBUG']) {
18             $this->client->setDebug($this->args['DEBUG']);
19         }
20     }
21
22     public function test404()
23     {
24         $f = new xmlrpcmsg('examples.echo', array(
25             new xmlrpcval('hello', 'string'),
26         ));
27         $r = $this->client->send($f, 5);
28         $this->assertEquals(5, $r->faultCode());
29     }
30
31     public function testSrvNotFound()
32     {
33         $f = new xmlrpcmsg('examples.echo', array(
34             new xmlrpcval('hello', 'string'),
35         ));
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);
40         if ($dnsinfo) {
41             $this->markTestSkipped('Seems like there is a catchall DNS in effect: host ' . $this->client->server . ' found');
42         } else {
43             $this->assertEquals(5, $r->faultCode());
44         }
45     }
46
47     public function testCurlKAErr()
48     {
49         if (!function_exists('curl_init')) {
50             $this->markTestSkipped('CURL missing: cannot test curl keepalive errors');
51
52             return;
53         }
54         $f = new xmlrpcmsg('examples.stringecho', array(
55             new xmlrpcval('hello', 'string'),
56         ));
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);
63
64         // now test a successful connection
65         $server = explode(':', $this->args['LOCALSERVER']);
66         if (count($server) > 1) {
67             $this->client->port = $server[1];
68         }
69         $this->client->server = $server[0];
70         $this->client->path = $this->args['URI'];
71
72         $r = $this->client->send($f, 5, 'http11');
73         $this->assertEquals(0, $r->faultCode());
74         $ro = $r->value();
75         is_object($ro) && $this->assertEquals('hello', $ro->scalarVal());
76     }
77 }