Skip to content

Commit fc8ac8c

Browse files
committed
tests refactoring
1 parent 573db6e commit fc8ac8c

File tree

3 files changed

+47
-31
lines changed

3 files changed

+47
-31
lines changed

tests/07ClientTest.php

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ public function set_up()
1414
{
1515
parent::set_up();
1616

17-
$this->client = new xmlrpc_client('/NOTEXIST.php', $this->args['HTTPSERVER'], 80);
18-
$this->client->setDebug($this->args['DEBUG']);
17+
$this->client = $this->getClient();
1918
}
2019

2120
public function test404()
2221
{
22+
$this->client->path = '/NOTEXIST.php';
23+
2324
$m = new xmlrpcmsg('examples.echo', array(
2425
new xmlrpcval('hello', 'string'),
2526
));
@@ -29,6 +30,8 @@ public function test404()
2930

3031
public function test404Interop()
3132
{
33+
$this->client->path = '/NOTEXIST.php';
34+
3235
$m = new xmlrpcmsg('examples.echo', array(
3336
new xmlrpcval('hello', 'string'),
3437
));
@@ -53,14 +56,14 @@ public function testUnsupportedAuth()
5356

5457
public function testSrvNotFound()
5558
{
56-
$m = new xmlrpcmsg('examples.echo', array(
57-
new xmlrpcval('hello', 'string'),
58-
));
5959
$this->client->server .= 'XXX';
6060
$dnsinfo = @dns_get_record($this->client->server);
6161
if ($dnsinfo) {
6262
$this->markTestSkipped('Seems like there is a catchall DNS in effect: host ' . $this->client->server . ' found');
6363
} else {
64+
$m = new xmlrpcmsg('examples.echo', array(
65+
new xmlrpcval('hello', 'string'),
66+
));
6467
$r = $this->client->send($m, 5);
6568
// make sure there's no freaking catchall DNS in effect
6669
$this->assertEquals(5, $r->faultCode());
@@ -90,32 +93,37 @@ public function testCurlKAErr()
9093
$this->client->port = $server[1];
9194
}
9295
$this->client->server = $server[0];
93-
$this->client->path = $this->args['HTTPURI'];
94-
$this->client->setCookie('PHPUNIT_RANDOM_TEST_ID', static::$randId);
96+
//$this->client->path = $this->args['HTTPURI'];
97+
//$this->client->setCookie('PHPUNIT_RANDOM_TEST_ID', static::$randId);
9598
$r = $this->client->send($m, 5, 'http11');
9699
$this->assertEquals(0, $r->faultCode());
97100
$ro = $r->value();
98101
is_object($ro) && $this->assertEquals('hello', $ro->scalarVal());
99102
}
100103

101-
public function testCustomHeaders()
104+
/**
105+
* @dataProvider getAvailableUseCurlOptions
106+
*/
107+
public function testCustomHeaders($curlOpt)
108+
{
109+
$this->client->setOption(\PhpXmlRpc\Client::OPT_USE_CURL, $curlOpt);
110+
$this->client->setOption(\PhpXmlRpc\Client::OPT_EXTRA_HEADERS, array('X-PXR-Test: yes'));
111+
$r = new \PhpXmlRpc\Request('tests.getallheaders');
112+
$r = $this->client->send($r);
113+
$this->assertEquals(0, $r->faultCode());
114+
$ro = $r->value();
115+
$this->assertArrayHasKey('X-Pxr-Test', $ro->scalarVal(), "Testing with curl mode: $curlOpt");
116+
}
117+
118+
public function getAvailableUseCurlOptions()
102119
{
103120
$opts = array(\PhpXmlRpc\Client::USE_CURL_NEVER);
104121
if (function_exists('curl_init'))
105122
{
106123
$opts[] = \PhpXmlRpc\Client::USE_CURL_ALWAYS;
107124
}
108125

109-
$this->client->setOption(\PhpXmlRpc\Client::OPT_EXTRA_HEADERS, array('X-PXR-Test: yes'));
110-
$r = new \PhpXmlRpc\Request('tests.getallheaders');
111-
112-
foreach ($opts as $opt) {
113-
$this->client->setOption(\PhpXmlRpc\Client::OPT_USE_CURL, $opt);
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: $opt");
118-
}
126+
return array($opts);
119127
}
120128

121129
public function testgetUrl()

tests/08ServerTest.php

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,10 @@ public function set_up()
4444
{
4545
parent::set_up();
4646

47-
$server = explode(':', $this->args['HTTPSERVER']);
48-
if (count($server) > 1) {
49-
$this->client = new xmlrpc_client($this->args['HTTPURI'], $server[0], $server[1]);
50-
} else {
51-
$this->client = new xmlrpc_client($this->args['HTTPURI'], $this->args['HTTPSERVER']);
52-
}
47+
$this->client = $this->getClient();
5348

54-
$this->client->setDebug($this->args['DEBUG']);
5549
$this->client->request_compression = $this->request_compression;
5650
$this->client->accepted_compression = $this->accepted_compression;
57-
58-
$this->client->setCookie('PHPUNIT_RANDOM_TEST_ID', static::$randId);
59-
60-
if ($this->collectCodeCoverageInformation) {
61-
$this->client->setCookie('PHPUNIT_SELENIUM_TEST_ID', $this->testId);
62-
}
6351
}
6452

6553
/**

tests/ServerAwareTestCase.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,24 @@ public function set_up()
8282
$this->baseUrl = 'http://' . $this->args['HTTPSERVER'] . preg_replace('|\?.+|', '', $this->args['HTTPURI']);
8383
$this->coverageScriptUrl = 'http://' . $this->args['HTTPSERVER'] . preg_replace('|/tests/index\.php(\?.*)?|', '/tests/phpunit_coverage.php', $this->args['HTTPURI']);
8484
}
85+
86+
protected function getClient($customPath)
87+
{
88+
$server = explode(':', $this->args['HTTPSERVER']);
89+
if (count($server) > 1) {
90+
$client = new xmlrpc_client($this->args['HTTPURI'], $server[0], $server[1]);
91+
} else {
92+
$client = new xmlrpc_client($this->args['HTTPURI'], $this->args['HTTPSERVER']);
93+
}
94+
95+
$client->setDebug($this->args['DEBUG']);
96+
97+
$client->setCookie('PHPUNIT_RANDOM_TEST_ID', static::$randId);
98+
99+
if ($this->collectCodeCoverageInformation) {
100+
$client->setCookie('PHPUNIT_SELENIUM_TEST_ID', $this->testId);
101+
}
102+
103+
return $client;
104+
}
85105
}

0 commit comments

Comments
 (0)