ConnectionFactoryOptionTest.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 PHPUnit_Framework_TestCase as StandardTestCase;
  13. use stdClass;
  14. use Predis\Connection\ConnectionFactory;
  15. /**
  16. *
  17. */
  18. class ConnectionFactoryOptionTest extends StandardTestCase
  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. }