From fc8ac8c23808db844d80a3cb94b75449d874765a Mon Sep 17 00:00:00 2001 From: gggeek Date: Sat, 7 Sep 2024 14:18:25 +0000 Subject: [PATCH] tests refactoring --- tests/07ClientTest.php | 44 +++++++++++++++++++++-------------- tests/08ServerTest.php | 14 +---------- tests/ServerAwareTestCase.php | 20 ++++++++++++++++ 3 files changed, 47 insertions(+), 31 deletions(-) diff --git a/tests/07ClientTest.php b/tests/07ClientTest.php index 4288c31d..3a56b9c9 100644 --- a/tests/07ClientTest.php +++ b/tests/07ClientTest.php @@ -14,12 +14,13 @@ class ClientTest extends PhpXmlRpc_ServerAwareTestCase { 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'), )); @@ -29,6 +30,8 @@ class ClientTest extends PhpXmlRpc_ServerAwareTestCase public function test404Interop() { + $this->client->path = '/NOTEXIST.php'; + $m = new xmlrpcmsg('examples.echo', array( new xmlrpcval('hello', 'string'), )); @@ -53,14 +56,14 @@ class ClientTest extends PhpXmlRpc_ServerAwareTestCase 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()); @@ -90,15 +93,29 @@ class ClientTest extends PhpXmlRpc_ServerAwareTestCase $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')) @@ -106,16 +123,7 @@ class ClientTest extends PhpXmlRpc_ServerAwareTestCase $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() diff --git a/tests/08ServerTest.php b/tests/08ServerTest.php index 074e2492..002e2b03 100644 --- a/tests/08ServerTest.php +++ b/tests/08ServerTest.php @@ -44,22 +44,10 @@ class ServerTest extends PhpXmlRpc_ServerAwareTestCase { 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); - } } /** diff --git a/tests/ServerAwareTestCase.php b/tests/ServerAwareTestCase.php index a559ddca..e82f0e09 100644 --- a/tests/ServerAwareTestCase.php +++ b/tests/ServerAwareTestCase.php @@ -82,4 +82,24 @@ abstract class PhpXmlRpc_ServerAwareTestCase extends PhpXmlRpc_LoggerAwareTestCa $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; + } } -- 2.47.0