ClusterOptionTest.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 PHPUnit_Framework_TestCase as StandardTestCase;
  12. use stdClass;
  13. /**
  14. *
  15. */
  16. class ClusterOptionTest extends StandardTestCase
  17. {
  18. /**
  19. * @group disconnected
  20. */
  21. public function testDefaultOptionValue()
  22. {
  23. $option = new ClusterOption();
  24. $options = $this->getMock('Predis\Configuration\OptionsInterface');
  25. $this->assertInstanceOf('Predis\Connection\PredisCluster', $option->getDefault($options));
  26. }
  27. /**
  28. * @group disconnected
  29. */
  30. public function testAcceptsInstanceOfClusterConnectionInterface()
  31. {
  32. $option = new ClusterOption();
  33. $options = $this->getMock('Predis\Configuration\OptionsInterface');
  34. $cluster = $this->getMock('Predis\Connection\ClusterConnectionInterface');
  35. $this->assertSame($cluster, $option->filter($options, $cluster));
  36. }
  37. /**
  38. * @group disconnected
  39. */
  40. public function testAcceptsPredefinedShortNameString()
  41. {
  42. $option = new ClusterOption();
  43. $options = $this->getMock('Predis\Configuration\OptionsInterface');
  44. $this->assertInstanceOf('Predis\Connection\PredisCluster', $option->filter($options, 'predis'));
  45. $this->assertInstanceOf('Predis\Connection\PredisCluster', $option->filter($options, 'predis-cluster'));
  46. $this->assertInstanceOf('Predis\Connection\RedisCluster', $option->filter($options, 'redis'));
  47. $this->assertInstanceOf('Predis\Connection\RedisCluster', $option->filter($options, 'redis-cluster'));
  48. }
  49. /**
  50. * @group disconnected
  51. * @expectedException InvalidArgumentException
  52. */
  53. public function testThrowsExceptionOnInvalidInstanceType()
  54. {
  55. $option = new ClusterOption();
  56. $options = $this->getMock('Predis\Configuration\OptionsInterface');
  57. $class = $this->getMock('Predis\Connection\SingleConnectionInterface');
  58. $option->filter($options, $class);
  59. }
  60. /**
  61. * @group disconnected
  62. * @expectedException InvalidArgumentException
  63. */
  64. public function testThrowsExceptionOnInvalidShortNameString()
  65. {
  66. $option = new ClusterOption();
  67. $options = $this->getMock('Predis\Configuration\OptionsInterface');
  68. $option->filter($options, 'unknown');
  69. }
  70. }