ClientOptionsTest.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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\Option;
  11. use PredisTestCase;
  12. /**
  13. * @todo We should test the inner work performed by this class
  14. * using mock objects, but it is quite hard to to that.
  15. */
  16. class ClientOptionsTest extends PredisTestCase
  17. {
  18. /**
  19. * @group disconnected
  20. */
  21. public function testConstructorWithoutArguments()
  22. {
  23. $options = new ClientOptions();
  24. $this->assertInstanceOf('Predis\Connection\ConnectionFactoryInterface', $options->connections);
  25. $this->assertInstanceOf('Predis\Profile\ServerProfileInterface', $options->profile);
  26. $this->assertInstanceOf('Predis\Connection\ClusterConnectionInterface', $options->cluster);
  27. $this->assertNull($options->prefix);
  28. }
  29. /**
  30. * @group disconnected
  31. */
  32. public function testConstructorWithArrayArgument()
  33. {
  34. $options = new ClientOptions(array(
  35. 'cluster' => 'Predis\Connection\PredisCluster',
  36. 'connections' => 'Predis\Connection\ConnectionFactory',
  37. 'prefix' => 'prefix:',
  38. 'profile' => '2.0',
  39. 'exceptions' => false,
  40. ));
  41. $this->assertInstanceOf('Predis\Connection\ConnectionFactoryInterface', $options->connections);
  42. $this->assertInstanceOf('Predis\Profile\ServerProfileInterface', $options->profile);
  43. $this->assertInstanceOf('Predis\Connection\ClusterConnectionInterface', $options->cluster);
  44. $this->assertInstanceOf('Predis\Command\Processor\CommandProcessorInterface', $options->prefix);
  45. $this->assertInternalType('bool', $options->exceptions);
  46. }
  47. /**
  48. * @group disconnected
  49. */
  50. public function testHandlesCustomOptionsWithoutHandlers()
  51. {
  52. $options = new ClientOptions(array(
  53. 'custom' => 'foobar',
  54. ));
  55. $this->assertSame('foobar', $options->custom);
  56. }
  57. /**
  58. * @group disconnected
  59. */
  60. public function testIsSetReturnsIfOptionHasBeenSetByUser()
  61. {
  62. $options = new ClientOptions(array(
  63. 'prefix' => 'prefix:',
  64. 'custom' => 'foobar',
  65. ));
  66. $this->assertTrue(isset($options->prefix));
  67. $this->assertTrue(isset($options->custom));
  68. $this->assertFalse(isset($options->profile));
  69. }
  70. /**
  71. * @group disconnected
  72. */
  73. public function testGetDefaultUsingOptionName()
  74. {
  75. $options = new ClientOptions();
  76. $this->assertInstanceOf('Predis\Connection\PredisCluster', $options->getDefault('cluster'));
  77. }
  78. /**
  79. * @group disconnected
  80. */
  81. public function testGetDefaultUsingUnhandledOptionName()
  82. {
  83. $options = new ClientOptions();
  84. $option = new ClientCluster();
  85. $this->assertNull($options->getDefault('foo'));
  86. }
  87. /**
  88. * @group disconnected
  89. */
  90. public function testGetDefaultUsingOptionInstance()
  91. {
  92. $options = new ClientOptions();
  93. $option = new ClientCluster();
  94. $this->assertInstanceOf('Predis\Connection\PredisCluster', $options->getDefault($option));
  95. }
  96. /**
  97. * @group disconnected
  98. */
  99. public function testGetDefaultUsingUnhandledOptionInstance()
  100. {
  101. $options = new ClientOptions();
  102. $option = new CustomOption(array(
  103. 'default' => function ($options) {
  104. return 'foo';
  105. },
  106. ));
  107. $this->assertSame('foo', $options->getDefault($option));
  108. }
  109. }