Passed
Push — master ( 24898d...721548 )
by Gaetano
08:06
created

ClientTest::test404Interop()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 1
Metric Value
cc 1
eloc 7
nc 1
nop 0
dl 0
loc 10
rs 10
c 1
b 1
f 1
1
<?php
2
3
include_once __DIR__ . '/LoggerAwareTestCase.php';
4
5
/**
6
 * Tests involving the Client class (and no server).
7
 */
8
class ClientTest extends PhpXmlRpc_LoggerAwareTestCase
9
{
10
    /** @var xmlrpc_client $client */
11
    public $client = null;
12
13
    public function set_up()
14
    {
15
        parent::set_up();
16
17
        $this->client = new xmlrpc_client('/NOTEXIST.php', $this->args['HTTPSERVER'], 80);
18
        $this->client->setDebug($this->args['DEBUG']);
19
    }
20
21
    public function test404()
22
    {
23
        $m = new xmlrpcmsg('examples.echo', array(
24
            new xmlrpcval('hello', 'string'),
25
        ));
26
        $r = $this->client->send($m, 5);
27
        $this->assertEquals(5, $r->faultCode());
28
    }
29
30
    public function test404Interop()
31
    {
32
        $m = new xmlrpcmsg('examples.echo', array(
33
            new xmlrpcval('hello', 'string'),
34
        ));
35
        $orig = \PhpXmlRpc\PhpXmlRpc::$xmlrpcerr;
36
        \PhpXmlRpc\PhpXmlRpc::useInteropFaults();
37
        $r = $this->client->send($m, 5);
38
        $this->assertEquals(-32300, $r->faultCode());
39
        \PhpXmlRpc\PhpXmlRpc::$xmlrpcerr = $orig;
40
    }
41
42
    public function testSrvNotFound()
43
    {
44
        $m = new xmlrpcmsg('examples.echo', array(
45
            new xmlrpcval('hello', 'string'),
46
        ));
47
        $this->client->server .= 'XXX';
48
        $dnsinfo = @dns_get_record($this->client->server);
49
        if ($dnsinfo) {
50
            $this->markTestSkipped('Seems like there is a catchall DNS in effect: host ' . $this->client->server . ' found');
51
        } else {
52
            $r = $this->client->send($m, 5);
53
            // make sure there's no freaking catchall DNS in effect
54
            $this->assertEquals(5, $r->faultCode());
55
        }
56
    }
57
58
    public function testCurlKAErr()
59
    {
60
        if (!function_exists('curl_init')) {
61
            $this->markTestSkipped('CURL missing: cannot test curl keepalive errors');
62
63
            return;
64
        }
65
        $m = new xmlrpcmsg('examples.stringecho', array(
66
            new xmlrpcval('hello', 'string'),
67
        ));
68
        // test 2 calls w. keepalive: 1st time connection ko, second time ok
69
        $this->client->server .= 'XXX';
70
        $this->client->keepalive = true;
71
        $r = $this->client->send($m, 5, 'http11');
72
        // in case we have a "universal dns resolver" getting in the way, we might get a 302 instead of a 404
73
        $this->assertTrue($r->faultCode() === 8 || $r->faultCode() == 5);
74
75
        // now test a successful connection
76
        $server = explode(':', $this->args['HTTPSERVER']);
77
        if (count($server) > 1) {
78
            $this->client->port = $server[1];
0 ignored issues
show
Documentation Bug introduced by
The property $port was declared of type integer, but $server[1] is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
79
        }
80
        $this->client->server = $server[0];
81
        $this->client->path = $this->args['HTTPURI'];
82
83
        $r = $this->client->send($m, 5, 'http11');
84
        $this->assertEquals(0, $r->faultCode());
85
        $ro = $r->value();
86
        is_object($ro) && $this->assertEquals('hello', $ro->scalarVal());
87
    }
88
}
89