Skip to content

Commit

Permalink
tests refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
gggeek committed Sep 7, 2024
1 parent 573db6e commit fc8ac8c
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 31 deletions.
44 changes: 26 additions & 18 deletions tests/07ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ public function set_up()
{
parent::set_up();

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

public function test404()
{
$this->client->path = '/NOTEXIST.php';

$m = new xmlrpcmsg('examples.echo', array(
new xmlrpcval('hello', 'string'),
));
Expand All @@ -29,6 +30,8 @@ public function test404()

public function test404Interop()
{
$this->client->path = '/NOTEXIST.php';

$m = new xmlrpcmsg('examples.echo', array(
new xmlrpcval('hello', 'string'),
));
Expand All @@ -53,14 +56,14 @@ public function testUnsupportedAuth()

public function testSrvNotFound()
{
$m = new xmlrpcmsg('examples.echo', array(
new xmlrpcval('hello', 'string'),
));
$this->client->server .= 'XXX';
$dnsinfo = @dns_get_record($this->client->server);
if ($dnsinfo) {
$this->markTestSkipped('Seems like there is a catchall DNS in effect: host ' . $this->client->server . ' found');
} else {
$m = new xmlrpcmsg('examples.echo', array(
new xmlrpcval('hello', 'string'),
));
$r = $this->client->send($m, 5);
// make sure there's no freaking catchall DNS in effect
$this->assertEquals(5, $r->faultCode());
Expand Down Expand Up @@ -90,32 +93,37 @@ public function testCurlKAErr()
$this->client->port = $server[1];
}
$this->client->server = $server[0];
$this->client->path = $this->args['HTTPURI'];
$this->client->setCookie('PHPUNIT_RANDOM_TEST_ID', static::$randId);
//$this->client->path = $this->args['HTTPURI'];
//$this->client->setCookie('PHPUNIT_RANDOM_TEST_ID', static::$randId);
$r = $this->client->send($m, 5, 'http11');
$this->assertEquals(0, $r->faultCode());
$ro = $r->value();
is_object($ro) && $this->assertEquals('hello', $ro->scalarVal());
}

public function testCustomHeaders()
/**
* @dataProvider getAvailableUseCurlOptions
*/
public function testCustomHeaders($curlOpt)
{
$this->client->setOption(\PhpXmlRpc\Client::OPT_USE_CURL, $curlOpt);
$this->client->setOption(\PhpXmlRpc\Client::OPT_EXTRA_HEADERS, array('X-PXR-Test: yes'));
$r = new \PhpXmlRpc\Request('tests.getallheaders');
$r = $this->client->send($r);
$this->assertEquals(0, $r->faultCode());
$ro = $r->value();
$this->assertArrayHasKey('X-Pxr-Test', $ro->scalarVal(), "Testing with curl mode: $curlOpt");
}

public function getAvailableUseCurlOptions()
{
$opts = array(\PhpXmlRpc\Client::USE_CURL_NEVER);
if (function_exists('curl_init'))
{
$opts[] = \PhpXmlRpc\Client::USE_CURL_ALWAYS;
}

$this->client->setOption(\PhpXmlRpc\Client::OPT_EXTRA_HEADERS, array('X-PXR-Test: yes'));
$r = new \PhpXmlRpc\Request('tests.getallheaders');

foreach ($opts as $opt) {
$this->client->setOption(\PhpXmlRpc\Client::OPT_USE_CURL, $opt);
$r = $this->client->send($r);
$this->assertEquals(0, $r->faultCode());
$ro = $r->value();
$this->assertArrayHasKey('X-Pxr-Test', $ro->scalarVal(), "Testing with curl mode: $opt");
}
return array($opts);
}

public function testgetUrl()
Expand Down
14 changes: 1 addition & 13 deletions tests/08ServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,10 @@ public function set_up()
{
parent::set_up();

$server = explode(':', $this->args['HTTPSERVER']);
if (count($server) > 1) {
$this->client = new xmlrpc_client($this->args['HTTPURI'], $server[0], $server[1]);
} else {
$this->client = new xmlrpc_client($this->args['HTTPURI'], $this->args['HTTPSERVER']);
}
$this->client = $this->getClient();

$this->client->setDebug($this->args['DEBUG']);
$this->client->request_compression = $this->request_compression;
$this->client->accepted_compression = $this->accepted_compression;

$this->client->setCookie('PHPUNIT_RANDOM_TEST_ID', static::$randId);

if ($this->collectCodeCoverageInformation) {
$this->client->setCookie('PHPUNIT_SELENIUM_TEST_ID', $this->testId);
}
}

/**
Expand Down
20 changes: 20 additions & 0 deletions tests/ServerAwareTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,24 @@ public function set_up()
$this->baseUrl = 'http://' . $this->args['HTTPSERVER'] . preg_replace('|\?.+|', '', $this->args['HTTPURI']);
$this->coverageScriptUrl = 'http://' . $this->args['HTTPSERVER'] . preg_replace('|/tests/index\.php(\?.*)?|', '/tests/phpunit_coverage.php', $this->args['HTTPURI']);
}

protected function getClient($customPath)
{
$server = explode(':', $this->args['HTTPSERVER']);
if (count($server) > 1) {
$client = new xmlrpc_client($this->args['HTTPURI'], $server[0], $server[1]);
} else {
$client = new xmlrpc_client($this->args['HTTPURI'], $this->args['HTTPSERVER']);
}

$client->setDebug($this->args['DEBUG']);

$client->setCookie('PHPUNIT_RANDOM_TEST_ID', static::$randId);

if ($this->collectCodeCoverageInformation) {
$client->setCookie('PHPUNIT_SELENIUM_TEST_ID', $this->testId);
}

return $client;
}
}

0 comments on commit fc8ac8c

Please sign in to comment.