ClusterOptionTest.php 2.7 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;
  11. use PredisTestCase;
  12. /**
  13. *
  14. */
  15. class ClusterOptionTest extends PredisTestCase
  16. {
  17. /**
  18. * @group disconnected
  19. */
  20. public function testDefaultOptionValue()
  21. {
  22. $option = new ClusterOption();
  23. $options = $this->getMock('Predis\Configuration\OptionsInterface');
  24. $this->assertInstanceOf('Predis\Connection\Aggregate\PredisCluster', $option->getDefault($options));
  25. }
  26. /**
  27. * @group disconnected
  28. */
  29. public function testAcceptsInstanceOfClusterInterface()
  30. {
  31. $option = new ClusterOption();
  32. $options = $this->getMock('Predis\Configuration\OptionsInterface');
  33. $cluster = $this->getMock('Predis\Connection\Aggregate\ClusterInterface');
  34. $this->assertSame($cluster, $option->filter($options, $cluster));
  35. }
  36. /**
  37. * @group disconnected
  38. */
  39. public function testAcceptsPredefinedShortNameString()
  40. {
  41. $option = new ClusterOption();
  42. $options = $this->getMock('Predis\Configuration\OptionsInterface');
  43. $options->expects($this->any())
  44. ->method('__get')
  45. ->with('connections')
  46. ->will($this->returnValue(
  47. $this->getMock('Predis\Connection\FactoryInterface')
  48. ));
  49. $this->assertInstanceOf('Predis\Connection\Aggregate\PredisCluster', $option->filter($options, 'predis'));
  50. $this->assertInstanceOf('Predis\Connection\Aggregate\PredisCluster', $option->filter($options, 'predis-cluster'));
  51. $this->assertInstanceOf('Predis\Connection\Aggregate\RedisCluster', $option->filter($options, 'redis'));
  52. $this->assertInstanceOf('Predis\Connection\Aggregate\RedisCluster', $option->filter($options, 'redis-cluster'));
  53. }
  54. /**
  55. * @group disconnected
  56. * @expectedException \InvalidArgumentException
  57. */
  58. public function testThrowsExceptionOnInvalidInstanceType()
  59. {
  60. $option = new ClusterOption();
  61. $options = $this->getMock('Predis\Configuration\OptionsInterface');
  62. $class = $this->getMock('Predis\Connection\NodeConnectionInterface');
  63. $option->filter($options, $class);
  64. }
  65. /**
  66. * @group disconnected
  67. * @expectedException \InvalidArgumentException
  68. */
  69. public function testThrowsExceptionOnInvalidShortNameString()
  70. {
  71. $option = new ClusterOption();
  72. $options = $this->getMock('Predis\Configuration\OptionsInterface');
  73. $option->filter($options, 'unknown');
  74. }
  75. }