Просмотр исходного кода

Make option "prefix" accept command processor instances.

Daniele Alessandri 11 лет назад
Родитель
Сommit
7a56856d46

+ 5 - 0
lib/Predis/Configuration/PrefixOption.php

@@ -12,6 +12,7 @@
 namespace Predis\Configuration;
 
 use Predis\Command\Processor\KeyPrefixProcessor;
+use Predis\Command\Processor\CommandProcessorInterface;
 
 /**
  * Configures a command processor that apply the specified
@@ -27,6 +28,10 @@ class PrefixOption implements OptionInterface
      */
     public function filter(OptionsInterface $options, $value)
     {
+        if ($value instanceof CommandProcessorInterface) {
+            return $value;
+        }
+
         return new KeyPrefixProcessor($value);
     }
 

+ 14 - 0
tests/Predis/Configuration/PrefixOptionTest.php

@@ -43,4 +43,18 @@ class PrefixOptionTest extends StandardTestCase
         $this->assertInstanceOf('Predis\Command\Processor\KeyPrefixProcessor', $return);
         $this->assertSame($value, $return->getPrefix());
     }
+
+    /**
+     * @group disconnected
+     */
+    public function testAcceptsCommandProcessorInstance()
+    {
+        $option = new PrefixOption();
+        $options = $this->getMock('Predis\Configuration\OptionsInterface');
+        $processor = $this->getMock('Predis\Command\Processor\CommandProcessorInterface');
+
+        $return = $option->filter($options, $processor);
+
+        $this->assertSame($processor, $return);
+    }
 }