AggregateTest.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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\Option;
  11. use PredisTestCase;
  12. /**
  13. *
  14. */
  15. class AggregateTest extends PredisTestCase
  16. {
  17. /**
  18. * @group disconnected
  19. */
  20. public function testDefaultOptionValue()
  21. {
  22. $option = new Aggregate();
  23. $options = $this->getMock('Predis\Configuration\OptionsInterface');
  24. $this->assertNull($option->getDefault($options));
  25. }
  26. /**
  27. * @group disconnected
  28. */
  29. public function testAcceptsCallableAsConnectionInitializer()
  30. {
  31. $option = new Aggregate();
  32. $options = $this->getMock('Predis\Configuration\OptionsInterface');
  33. $connection = $this->getMock('Predis\Connection\AggregateConnectionInterface');
  34. $callable = $this->getMock('stdClass', array('__invoke'));
  35. $callable
  36. ->expects($this->once())
  37. ->method('__invoke')
  38. ->with($this->isInstanceOf('Predis\Configuration\OptionsInterface'))
  39. ->will($this->returnValue($connection));
  40. $this->assertInstanceOf('Closure', $initializer = $option->filter($options, $callable));
  41. $this->assertSame($connection, $initializer($parameters = array()));
  42. }
  43. /**
  44. * @group disconnected
  45. * @expectedException \InvalidArgumentException
  46. * @expectedExceptionMessage Predis\Configuration\Option\Aggregate expects a valid connection type returned by callable initializer
  47. */
  48. public function testThrowsExceptionOnInvalidReturnTypeOfConnectionInitializer()
  49. {
  50. $option = new Aggregate();
  51. $options = $this->getMock('Predis\Configuration\OptionsInterface');
  52. $connection = $this->getMock('Predis\Connection\NodeConnectionInterface');
  53. $callable = $this->getMock('stdClass', array('__invoke'));
  54. $callable
  55. ->expects($this->once())
  56. ->method('__invoke')
  57. ->with($this->isInstanceOf('Predis\Configuration\OptionsInterface'))
  58. ->will($this->returnValue($connection));
  59. $this->assertInstanceOf('Closure', $initializer = $option->filter($options, $callable));
  60. $initializer($parameters = array());
  61. }
  62. /**
  63. * @group disconnected
  64. * @expectedException \InvalidArgumentException
  65. * @expectedExceptionMessage Predis\Configuration\Option\Aggregate expects a valid callable
  66. */
  67. public function testThrowsExceptionOnInstanceOfAggregateConnectionInterface()
  68. {
  69. $option = new Aggregate();
  70. $options = $this->getMock('Predis\Configuration\OptionsInterface');
  71. $cluster = $this->getMock('Predis\Connection\AggregateConnectionInterface');
  72. $option->filter($options, $cluster);
  73. }
  74. }