ClientClusterTest.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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\Option;
  11. use \PHPUnit_Framework_TestCase as StandardTestCase;
  12. /**
  13. *
  14. */
  15. class ClientClusterTest extends StandardTestCase
  16. {
  17. /**
  18. * @group disconnected
  19. */
  20. public function testValidationAcceptsFQNStringAsInitializer()
  21. {
  22. $clusterClass = get_class($this->getMock('Predis\Connection\ClusterConnectionInterface'));
  23. $options = $this->getMock('Predis\Option\ClientOptionsInterface');
  24. $option = new ClientCluster();
  25. $cluster = $option->filter($options, $clusterClass);
  26. $this->assertInstanceOf('Predis\Connection\ClusterConnectionInterface', $cluster);
  27. }
  28. /**
  29. * @group disconnected
  30. */
  31. public function testValidationRecognizesCertainPredefinedShortNames()
  32. {
  33. $options = $this->getMock('Predis\Option\ClientOptionsInterface');
  34. $option = new ClientCluster();
  35. $cluster = $option->filter($options, 'predis');
  36. $this->assertInstanceOf('Predis\Connection\ClusterConnectionInterface', $cluster);
  37. }
  38. /**
  39. * @group disconnected
  40. */
  41. public function testValidationAcceptsCallableObjectAsInitializers()
  42. {
  43. $value = $this->getMock('Predis\Connection\ClusterConnectionInterface');
  44. $initializer = $this->getMock('stdClass', array('__invoke'));
  45. $initializer->expects($this->once())
  46. ->method('__invoke')
  47. ->with($this->isInstanceOf('Predis\Option\ClientOptionsInterface'))
  48. ->will($this->returnValue($value));
  49. $options = $this->getMock('Predis\Option\ClientOptionsInterface');
  50. $option = new ClientCluster();
  51. $cluster = $option->filter($options, $initializer);
  52. $this->assertInstanceOf('Predis\Connection\ClusterConnectionInterface', $cluster);
  53. $this->assertSame($value, $cluster);
  54. }
  55. /**
  56. * @group disconnected
  57. */
  58. public function testValidationThrowsExceptionOnInvalidClassTypes()
  59. {
  60. $this->setExpectedException('InvalidArgumentException');
  61. $connectionClass = get_class($this->getMock('Predis\Connection\SingleConnectionInterface'));
  62. $options = $this->getMock('Predis\Option\ClientOptionsInterface');
  63. $option = new ClientCluster();
  64. $option->filter($options, $connectionClass);
  65. }
  66. /**
  67. * @group disconnected
  68. */
  69. public function testValidationThrowsExceptionOnInvalidShortName()
  70. {
  71. $this->setExpectedException('InvalidArgumentException');
  72. $options = $this->getMock('Predis\Option\ClientOptionsInterface');
  73. $option = new ClientCluster();
  74. $option->filter($options, 'unknown');
  75. }
  76. /**
  77. * @group disconnected
  78. */
  79. public function testValidationThrowsExceptionOnInvalidObjectReturnedByCallback()
  80. {
  81. $this->setExpectedException('InvalidArgumentException');
  82. $value = function ($options) {
  83. return new \stdClass();
  84. };
  85. $options = $this->getMock('Predis\Option\ClientOptionsInterface');
  86. $option = new ClientCluster();
  87. $option->filter($options, $value);
  88. }
  89. /**
  90. * @group disconnected
  91. */
  92. public function testValidationThrowsExceptionOnInvalidArguments()
  93. {
  94. $this->setExpectedException('InvalidArgumentException');
  95. $options = $this->getMock('Predis\Option\ClientOptionsInterface');
  96. $option = new ClientCluster();
  97. $option->filter($options, new \stdClass());
  98. }
  99. }