PrefixTest.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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\Configuration\Option;
  11. use PredisTestCase;
  12. /**
  13. *
  14. */
  15. class PrefixTest extends PredisTestCase
  16. {
  17. /**
  18. * @group disconnected
  19. */
  20. public function testDefaultOptionValue()
  21. {
  22. $option = new Prefix();
  23. $options = $this->getMock('Predis\Configuration\OptionsInterface');
  24. $this->assertNull($option->getDefault($options));
  25. }
  26. /**
  27. * @group disconnected
  28. */
  29. public function testAcceptsStringAndReturnsCommandProcessor()
  30. {
  31. $option = new Prefix();
  32. $options = $this->getMock('Predis\Configuration\OptionsInterface');
  33. $prefix = $option->filter($options, $value = 'prefix:');
  34. $this->assertInstanceOf('Predis\Command\Processor\ProcessorInterface', $prefix);
  35. $this->assertInstanceOf('Predis\Command\Processor\KeyPrefixProcessor', $prefix);
  36. $this->assertSame($value, $prefix->getPrefix());
  37. }
  38. /**
  39. * @group disconnected
  40. */
  41. public function testAcceptsCommandProcessorInstance()
  42. {
  43. $option = new Prefix();
  44. $options = $this->getMock('Predis\Configuration\OptionsInterface');
  45. $processor = $this->getMock('Predis\Command\Processor\ProcessorInterface');
  46. $prefix = $option->filter($options, $processor);
  47. $this->assertSame($processor, $prefix);
  48. }
  49. /**
  50. * @group disconnected
  51. */
  52. public function testAcceptsCallableReturningProcessorInterface()
  53. {
  54. $option = new Prefix();
  55. $options = $this->getMock('Predis\Configuration\OptionsInterface');
  56. $processor = $this->getMock('Predis\Command\Processor\ProcessorInterface');
  57. $callable = $this->getMock('stdClass', array('__invoke'));
  58. $callable->expects($this->once())
  59. ->method('__invoke')
  60. ->with($this->isInstanceOf('Predis\Configuration\OptionsInterface'))
  61. ->will($this->returnValue($processor));
  62. $prefix = $option->filter($options, $callable);
  63. $this->assertSame($processor, $prefix);
  64. }
  65. /**
  66. * @group disconnected
  67. */
  68. public function testAcceptsCallableReturningStringPrefix()
  69. {
  70. $option = new Prefix();
  71. $options = $this->getMock('Predis\Configuration\OptionsInterface');
  72. $callable = $this->getMock('stdClass', array('__invoke'));
  73. $callable->expects($this->once())
  74. ->method('__invoke')
  75. ->with($this->isInstanceOf('Predis\Configuration\OptionsInterface'))
  76. ->will($this->returnValue('pfx:'));
  77. $prefix = $option->filter($options, $callable);
  78. $this->assertInstanceOf('Predis\Command\Processor\ProcessorInterface', $prefix);
  79. $this->assertInstanceOf('Predis\Command\Processor\KeyPrefixProcessor', $prefix);
  80. $this->assertSame('pfx:', $prefix->getPrefix());
  81. }
  82. /**
  83. * @group disconnected
  84. */
  85. public function testAcceptsObjectAsPrefixAndCastsToString()
  86. {
  87. $option = new Prefix();
  88. $options = $this->getMock('Predis\Configuration\OptionsInterface');
  89. $input = $this->getMock('stdClass', array('__toString'));
  90. $input->expects($this->once())
  91. ->method('__toString')
  92. ->will($this->returnValue('pfx:'));
  93. $prefix = $option->filter($options, $input);
  94. $this->assertInstanceOf('Predis\Command\Processor\ProcessorInterface', $prefix);
  95. $this->assertInstanceOf('Predis\Command\Processor\KeyPrefixProcessor', $prefix);
  96. $this->assertSame('pfx:', $prefix->getPrefix());
  97. }
  98. }