ReplicationOptionTest.php 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 PredisTestCase;
  12. /**
  13. *
  14. */
  15. class ReplicationOptionTest extends PredisTestCase
  16. {
  17. /**
  18. * @group disconnected
  19. */
  20. public function testDefaultOptionValue()
  21. {
  22. $option = new ReplicationOption();
  23. $options = $this->getMock('Predis\Configuration\OptionsInterface');
  24. $this->assertInstanceOf('Predis\Connection\Aggregate\ReplicationInterface', $option->getDefault($options));
  25. $this->assertInstanceOf('Predis\Connection\Aggregate\MasterSlaveReplication', $option->getDefault($options));
  26. }
  27. /**
  28. * @group disconnected
  29. */
  30. public function testAcceptsValuesThatCanBeInterpretedAsBooleans()
  31. {
  32. $option = new ReplicationOption();
  33. $options = $this->getMock('Predis\Configuration\OptionsInterface');
  34. $this->assertNull($option->filter($options, null));
  35. $this->assertInstanceOf('Predis\Connection\Aggregate\ReplicationInterface', $option->filter($options, true));
  36. $this->assertNull($option->filter($options, false));
  37. $this->assertInstanceOf('Predis\Connection\Aggregate\ReplicationInterface', $option->filter($options, 1));
  38. $this->assertNull($option->filter($options, 0));
  39. $this->assertInstanceOf('Predis\Connection\Aggregate\ReplicationInterface', $option->filter($options, 'true'));
  40. $this->assertNull($option->filter($options, 'false'));
  41. $this->assertInstanceOf('Predis\Connection\Aggregate\ReplicationInterface', $option->filter($options, 'on'));
  42. $this->assertNull($option->filter($options, 'off'));
  43. }
  44. /**
  45. * @group disconnected
  46. */
  47. public function testConfiguresAutomaticDiscoveryWhenAutodiscoveryOptionIsPresent()
  48. {
  49. $option = new ReplicationOption();
  50. $options = $this->getMock('Predis\Configuration\OptionsInterface');
  51. $connFactory = $this->getMock('Predis\Connection\FactoryInterface');
  52. $options->expects($this->at(0))
  53. ->method('__get')
  54. ->with('autodiscovery')
  55. ->will($this->returnValue(true));
  56. $options->expects($this->at(1))
  57. ->method('__get')
  58. ->with('connections')
  59. ->will($this->returnValue($connFactory));
  60. $replication = $option->getDefault($options);
  61. // TODO: I know, I know...
  62. $reflection = new \ReflectionProperty($replication, 'autoDiscovery');
  63. $reflection->setAccessible(true);
  64. $this->assertTrue($reflection->getValue($replication));
  65. }
  66. /**
  67. * @group disconnected
  68. * @expectedException \InvalidArgumentException
  69. */
  70. public function testThrowsExceptionOnInvalidInstanceType()
  71. {
  72. $option = new ReplicationOption();
  73. $options = $this->getMock('Predis\Configuration\OptionsInterface');
  74. $value = $this->getMock('Predis\Connection\NodeConnectionInterface');
  75. $option->filter($options, $value);
  76. }
  77. }