CommandsOptionTest.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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;
  11. use Predis\Command\RedisFactory;
  12. use Predis\Command\Processor\KeyPrefixProcessor;
  13. use PredisTestCase;
  14. /**
  15. *
  16. */
  17. class CommandsOptionTest extends PredisTestCase
  18. {
  19. /**
  20. * @group disconnected
  21. */
  22. public function testDefaultOptionValue()
  23. {
  24. $option = new CommandsOption();
  25. $options = $this->getMock('Predis\Configuration\OptionsInterface');
  26. $commands = $option->getDefault($options);
  27. $this->assertInstanceOf('Predis\Command\FactoryInterface', $commands);
  28. $this->assertNull($commands->getProcessor());
  29. }
  30. /**
  31. * @group disconnected
  32. */
  33. public function testAcceptsCommandFactoryInstanceAsValue()
  34. {
  35. $option = new CommandsOption();
  36. $options = $this->getMock('Predis\Configuration\OptionsInterface');
  37. $value = new RedisFactory();
  38. $commands = $option->filter($options, $value);
  39. $this->assertSame($commands, $value);
  40. $this->assertNull($commands->getProcessor());
  41. }
  42. /**
  43. * @group disconnected
  44. */
  45. public function testAppliesPrefixOnDefaultOptionValue()
  46. {
  47. $option = new CommandsOption();
  48. $options = $this->getMock('Predis\Configuration\OptionsInterface');
  49. $options->expects($this->once())
  50. ->method('__isset')
  51. ->with('prefix')
  52. ->will($this->returnValue(true));
  53. $options->expects($this->once())
  54. ->method('__get')
  55. ->with('prefix')
  56. ->will($this->returnValue(new KeyPrefixProcessor('prefix:')));
  57. $commands = $option->getDefault($options);
  58. $this->assertInstanceOf('Predis\Command\FactoryInterface', $commands);
  59. $this->assertInstanceOf('Predis\Command\Processor\KeyPrefixProcessor', $commands->getProcessor());
  60. $this->assertSame('prefix:', $commands->getProcessor()->getPrefix());
  61. }
  62. /**
  63. * @group disconnected
  64. * @expectedException InvalidArgumentException
  65. */
  66. public function testThrowsExceptionOnStringValue()
  67. {
  68. $option = new CommandsOption();
  69. $options = $this->getMock('Predis\Configuration\OptionsInterface');
  70. $option->filter($options, '3.2');
  71. }
  72. /**
  73. * @group disconnected
  74. * @expectedException InvalidArgumentException
  75. */
  76. public function testThrowsExceptionOnInvalidValue()
  77. {
  78. $option = new CommandsOption();
  79. $options = $this->getMock('Predis\Configuration\OptionsInterface');
  80. $option->filter($options, new \stdClass());
  81. }
  82. }