KeyPrefixProcessorTest.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. /*
  3. * This file is part of the Predis package.
  4. *
  5. * (c) Daniele Alessandri <suppakilla@gmail.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Predis\Commands\Processors;
  11. use \PHPUnit_Framework_TestCase as StandardTestCase;
  12. /**
  13. *
  14. */
  15. class KeyPrefixProcessorTest extends StandardTestCase
  16. {
  17. /**
  18. * @group disconnected
  19. */
  20. public function testConstructorWithPrefix()
  21. {
  22. $prefix = 'prefix:';
  23. $processor = new KeyPrefixProcessor($prefix);
  24. $this->assertInstanceOf('Predis\Commands\Processors\ICommandProcessor', $processor);
  25. $this->assertEquals($prefix, $processor->getPrefix());
  26. }
  27. /**
  28. * @group disconnected
  29. */
  30. public function testChangePrefix()
  31. {
  32. $prefix1 = 'prefix:';
  33. $prefix2 = 'prefix:new:';
  34. $processor = new KeyPrefixProcessor($prefix1);
  35. $this->assertEquals($prefix1, $processor->getPrefix());
  36. $processor->setPrefix($prefix2);
  37. $this->assertEquals($prefix2, $processor->getPrefix());
  38. }
  39. /**
  40. * @group disconnected
  41. */
  42. public function testProcessPrefixableCommands()
  43. {
  44. $prefix = 'prefix:';
  45. $unprefixed = 'key';
  46. $expected = "$prefix$unprefixed";
  47. $command = $this->getMock('Predis\Commands\PrefixableCommand');
  48. $command->expects($this->once())
  49. ->method('prefixKeys')
  50. ->with($prefix);
  51. $processor = new KeyPrefixProcessor($prefix);
  52. $processor->process($command);
  53. }
  54. /**
  55. * @group disconnected
  56. */
  57. public function testProcessNotPrefixableCommands()
  58. {
  59. $prefix = 'prefix:';
  60. $unprefixed = 'key';
  61. $expected = "$prefix$unprefixed";
  62. $command = $this->getMock('Predis\Commands\ICommand');
  63. $command->expects($this->never())->method('prefixKeys');
  64. $processor = new KeyPrefixProcessor($prefix);
  65. $processor->process($command);
  66. }
  67. }