Browse Source

Fix Predis\Commands\ServerEvalSHA::getScriptHash().

"Predis\Commands\ServerEvalSHA::getScriptHash()" was calculating the hash
while it just needs to return the first argument of the command.
Daniele Alessandri 13 years ago
parent
commit
b67dab9ab1

+ 2 - 0
CHANGELOG.md

@@ -11,6 +11,8 @@ v0.7.3 (2012-xx-xx)
   This bug is limited to the above mentioned example and does not affect the
   This bug is limited to the above mentioned example and does not affect the
   classes implemented in the `Predis\Distribution` namespace.
   classes implemented in the `Predis\Distribution` namespace.
 
 
+- __FIX__: `Predis\Commands\ServerEvalSHA::getScriptHash()` was calculating the
+  hash while it just needs to return the first argument of the command.
 
 
 v0.7.2 (2012-04-01)
 v0.7.2 (2012-04-01)
 ===============================================================================
 ===============================================================================

+ 10 - 0
lib/Predis/Commands/ServerEvalSHA.php

@@ -24,4 +24,14 @@ class ServerEvalSHA extends ServerEval
     {
     {
         return 'EVALSHA';
         return 'EVALSHA';
     }
     }
+
+    /**
+     * Returns the SHA1 hash of the body of the script.
+     *
+     * @return string SHA1 hash.
+     */
+    public function getScriptHash()
+    {
+        return $this->getArgument(0);
+    }
 }
 }

+ 9 - 0
tests/Predis/Commands/ServerEvalSHATest.php

@@ -75,6 +75,15 @@ class ServerEvalSHATest extends CommandTestCase
         $this->assertSame($expected, $command->getArguments());
         $this->assertSame($expected, $command->getArguments());
     }
     }
 
 
+    /**
+     * @group disconnected
+     */
+    public function testGetScriptHash()
+    {
+        $command = $this->getCommandWithArgumentsArray(array($sha1 = sha1('return true')), 0);
+        $this->assertSame($sha1, $command->getScriptHash());
+    }
+
     /**
     /**
      * @group connected
      * @group connected
      */
      */