ConnectionFactoryOptionTest.php 2.7 KB

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