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