ConnectionFactoryOptionTest.php 2.6 KB

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