merge upstream phpxmlrpc
[plcapi.git] / php / phpxmlrpc / tests / WebTestCase.php
similarity index 62%
rename from php/phpxmlrpc/tests/LocalFileTestCase.php
rename to php/phpxmlrpc/tests/WebTestCase.php
index 59818c8..f4818b3 100644 (file)
@@ -2,7 +2,11 @@
 
 include_once __DIR__ . '/parse_args.php';
 
-abstract class PhpXmlRpc_LocalFileTestCase extends PHPUnit_Framework_TestCase
+include_once __DIR__ . '/PolyfillTestCase.php';
+
+use PHPUnit\Extensions\SeleniumCommon\RemoteCoverage;
+
+abstract class PhpXmlRpc_WebTestCase extends PhpXmlRpc_PolyfillTestCase
 {
     public $args = array();
 
@@ -13,7 +17,13 @@ abstract class PhpXmlRpc_LocalFileTestCase extends PHPUnit_Framework_TestCase
     protected $collectCodeCoverageInformation;
     protected $coverageScriptUrl;
 
-    public function run(PHPUnit_Framework_TestResult $result = NULL)
+    /**
+     * Reimplemented to allow us to collect code coverage info for the target php files executed via an http request.
+     * Code taken from PHPUnit_Extensions_Selenium2TestCase
+     *
+     * @todo instead of overriding run via _run, try to achieve this by implementing Yoast\PHPUnitPolyfills\TestListeners\TestListenerDefaultImplementation
+     */
+    public function _run($result = NULL)
     {
         $this->testId = get_class($this) . '__' . $this->getName();
 
@@ -23,10 +33,10 @@ abstract class PhpXmlRpc_LocalFileTestCase extends PHPUnit_Framework_TestCase
 
         $this->collectCodeCoverageInformation = $result->getCollectCodeCoverageInformation();
 
-        parent::run($result);
+        parent::_run($result);
 
         if ($this->collectCodeCoverageInformation) {
-            $coverage = new PHPUnit_Extensions_SeleniumCommon_RemoteCoverage(
+            $coverage = new RemoteCoverage(
                 $this->coverageScriptUrl,
                 $this->testId
             );
@@ -41,9 +51,16 @@ abstract class PhpXmlRpc_LocalFileTestCase extends PHPUnit_Framework_TestCase
         return $result;
     }
 
-    protected function request($file, $method = 'GET', $payload = '', $emptyPageOk = false)
+    /**
+     * @param string $path
+     * @param string $method
+     * @param string $payload
+     * @param false $emptyPageOk
+     * @return bool|string
+     */
+    protected function request($path, $method = 'GET', $payload = '', $emptyPageOk = false)
     {
-        $url = $this->baseUrl . $file;
+        $url = $this->baseUrl . $path;
 
         $ch = curl_init($url);
         curl_setopt_array($ch, array(
@@ -59,7 +76,7 @@ abstract class PhpXmlRpc_LocalFileTestCase extends PHPUnit_Framework_TestCase
         }
         if ($this->collectCodeCoverageInformation)
         {
-            curl_setopt($ch, CURLOPT_COOKIE, 'PHPUNIT_SELENIUM_TEST_ID=true');
+            curl_setopt($ch, CURLOPT_COOKIE, 'PHPUNIT_SELENIUM_TEST_ID='.$this->testId);
         }
         if ($this->args['DEBUG'] > 0) {
             curl_setopt($ch, CURLOPT_VERBOSE, 1);
@@ -71,10 +88,9 @@ abstract class PhpXmlRpc_LocalFileTestCase extends PHPUnit_Framework_TestCase
         if (!$emptyPageOk) {
             $this->assertNotEquals('', $page);
         }
-        $this->assertNotContains('Fatal error', $page);
-        $this->assertNotContains('Notice:', $page);
+        $this->assertStringNotContainsStringIgnoringCase('Fatal error', $page);
+        $this->assertStringNotContainsStringIgnoringCase('Notice:', $page);
 
         return $page;
     }
-
 }