Browse Source

[tests] Fix version check to work on Redis < 2.6.0.

INFO does not have the concept of sections prior to 2.6.0 while our
test suite can be run against 2.4.0 (provided that phpunit.xml uses
the correct server profile), so we need to make sure that the check
does not break with prior version of Redis even if this is unlikely
to happen at this point.

Also changed a bit the naming of variables since things are already
pretty much explicit in this context.
Daniele Alessandri 12 years ago
parent
commit
dffbb8b042
1 changed files with 14 additions and 16 deletions
  1. 14 16
      tests/PHPUnit/CommandTestCase.php

+ 14 - 16
tests/PHPUnit/CommandTestCase.php

@@ -160,30 +160,28 @@ abstract class CommandTestCase extends StandardTestCase
     }
     }
 
 
     /**
     /**
-     * @param  string $expectedRedisVersion
+     * @param  string $expectedVersion
      * @param  string $message Optional message.
      * @param  string $message Optional message.
      * @throws \RuntimeException when unable to retrieve server info or redis version
      * @throws \RuntimeException when unable to retrieve server info or redis version
      * @throws \PHPUnit_Framework_SkippedTestError when expected redis version is not met
      * @throws \PHPUnit_Framework_SkippedTestError when expected redis version is not met
      */
      */
-    protected function markTestSkippedOnRedisVersionBelow($expectedRedisVersion, $message = '')
+    protected function markTestSkippedOnRedisVersionBelow($expectedVersion, $message = '')
     {
     {
         $client = $this->getClient();
         $client = $this->getClient();
-        $serverInfo = $client->info('SERVER');
-        $serverInfo = array_change_key_case($serverInfo);
-        if (!isset($serverInfo['server'])
-            || !isset($serverInfo['server']['redis_version']))
-        {
+        $info = array_change_key_case($client->info());
+
+        if (isset($info['server']['redis_version'])) {
+            // Redis >= 2.6
+            $version = $info['server']['redis_version'];
+        } else if (isset($info['redis_version'])) {
+            // Redis < 2.6
+            $version = $info['redis_version'];
+        } else {
             throw new \RuntimeException('Unable to retrieve server info');
             throw new \RuntimeException('Unable to retrieve server info');
         }
         }
-        $serverVersion = $serverInfo['server']['redis_version'];
-        if (version_compare($serverVersion, $expectedRedisVersion) <= -1) {
-            if ($message === '') {
-                $message = sprintf(
-                    'Test skipped as required Redis version %s was not met.',
-                    $expectedRedisVersion
-                );
-            }
-            throw new \PHPUnit_Framework_SkippedTestError($message);
+
+        if (version_compare($version, $expectedVersion) <= -1) {
+            $this->markTestSkipped($message ?: "Test requires Redis $expectedVersion, current is $version.");
         }
         }
     }
     }