ClientReplicationTest.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 PredisTestCase;
  12. /**
  13. *
  14. */
  15. class ClientReplicationTest extends PredisTestCase
  16. {
  17. /**
  18. * @group disconnected
  19. */
  20. public function testValidationAcceptsFQNStringAsInitializer()
  21. {
  22. $replicationClass = get_class($this->getMock('Predis\Connection\ReplicationConnectionInterface'));
  23. $options = $this->getMock('Predis\Option\ClientOptionsInterface');
  24. $option = new ClientReplication();
  25. $replication = $option->filter($options, $replicationClass);
  26. $this->assertInstanceOf('Predis\Connection\ReplicationConnectionInterface', $replication);
  27. }
  28. /**
  29. * @group disconnected
  30. */
  31. public function testValidationAcceptsBooleanValue()
  32. {
  33. $options = $this->getMock('Predis\Option\ClientOptionsInterface');
  34. $option = new ClientReplication();
  35. $replication = $option->filter($options, true);
  36. $this->assertInstanceOf('Predis\Connection\ReplicationConnectionInterface', $replication);
  37. $replication = $option->filter($options, false);
  38. $this->assertNull($replication);
  39. }
  40. /**
  41. * @group disconnected
  42. */
  43. public function testValidationAcceptsCallableObjectAsInitializers()
  44. {
  45. $value = $this->getMock('Predis\Connection\ReplicationConnectionInterface');
  46. $options = $this->getMock('Predis\Option\ClientOptionsInterface');
  47. $option = new ClientReplication();
  48. $initializer = $this->getMock('stdClass', array('__invoke'));
  49. $initializer->expects($this->once())
  50. ->method('__invoke')
  51. ->with($this->isInstanceOf('Predis\Option\ClientOptionsInterface'), $option)
  52. ->will($this->returnValue($value));
  53. $replication = $option->filter($options, $initializer, $option);
  54. $this->assertInstanceOf('Predis\Connection\ReplicationConnectionInterface', $replication);
  55. $this->assertSame($value, $replication);
  56. }
  57. /**
  58. * @group disconnected
  59. * @expectedException InvalidArgumentException
  60. */
  61. public function testValidationThrowsExceptionOnInvalidObjectReturnedByCallback()
  62. {
  63. $value = function ($options) {
  64. return new \stdClass();
  65. };
  66. $options = $this->getMock('Predis\Option\ClientOptionsInterface');
  67. $option = new ClientReplication();
  68. $option->filter($options, $value);
  69. }
  70. /**
  71. * @group disconnected
  72. * @expectedException InvalidArgumentException
  73. */
  74. public function testValidationThrowsExceptionOnInvalidClassTypes()
  75. {
  76. $connectionClass = get_class($this->getMock('Predis\Connection\SingleConnectionInterface'));
  77. $options = $this->getMock('Predis\Option\ClientOptionsInterface');
  78. $option = new ClientReplication();
  79. $option->filter($options, $connectionClass);
  80. }
  81. }