ReplicationOptionTest.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. * @expectedException \InvalidArgumentException
  47. */
  48. public function testThrowsExceptionOnInvalidInstanceType()
  49. {
  50. $option = new ReplicationOption();
  51. $options = $this->getMock('Predis\Configuration\OptionsInterface');
  52. $value = $this->getMock('Predis\Connection\NodeConnectionInterface');
  53. $option->filter($options, $value);
  54. }
  55. }