Add a new test for verify_compat.php, refactor some test classes
authorgggeek <giunta.gaetano@gmail.com>
Tue, 7 Apr 2015 11:03:03 +0000 (12:03 +0100)
committergggeek <giunta.gaetano@gmail.com>
Tue, 7 Apr 2015 11:03:03 +0000 (12:03 +0100)
tests/5DemofilesTest.php
tests/6DebuggerTest.php
tests/7ExtraTest.php [new file with mode: 0644]
tests/LocalFileTestCase.php [new file with mode: 0644]
tests/parse_args.php

index 4e79053..63708fe 100644 (file)
@@ -1,46 +1,9 @@
 <?php
 
-include_once __DIR__ . '/parse_args.php';
+include_once __DIR__ . '/LocalFileTestCase.php';
 
-class DemoFilesTest extends PHPUnit_Framework_TestCase
+class DemoFilesTest extends PhpXmlRpc_LocalFileTestCase
 {
-    public $args = array();
-
-    protected $baseUrl;
-
-    protected $testId;
-    /** @var boolean $collectCodeCoverageInformation */
-    protected $collectCodeCoverageInformation;
-    protected $coverageScriptUrl;
-
-    public function run(PHPUnit_Framework_TestResult $result = NULL)
-    {
-        $this->testId = get_class($this) . '__' . $this->getName();
-
-        if ($result === NULL) {
-            $result = $this->createResult();
-        }
-
-        $this->collectCodeCoverageInformation = $result->getCollectCodeCoverageInformation();
-
-        parent::run($result);
-
-        if ($this->collectCodeCoverageInformation) {
-            $coverage = new PHPUnit_Extensions_SeleniumCommon_RemoteCoverage(
-                $this->coverageScriptUrl,
-                $this->testId
-            );
-            $result->getCodeCoverage()->append(
-                $coverage->get(), $this
-            );
-        }
-
-        // do not call this before to give the time to the Listeners to run
-        //$this->getStrategy()->endOfTest($this->session);
-
-        return $result;
-    }
-
     public function setUp()
     {
         $this->args = argParser::getArgs();
@@ -50,39 +13,6 @@ class DemoFilesTest extends PHPUnit_Framework_TestCase
         $this->coverageScriptUrl = 'http://' . $this->args['LOCALSERVER'] . '/' . str_replace( '/demo/server/server.php', 'tests/phpunit_coverage.php', $this->args['URI'] );
     }
 
-    protected function request($file, $method = 'GET', $payload = '')
-    {
-        $url = $this->baseUrl . $file;
-
-        $ch = curl_init($url);
-        curl_setopt_array($ch, array(
-            CURLOPT_RETURNTRANSFER => true,
-            CURLOPT_FAILONERROR => true
-        ));
-        if ($method == 'POST')
-        {
-            curl_setopt_array($ch, array(
-                CURLOPT_POST => true,
-                CURLOPT_POSTFIELDS => $payload
-            ));
-        }
-        if ($this->collectCodeCoverageInformation)
-        {
-            curl_setopt($ch, CURLOPT_COOKIE, 'PHPUNIT_SELENIUM_TEST_ID=true');
-        }
-        if ($this->args['DEBUG'] > 0) {
-            curl_setopt($ch, CURLOPT_VERBOSE, 1);
-        }
-        $page = curl_exec($ch);
-        curl_close($ch);
-
-        $this->assertNotFalse($page);
-        $this->assertNotContains('Fatal error', $page);
-        $this->assertNotContains('Notice:', $page);
-
-        return $page;
-    }
-
     public function testAgeSort()
     {
         $page = $this->request('client/agesort.php');
index f002180..db0e850 100644 (file)
@@ -1,46 +1,9 @@
 <?php
 
-include_once __DIR__ . '/parse_args.php';
+include_once __DIR__ . '/LocalFileTestCase.php';
 
-class DebuggerTest extends PHPUnit_Framework_TestCase
+class DebuggerTest extends PhpXmlRpc_LocalFileTestCase
 {
-    public $args = array();
-
-    protected $baseUrl;
-
-    protected $testId;
-    /** @var boolean $collectCodeCoverageInformation */
-    protected $collectCodeCoverageInformation;
-    protected $coverageScriptUrl;
-
-    public function run(PHPUnit_Framework_TestResult $result = NULL)
-    {
-        $this->testId = get_class($this) . '__' . $this->getName();
-
-        if ($result === NULL) {
-            $result = $this->createResult();
-        }
-
-        $this->collectCodeCoverageInformation = $result->getCollectCodeCoverageInformation();
-
-        parent::run($result);
-
-        if ($this->collectCodeCoverageInformation) {
-            $coverage = new PHPUnit_Extensions_SeleniumCommon_RemoteCoverage(
-                $this->coverageScriptUrl,
-                $this->testId
-            );
-            $result->getCodeCoverage()->append(
-                $coverage->get(), $this
-            );
-        }
-
-        // do not call this before to give the time to the Listeners to run
-        //$this->getStrategy()->endOfTest($this->session);
-
-        return $result;
-    }
-
     public function setUp()
     {
         $this->args = argParser::getArgs();
@@ -50,39 +13,6 @@ class DebuggerTest extends PHPUnit_Framework_TestCase
         $this->coverageScriptUrl = 'http://' . $this->args['LOCALSERVER'] . '/' . str_replace( '/demo/server/server.php', 'tests/phpunit_coverage.php', $this->args['URI'] );
     }
 
-    protected function request($file, $method = 'GET', $payload = '')
-    {
-        $url = $this->baseUrl . $file;
-
-        $ch = curl_init($url);
-        curl_setopt_array($ch, array(
-            CURLOPT_RETURNTRANSFER => true,
-            CURLOPT_FAILONERROR => true
-        ));
-        if ($method == 'POST')
-        {
-            curl_setopt_array($ch, array(
-                CURLOPT_POST => true,
-                CURLOPT_POSTFIELDS => $payload
-            ));
-        }
-        if ($this->collectCodeCoverageInformation)
-        {
-            curl_setopt($ch, CURLOPT_COOKIE, 'PHPUNIT_SELENIUM_TEST_ID=true');
-        }
-        if ($this->args['DEBUG'] > 0) {
-            curl_setopt($ch, CURLOPT_VERBOSE, 1);
-        }
-        $page = curl_exec($ch);
-        curl_close($ch);
-
-        $this->assertNotFalse($page);
-        $this->assertNotContains('Fatal error', $page);
-        $this->assertNotContains('Notice:', $page);
-
-        return $page;
-    }
-
     public function testIndex()
     {
         $page = $this->request('index.php');
diff --git a/tests/7ExtraTest.php b/tests/7ExtraTest.php
new file mode 100644 (file)
index 0000000..ff2d056
--- /dev/null
@@ -0,0 +1,21 @@
+<?php
+
+include_once __DIR__ . '/LocalFileTestCase.php';
+
+class ExtraTest extends PhpXmlRpc_LocalFileTestCase
+{
+
+    public function setUp()
+    {
+        $this->args = argParser::getArgs();
+
+        $this->baseUrl = $this->args['LOCALSERVER'] . str_replace( '/demo/server/server.php', '/tests/', $this->args['URI'] );
+
+        $this->coverageScriptUrl = 'http://' . $this->args['LOCALSERVER'] . '/' . str_replace( '/demo/server/server.php', 'tests/phpunit_coverage.php', $this->args['URI'] );
+    }
+
+    public function testVerifyCompat()
+    {
+        $page = $this->request('verify_compat.php');
+    }
+}
\ No newline at end of file
diff --git a/tests/LocalFileTestCase.php b/tests/LocalFileTestCase.php
new file mode 100644 (file)
index 0000000..688e0df
--- /dev/null
@@ -0,0 +1,77 @@
+<?php
+
+include_once __DIR__ . '/parse_args.php';
+
+abstract class PhpXmlRpc_LocalFileTestCase extends PHPUnit_Framework_TestCase
+{
+    public $args = array();
+
+    protected $baseUrl;
+
+    protected $testId;
+    /** @var boolean $collectCodeCoverageInformation */
+    protected $collectCodeCoverageInformation;
+    protected $coverageScriptUrl;
+
+    public function run(PHPUnit_Framework_TestResult $result = NULL)
+    {
+        $this->testId = get_class($this) . '__' . $this->getName();
+
+        if ($result === NULL) {
+            $result = $this->createResult();
+        }
+
+        $this->collectCodeCoverageInformation = $result->getCollectCodeCoverageInformation();
+
+        parent::run($result);
+
+        if ($this->collectCodeCoverageInformation) {
+            $coverage = new PHPUnit_Extensions_SeleniumCommon_RemoteCoverage(
+                $this->coverageScriptUrl,
+                $this->testId
+            );
+            $result->getCodeCoverage()->append(
+                $coverage->get(), $this
+            );
+        }
+
+        // do not call this before to give the time to the Listeners to run
+        //$this->getStrategy()->endOfTest($this->session);
+
+        return $result;
+    }
+
+    protected function request($file, $method = 'GET', $payload = '')
+    {
+        $url = $this->baseUrl . $file;
+
+        $ch = curl_init($url);
+        curl_setopt_array($ch, array(
+            CURLOPT_RETURNTRANSFER => true,
+            CURLOPT_FAILONERROR => true
+        ));
+        if ($method == 'POST')
+        {
+            curl_setopt_array($ch, array(
+                CURLOPT_POST => true,
+                CURLOPT_POSTFIELDS => $payload
+            ));
+        }
+        if ($this->collectCodeCoverageInformation)
+        {
+            curl_setopt($ch, CURLOPT_COOKIE, 'PHPUNIT_SELENIUM_TEST_ID=true');
+        }
+        if ($this->args['DEBUG'] > 0) {
+            curl_setopt($ch, CURLOPT_VERBOSE, 1);
+        }
+        $page = curl_exec($ch);
+        curl_close($ch);
+
+        $this->assertNotFalse($page);
+        $this->assertNotContains('Fatal error', $page);
+        $this->assertNotContains('Notice:', $page);
+
+        return $page;
+    }
+
+}
index b2e438e..6660b9e 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 
 /**
- * Common parameter parsing for benchmarks and tests scripts.
+ * Common parameter parsing for benchmark and tests scripts.
  *
  * @param integer DEBUG
  * @param string  LOCALSERVER