12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?php
- namespace Predis\Command\Processor;
- use \PHPUnit_Framework_TestCase as StandardTestCase;
- class KeyPrefixProcessorTest extends StandardTestCase
- {
-
- public function testConstructorWithPrefix()
- {
- $prefix = 'prefix:';
- $processor = new KeyPrefixProcessor($prefix);
- $this->assertInstanceOf('Predis\Command\Processor\CommandProcessorInterface', $processor);
- $this->assertEquals($prefix, $processor->getPrefix());
- }
-
- public function testChangePrefix()
- {
- $prefix1 = 'prefix:';
- $prefix2 = 'prefix:new:';
- $processor = new KeyPrefixProcessor($prefix1);
- $this->assertEquals($prefix1, $processor->getPrefix());
- $processor->setPrefix($prefix2);
- $this->assertEquals($prefix2, $processor->getPrefix());
- }
-
- public function testProcessPrefixableCommands()
- {
- $prefix = 'prefix:';
- $unprefixed = 'key';
- $expected = "$prefix$unprefixed";
- $command = $this->getMock('Predis\Command\PrefixableCommand');
- $command->expects($this->once())
- ->method('prefixKeys')
- ->with($prefix);
- $processor = new KeyPrefixProcessor($prefix);
- $processor->process($command);
- }
-
- public function testProcessNotPrefixableCommands()
- {
- $prefix = 'prefix:';
- $unprefixed = 'key';
- $expected = "$prefix$unprefixed";
- $command = $this->getMock('Predis\Command\CommandInterface');
- $command->expects($this->never())->method('prefixKeys');
- $processor = new KeyPrefixProcessor($prefix);
- $processor->process($command);
- }
-
- public function testInstanceCanBeCastedToString()
- {
- $prefix = 'prefix:';
- $processor = new KeyPrefixProcessor($prefix);
- $this->assertEquals($prefix, (string) $processor);
- }
- }
|