Pārlūkot izejas kodu

[tests] Improve base command test case.

Daniele Alessandri 11 gadi atpakaļ
vecāks
revīzija
d52daacba9
1 mainītis faili ar 43 papildinājumiem un 6 dzēšanām
  1. 43 6
      tests/PHPUnit/CommandTestCase.php

+ 43 - 6
tests/PHPUnit/CommandTestCase.php

@@ -159,12 +159,11 @@ abstract class CommandTestCase extends StandardTestCase
     }
 
     /**
-     * @param  string $expectedVersion
-     * @param  string $message Optional message.
-     * @throws \RuntimeException when unable to retrieve server info or redis version
+     * @param  string $expectedVersion Expected redis version
+     * @param  string $operator Comparison operator.
      * @throws \PHPUnit_Framework_SkippedTestError when expected redis version is not met
      */
-    protected function markTestSkippedOnRedisVersionBelow($expectedVersion, $message = '')
+    protected function executeOnRedisVersion($expectedVersion, $operator, $callback)
     {
         $client = $this->getClient();
         $info = array_change_key_case($client->info());
@@ -179,9 +178,47 @@ abstract class CommandTestCase extends StandardTestCase
             throw new \RuntimeException('Unable to retrieve server info');
         }
 
-        if (version_compare($version, $expectedVersion) <= -1) {
-            $this->markTestSkipped($message ?: "Test requires Redis $expectedVersion, current is $version.");
+        $comparation = version_compare($version, $expectedVersion);
+
+        if ($match = eval("return $comparation $operator 0;")) {
+            call_user_func($callback, $this, $version);
         }
+
+        return $match;
+    }
+
+    /**
+     * @param  string $expectedVersion Expected redis version
+     * @param  string $operator Comparison operator.
+     * @throws \PHPUnit_Framework_SkippedTestError when expected redis version is not met
+     */
+    protected function executeOnProfileVersion($expectedVersion, $operator, $callback)
+    {
+        $profile = $this->getProfile();
+        $comparation = version_compare($profile->getVersion(), $expectedVersion);
+
+        if ($match = eval("return $comparation $operator 0;")) {
+            call_user_func($callback, $this, $version);
+        }
+
+        return $match;
+    }
+
+    /**
+     * @param  string $expectedVersion Expected redis version.
+     * @param  string $message Optional message.
+     * @param  bool $remote Based on local profile or remote redis version.
+     * @throws \RuntimeException when unable to retrieve server info or redis version
+     * @throws \PHPUnit_Framework_SkippedTestError when expected redis version is not met
+     */
+    protected function markTestSkippedOnRedisVersionBelow($expectedVersion, $message = '', $remote = true)
+    {
+        $callback = function ($test, $version) use ($message, $expectedVersion) {
+            $test->markTestSkipped($message ?: "Test requires Redis $expectedVersion, current is $version.");
+        };
+
+        $method = $remote ? 'executeOnRedisVersion' : 'executeOnProfileVersion';
+        $this->$method($expectedVersion, '<', $callback);
     }
 
     /**