AggregateTest.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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->expects($this->once())
  36. ->method('__invoke')
  37. ->with($this->isInstanceOf('Predis\Configuration\OptionsInterface'))
  38. ->will($this->returnValue($connection));
  39. $this->assertInstanceOf('Closure', $initializer = $option->filter($options, $callable));
  40. $this->assertSame($connection, $initializer($parameters = array()));
  41. }
  42. /**
  43. * @group disconnected
  44. * @expectedException \InvalidArgumentException
  45. * @expectedExceptionMessage Predis\Configuration\Option\Aggregate expects a valid connection type returned by callable initializer
  46. */
  47. public function testThrowsExceptionOnInvalidReturnTypeOfConnectionInitializer()
  48. {
  49. $option = new Aggregate();
  50. $options = $this->getMock('Predis\Configuration\OptionsInterface');
  51. $connection = $this->getMock('Predis\Connection\NodeConnectionInterface');
  52. $callable = $this->getMock('stdClass', array('__invoke'));
  53. $callable->expects($this->once())
  54. ->method('__invoke')
  55. ->with($this->isInstanceOf('Predis\Configuration\OptionsInterface'))
  56. ->will($this->returnValue($connection));
  57. $this->assertInstanceOf('Closure', $initializer = $option->filter($options, $callable));
  58. $initializer($parameters = array());
  59. }
  60. /**
  61. * @group disconnected
  62. * @expectedException \InvalidArgumentException
  63. * @expectedExceptionMessage Predis\Configuration\Option\Aggregate expects a valid callable
  64. */
  65. public function testThrowsExceptionOnInstanceOfAggregateConnectionInterface()
  66. {
  67. $option = new Aggregate();
  68. $options = $this->getMock('Predis\Configuration\OptionsInterface');
  69. $cluster = $this->getMock('Predis\Connection\AggregateConnectionInterface');
  70. $option->filter($options, $cluster);
  71. }
  72. }