Browse Source

Added PHPUnit utility method markTestSkippedOnRedisVersionBelow and applied it where necessary

Raphael Stolt 12 years ago
parent
commit
06d5475129
2 changed files with 34 additions and 0 deletions
  1. 28 0
      tests/PHPUnit/CommandTestCase.php
  2. 6 0
      tests/Predis/Command/ServerClientTest.php

+ 28 - 0
tests/PHPUnit/CommandTestCase.php

@@ -159,6 +159,34 @@ abstract class CommandTestCase extends StandardTestCase
         $this->assertEquals($this->getExpectedId(), $command->getId());
     }
 
+    /**
+     * @param  string $expectedRedisVersion
+     * @param  string $message Optional message.
+     * @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($expectedRedisVersion, $message = '')
+    {
+        $client = $this->getClient();
+        $serverInfo = $client->info('SERVER');
+        $serverInfo = array_change_key_case($serverInfo);
+        if (!isset($serverInfo['server'])
+            || !isset($serverInfo['server']['redis_version']))
+        {
+            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);
+        }
+    }
+
     /**
      * @group disconnected
      */

+ 6 - 0
tests/Predis/Command/ServerClientTest.php

@@ -148,6 +148,8 @@ BUFFER;
      */
     public function testGetsNameOfConnection()
     {
+         $this->markTestSkippedOnRedisVersionBelow('2.6.9');
+
          $redis = $this->getClient();
          $clientName = $redis->client('GETNAME');
          $this->assertNull($clientName);
@@ -162,6 +164,8 @@ BUFFER;
      */
     public function testSetsNameOfConnection()
     {
+         $this->markTestSkippedOnRedisVersionBelow('2.6.9');
+
          $redis = $this->getClient();
 
          $expectedConnectionName = 'foo-baz';
@@ -188,6 +192,8 @@ BUFFER;
      */
     public function testInvalidSetNameOfConnection($invalidConnectionName)
     {
+         $this->markTestSkippedOnRedisVersionBelow('2.6.9');
+
          $redis = $this->getClient();
          $redis->client('SETNAME', $invalidConnectionName);
     }