ConnectionFactoryOptionTest.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 PredisTestCase;
  12. /**
  13. *
  14. */
  15. class ConnectionFactoryOptionTest extends PredisTestCase
  16. {
  17. /**
  18. * @group disconnected
  19. */
  20. public function testDefaultOptionValue()
  21. {
  22. $option = new ConnectionFactoryOption();
  23. $options = $this->getMock('Predis\Configuration\OptionsInterface');
  24. $this->assertInstanceOf('Predis\Connection\Factory', $option->getDefault($options));
  25. }
  26. /**
  27. * @group disconnected
  28. */
  29. public function testAcceptsNamedArrayWithSchemeToConnectionClassMappings()
  30. {
  31. $options = $this->getMock('Predis\Configuration\OptionsInterface');
  32. $class = get_class($this->getMock('Predis\Connection\NodeConnectionInterface'));
  33. $value = array('tcp' => $class, 'redis' => $class);
  34. $default = $this->getMock('Predis\Connection\FactoryInterface');
  35. $default->expects($this->exactly(2))
  36. ->method('define')
  37. ->with($this->matchesRegularExpression('/^tcp|redis$/'), $class);
  38. $option = $this->getMock('Predis\Configuration\ConnectionFactoryOption', array('getDefault'));
  39. $option->expects($this->once())
  40. ->method('getDefault')
  41. ->with($options)
  42. ->will($this->returnValue($default));
  43. $this->assertInstanceOf('Predis\Connection\FactoryInterface', $factory = $option->filter($options, $value));
  44. $this->assertSame($default, $factory);
  45. }
  46. /**
  47. * @group disconnected
  48. */
  49. public function testAcceptsConnectionFactoryInstance()
  50. {
  51. $options = $this->getMock('Predis\Configuration\OptionsInterface');
  52. $value = $this->getMock('Predis\Connection\FactoryInterface');
  53. $option = $this->getMock('Predis\Configuration\ConnectionFactoryOption', array('getDefault'));
  54. $option->expects($this->never())->method('getDefault');
  55. $this->assertSame($value, $option->filter($options, $value));
  56. }
  57. /**
  58. * @group disconnected
  59. * @expectedException InvalidArgumentException
  60. */
  61. public function testThrowsExceptionOnInvalidArguments()
  62. {
  63. $option = new ConnectionFactoryOption();
  64. $options = $this->getMock('Predis\Configuration\OptionsInterface');
  65. $option->filter($options, new \stdClass());
  66. }
  67. }