Make option "prefix" accept command processor instances.

This commit is contained in:
Daniele Alessandri
2013-11-30 09:50:40 +01:00
parent fc4e279b9a
commit 7a56856d46
2 changed files with 19 additions and 0 deletions
@@ -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);
}
@@ -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);
}
}