Explorar el Código

[tests] Fix base test case class to handle required Redis versions.

This change is needed due to some internal changes in one of the
latest minor releases of PHPUnit 4.x that essentially broke how we
were checking for the required Redis version from method annotations.
Daniele Alessandri hace 10 años
padre
commit
5cd4f41424
Se han modificado 1 ficheros con 17 adiciones y 25 borrados
  1. 17 25
      tests/PHPUnit/PredisTestCase.php

+ 17 - 25
tests/PHPUnit/PredisTestCase.php

@@ -256,7 +256,7 @@ abstract class PredisTestCase extends \PHPUnit_Framework_TestCase
     /**
      *
      */
-    protected function setRequiredRedisVersionFromAnnotation()
+    protected function getRequiredRedisServerVersion()
     {
         $annotations = $this->getAnnotations();
 
@@ -264,49 +264,41 @@ abstract class PredisTestCase extends \PHPUnit_Framework_TestCase
             !empty($annotations['method']['requiresRedisVersion']) &&
             in_array('connected', $annotations['method']['group'])
         ) {
-            $this->predisRequirements['requiresRedisVersion'] = $annotations['method']['requiresRedisVersion'][0];
+            return $annotations['method']['requiresRedisVersion'][0];
         }
+
+        return null;
     }
 
     /**
      *
      */
-    protected function checkRequiredRedisVersion()
+    protected function checkRequiredRedisServerVersion()
     {
-        if (!isset($this->predisRequirements['requiresRedisVersion'])) {
+        if (!$requiredVersion = $this->getRequiredRedisServerVersion()) {
             return;
         }
 
-        $srvVersion = $this->getRedisServerVersion();
-        $expectation = explode(' ', $this->predisRequirements['requiresRedisVersion'], 2);
+        $serverVersion = $this->getRedisServerVersion();
+        $requiredVersion = explode(' ', $requiredVersion, 2);
 
-        if (count($expectation) === 1) {
-            $expOperator = '>=';
-            $expVersion = $expectation[0];
+        if (count($requiredVersion) === 1) {
+            $reqOperator = '>=';
+            $reqVersion = $requiredVersion[0];
         } else {
-            $expOperator = $expectation[0];
-            $expVersion = $expectation[1];
+            $reqOperator = $requiredVersion[0];
+            $reqVersion = $requiredVersion[1];
         }
 
-        $comparation = version_compare($srvVersion, $expVersion);
+        $comparation = version_compare($serverVersion, $reqVersion);
 
-        if (!$match = eval("return $comparation $expOperator 0;")) {
+        if (!$match = eval("return $comparation $reqOperator 0;")) {
             $this->markTestSkipped(
-                "This test requires Redis $expOperator $expVersion but the current version is $srvVersion."
+                "This test requires Redis $reqOperator $reqVersion but the current version is $serverVersion."
             );
         }
     }
 
-    /**
-     * {@inheritdoc}
-     */
-    protected function setRequirementsFromAnnotation()
-    {
-        parent::setRequirementsFromAnnotation();
-
-        $this->setRequiredRedisVersionFromAnnotation();
-    }
-
     /**
      * {@inheritdoc}
      */
@@ -314,6 +306,6 @@ abstract class PredisTestCase extends \PHPUnit_Framework_TestCase
     {
         parent::checkRequirements();
 
-        $this->checkRequiredRedisVersion();
+        $this->checkRequiredRedisServerVersion();
     }
 }