Преглед изворни кода

[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.

Conflicts:
	tests/PHPUnit/PredisTestCase.php
Daniele Alessandri пре 9 година
родитељ
комит
192dfd61e5
1 измењених фајлова са 17 додато и 25 уклоњено
  1. 17 25
      tests/PHPUnit/PredisTestCase.php

+ 17 - 25
tests/PHPUnit/PredisTestCase.php

@@ -244,7 +244,7 @@ abstract class PredisTestCase extends PHPUnit_Framework_TestCase
     /**
      *
      */
-    protected function setRequiredRedisVersionFromAnnotation()
+    protected function getRequiredRedisServerVersion()
     {
         $annotations = $this->getAnnotations();
 
@@ -252,49 +252,41 @@ abstract class PredisTestCase extends PHPUnit_Framework_TestCase
             !empty($annotations['method']['requiresRedisVersion']) &&
             in_array('connected', $annotations['method']['group'])
         ) {
-            $this->required['requiresRedisVersion'] = $annotations['method']['requiresRedisVersion'][0];
+            return $annotations['method']['requiresRedisVersion'][0];
         }
+
+        return null;
     }
 
     /**
      *
      */
-    protected function checkRequiredRedisVersion()
+    protected function checkRequiredRedisServerVersion()
     {
-        if (!isset($this->required['requiresRedisVersion'])) {
+        if (!$requiredVersion = $this->getRequiredRedisServerVersion()) {
             return;
         }
 
-        $srvVersion = $this->getRedisServerVersion();
-        $expectation = explode(' ', $this->required['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}
      */
@@ -302,6 +294,6 @@ abstract class PredisTestCase extends PHPUnit_Framework_TestCase
     {
         parent::checkRequirements();
 
-        $this->checkRequiredRedisVersion();
+        $this->checkRequiredRedisServerVersion();
     }
 }