Jelajahi Sumber

Add missing tests for Predis\Command\Hash\CommandHashStrategy.

Daniele Alessandri 12 tahun lalu
induk
melakukan
4b73afc316
1 mengubah file dengan 40 tambahan dan 0 penghapusan
  1. 40 0
      tests/Predis/Command/Hash/CommandHashStrategyTest.php

+ 40 - 0
tests/Predis/Command/Hash/CommandHashStrategyTest.php

@@ -156,6 +156,46 @@ class CommandHashStrategyTest extends StandardTestCase
         }
     }
 
+    /**
+     * @group disconnected
+     */
+    public function testUnsettingCommandHandler()
+    {
+        $distribution = new HashRing();
+        $hashstrategy = new CommandHashStrategy();
+        $profile = ServerProfile::getDevelopment();
+
+        $hashstrategy->setCommandHandler('set');
+        $hashstrategy->setCommandHandler('get', null);
+
+        $command = $profile->createCommand('set', array('key', 'value'));
+        $this->assertNull($hashstrategy->getHash($distribution, $command));
+
+        $command = $profile->createCommand('get', array('key'));
+        $this->assertNull($hashstrategy->getHash($distribution, $command));
+    }
+
+    /**
+     * @group disconnected
+     */
+    public function testSettingCustomCommandHandler()
+    {
+        $distribution = new HashRing();
+        $hashstrategy = new CommandHashStrategy();
+        $profile = ServerProfile::getDevelopment();
+
+        $callable = $this->getMock('stdClass', array('__invoke'));
+        $callable->expects($this->once())
+                 ->method('__invoke')
+                 ->with($this->isInstanceOf('Predis\Command\CommandInterface'))
+                 ->will($this->returnValue('key'));
+
+        $hashstrategy->setCommandHandler('get', $callable);
+
+        $command = $profile->createCommand('get', array('key'));
+        $this->assertNotNull($hashstrategy->getHash($distribution, $command));
+    }
+
     // ******************************************************************** //
     // ---- HELPER METHODS ------------------------------------------------ //
     // ******************************************************************** //