tests refactoring
authorgggeek <giunta.gaetano@gmail.com>
Sat, 7 Sep 2024 14:18:25 +0000 (14:18 +0000)
committergggeek <giunta.gaetano@gmail.com>
Sat, 7 Sep 2024 14:18:25 +0000 (14:18 +0000)
tests/07ClientTest.php
tests/08ServerTest.php
tests/ServerAwareTestCase.php

index 4288c31..3a56b9c 100644 (file)
@@ -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()
index 074e249..002e2b0 100644 (file)
@@ -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);
-        }
     }
 
     /**
index a559ddc..e82f0e0 100644 (file)
@@ -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;
+    }
 }