mirror of
https://github.com/predis/predis.git
synced 2026-09-18 06:17:08 +00:00
Make option "prefix" accept command processor instances.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user