ClusterOptionTest.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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\PredisCluster', $option->getDefault($options));
  25. }
  26. /**
  27. * @group disconnected
  28. */
  29. public function testAcceptsInstanceOfClusterConnectionInterface()
  30. {
  31. $option = new ClusterOption();
  32. $options = $this->getMock('Predis\Configuration\OptionsInterface');
  33. $cluster = $this->getMock('Predis\Connection\ClusterConnectionInterface');
  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. $this->assertInstanceOf('Predis\Connection\PredisCluster', $option->filter($options, 'predis'));
  44. $this->assertInstanceOf('Predis\Connection\PredisCluster', $option->filter($options, 'predis-cluster'));
  45. $this->assertInstanceOf('Predis\Connection\RedisCluster', $option->filter($options, 'redis'));
  46. $this->assertInstanceOf('Predis\Connection\RedisCluster', $option->filter($options, 'redis-cluster'));
  47. }
  48. /**
  49. * @group disconnected
  50. * @expectedException InvalidArgumentException
  51. */
  52. public function testThrowsExceptionOnInvalidInstanceType()
  53. {
  54. $option = new ClusterOption();
  55. $options = $this->getMock('Predis\Configuration\OptionsInterface');
  56. $class = $this->getMock('Predis\Connection\SingleConnectionInterface');
  57. $option->filter($options, $class);
  58. }
  59. /**
  60. * @group disconnected
  61. * @expectedException InvalidArgumentException
  62. */
  63. public function testThrowsExceptionOnInvalidShortNameString()
  64. {
  65. $option = new ClusterOption();
  66. $options = $this->getMock('Predis\Configuration\OptionsInterface');
  67. $option->filter($options, 'unknown');
  68. }
  69. }