KeyPrefixProcessorTest.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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\Command\Processor;
  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\Command\Processor\CommandProcessorInterface', $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\Command\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\Command\CommandInterface');
  63. $command->expects($this->never())->method('prefixKeys');
  64. $processor = new KeyPrefixProcessor($prefix);
  65. $processor->process($command);
  66. }
  67. /**
  68. * @group disconnected
  69. */
  70. public function testInstanceCanBeCastedToString()
  71. {
  72. $prefix = 'prefix:';
  73. $processor = new KeyPrefixProcessor($prefix);
  74. $this->assertEquals($prefix, (string) $processor);
  75. }
  76. }