1 | <?php |
||
2 | |||
3 | include_once __DIR__ . '/ServerAwareTestCase.php'; |
||
4 | |||
5 | /** |
||
6 | * Tests involving the Client class features (and mostly no server). |
||
7 | * @todo review: are there any tests which belong to the ServerTest class? |
||
8 | */ |
||
9 | class ClientTest extends PhpXmlRpc_ServerAwareTestCase |
||
10 | { |
||
11 | /** @var xmlrpc_client $client */ |
||
12 | public $client = null; |
||
13 | protected $timeout = 10; |
||
14 | |||
15 | public function set_up() |
||
16 | { |
||
17 | parent::set_up(); |
||
18 | |||
19 | $this->client = $this->getClient(); |
||
20 | } |
||
21 | |||
22 | public function test404() |
||
23 | { |
||
24 | $this->client->path = '/NOTEXIST.php'; |
||
25 | |||
26 | $m = new xmlrpcmsg('examples.echo', array( |
||
27 | new xmlrpcval('hello', 'string'), |
||
28 | )); |
||
29 | $r = $this->client->send($m, $this->timeout); |
||
30 | $this->assertEquals(5, $r->faultCode()); |
||
31 | } |
||
32 | |||
33 | public function test404Interop() |
||
34 | { |
||
35 | $this->client->path = '/NOTEXIST.php'; |
||
36 | |||
37 | $m = new xmlrpcmsg('examples.echo', array( |
||
38 | new xmlrpcval('hello', 'string'), |
||
39 | )); |
||
40 | $orig = \PhpXmlRpc\PhpXmlRpc::$xmlrpcerr; |
||
41 | \PhpXmlRpc\PhpXmlRpc::useInteropFaults(); |
||
42 | $r = $this->client->send($m, $this->timeout); |
||
43 | $this->assertEquals(-32300, $r->faultCode()); |
||
44 | /// @todo reset this via tear_down |
||
45 | \PhpXmlRpc\PhpXmlRpc::$xmlrpcerr = $orig; |
||
46 | } |
||
47 | |||
48 | public function testUnsupportedAuth() |
||
49 | { |
||
50 | $m = new xmlrpcmsg('examples.echo', array( |
||
51 | new xmlrpcval('hello', 'string'), |
||
52 | )); |
||
53 | $this->client->setOption(\PhpXmlRpc\Client::OPT_USERNAME, 'user'); |
||
54 | $this->client->setOption(\PhpXmlRpc\Client::OPT_AUTH_TYPE, 2); |
||
55 | $this->client->setOption(\PhpXmlRpc\Client::OPT_USE_CURL, \PhpXmlRpc\Client::USE_CURL_NEVER); |
||
56 | $r = $this->client->send($m); |
||
57 | $this->assertEquals(\PhpXmlRpc\PhpXmlRpc::$xmlrpcerr['unsupported_option'], $r->faultCode()); |
||
58 | } |
||
59 | |||
60 | public function testSrvNotFound() |
||
61 | { |
||
62 | $this->client->server .= 'XXX'; |
||
63 | $dnsinfo = @dns_get_record($this->client->server); |
||
64 | if ($dnsinfo) { |
||
65 | $this->markTestSkipped('Seems like there is a catchall DNS in effect: host ' . $this->client->server . ' found'); |
||
66 | } else { |
||
67 | $m = new xmlrpcmsg('examples.echo', array( |
||
68 | new xmlrpcval('hello', 'string'), |
||
69 | )); |
||
70 | $r = $this->client->send($m, $this->timeout); |
||
71 | // make sure there's no freaking catchall DNS in effect |
||
72 | $this->assertEquals(5, $r->faultCode()); |
||
73 | } |
||
74 | } |
||
75 | |||
76 | public function testCurlKAErr() |
||
77 | { |
||
78 | if (!function_exists('curl_init')) { |
||
79 | $this->markTestSkipped('CURL missing: cannot test curl keepalive errors'); |
||
80 | } |
||
81 | |||
82 | $m = new xmlrpcmsg('examples.stringecho', array( |
||
83 | new xmlrpcval('hello', 'string'), |
||
84 | )); |
||
85 | // test 2 calls w. keepalive: 1st time connection ko, second time ok |
||
86 | $this->client->server .= 'XXX'; |
||
87 | $this->client->keepalive = true; |
||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||
88 | $r = $this->client->send($m, $this->timeout, 'http11'); |
||
89 | // in case we have a "universal dns resolver" getting in the way, we might get a 302 instead of a 404 |
||
90 | $this->assertTrue($r->faultCode() === 8 || $r->faultCode() == 5); |
||
91 | |||
92 | // now test a successful connection |
||
93 | $server = explode(':', $this->args['HTTPSERVER']); |
||
94 | if (count($server) > 1) { |
||
95 | $this->client->port = $server[1]; |
||
0 ignored issues
–
show
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;
![]() |
|||
96 | } |
||
97 | $this->client->server = $server[0]; |
||
98 | //$this->client->path = $this->args['HTTPURI']; |
||
99 | //$this->client->setCookie('PHPUNIT_RANDOM_TEST_ID', static::$randId); |
||
100 | $r = $this->client->send($m, $this->timeout, 'http11'); |
||
101 | $this->assertEquals(0, $r->faultCode()); |
||
102 | $ro = $r->value(); |
||
103 | is_object($ro) && $this->assertEquals('hello', $ro->scalarVal()); |
||
104 | } |
||
105 | |||
106 | /** |
||
107 | * @dataProvider getAvailableUseCurlOptions |
||
108 | */ |
||
109 | public function testCustomHeaders($curlOpt) |
||
110 | { |
||
111 | $this->client->setOption(\PhpXmlRpc\Client::OPT_USE_CURL, $curlOpt); |
||
112 | $this->client->setOption(\PhpXmlRpc\Client::OPT_EXTRA_HEADERS, array('X-PXR-Test: yes')); |
||
113 | $r = new \PhpXmlRpc\Request('tests.getallheaders'); |
||
114 | $r = $this->client->send($r); |
||
115 | $this->assertEquals(0, $r->faultCode()); |
||
116 | $ro = $r->value(); |
||
117 | $this->assertArrayHasKey('X-Pxr-Test', $ro->scalarVal(), "Testing with curl mode: $curlOpt"); |
||
118 | } |
||
119 | |||
120 | /// @todo add more permutations, eg. check that PHP_URL_SCHEME is ok with http10, http11, h2 etc... |
||
121 | public function testGetUrl() |
||
122 | { |
||
123 | $m = $this->client->getUrl(PHP_URL_SCHEME); |
||
124 | $this->assertEquals($m, $this->client->method); |
||
125 | $h = $this->client->getUrl(PHP_URL_HOST); |
||
126 | $this->assertEquals($h, $this->client->server); |
||
127 | $p = $this->client->getUrl(PHP_URL_PORT); |
||
128 | $this->assertEquals($p, $this->client->port); |
||
129 | $p = $this->client->getUrl(PHP_URL_PATH); |
||
130 | $this->assertEquals($p, $this->client->path); |
||
131 | } |
||
132 | } |
||
133 |