ConnectionFactoryOptionTest.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. $options = $this->getMock('Predis\Configuration\OptionsInterface');
  34. $class = get_class($this->getMock('Predis\Connection\NodeConnectionInterface'));
  35. $value = array('tcp' => $class, 'redis' => $class);
  36. $default = $this->getMock('Predis\Connection\FactoryInterface');
  37. $default->expects($this->exactly(2))
  38. ->method('define')
  39. ->with($this->matchesRegularExpression('/^tcp|redis$/'), $class);
  40. $option = $this->getMock('Predis\Configuration\ConnectionFactoryOption', array('getDefault'));
  41. $option->expects($this->once())
  42. ->method('getDefault')
  43. ->with($options)
  44. ->will($this->returnValue($default));
  45. $this->assertInstanceOf('Predis\Connection\FactoryInterface', $factory = $option->filter($options, $value));
  46. $this->assertSame($default, $factory);
  47. }
  48. /**
  49. * @group disconnected
  50. */
  51. public function testAcceptsConnectionFactoryInstance()
  52. {
  53. $options = $this->getMock('Predis\Configuration\OptionsInterface');
  54. $value = $this->getMock('Predis\Connection\FactoryInterface');
  55. $option = $this->getMock('Predis\Configuration\ConnectionFactoryOption', array('getDefault'));
  56. $option->expects($this->never())->method('getDefault');
  57. $this->assertSame($value, $option->filter($options, $value));
  58. }
  59. /**
  60. * @group disconnected
  61. * @expectedException InvalidArgumentException
  62. */
  63. public function testThrowsExceptionOnInvalidArguments()
  64. {
  65. $option = new ConnectionFactoryOption();
  66. $options = $this->getMock('Predis\Configuration\OptionsInterface');
  67. $option->filter($options, new stdClass);
  68. }
  69. }