ClientOptionsTest.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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\Options;
  11. use \PHPUnit_Framework_TestCase as StandardTestCase;
  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 StandardTestCase
  17. {
  18. /**
  19. * @group disconnected
  20. */
  21. public function testConstructorWithoutArguments()
  22. {
  23. $options = new ClientOptions();
  24. $this->assertInstanceOf('Predis\Profiles\IServerProfile', $options->profile);
  25. $this->assertInstanceOf('Predis\Network\IConnectionCluster', $options->cluster);
  26. $this->assertInstanceOf('Predis\IConnectionFactory', $options->connections);
  27. $this->assertNull($options->prefix);
  28. }
  29. /**
  30. * @group disconnected
  31. */
  32. public function testConstructorWithArrayArgument()
  33. {
  34. $options = new ClientOptions(array(
  35. 'cluster' => 'Predis\Network\PredisCluster',
  36. 'connections' => 'Predis\ConnectionFactory',
  37. 'prefix' => 'prefix:',
  38. 'profile' => '2.0',
  39. ));
  40. $this->assertInstanceOf('Predis\Commands\Processors\ICommandProcessor', $options->prefix);
  41. $this->assertInstanceOf('Predis\Network\IConnectionCluster', $options->cluster);
  42. $this->assertInstanceOf('Predis\Profiles\IServerProfile', $options->profile);
  43. $this->assertInstanceOf('Predis\IConnectionFactory', $options->connections);
  44. }
  45. /**
  46. * @group disconnected
  47. */
  48. public function testHandlesCustomOptionsWithoutHandlers()
  49. {
  50. $options = new ClientOptions(array(
  51. 'custom' => 'foobar',
  52. ));
  53. $this->assertSame('foobar', $options->custom);
  54. }
  55. /**
  56. * @group disconnected
  57. */
  58. public function testIsSetReturnsIfOptionHasBeenSetByUser()
  59. {
  60. $options = new ClientOptions(array(
  61. 'prefix' => 'prefix:',
  62. 'custom' => 'foobar',
  63. ));
  64. $this->assertTrue(isset($options->prefix));
  65. $this->assertTrue(isset($options->custom));
  66. $this->assertFalse(isset($options->profile));
  67. }
  68. }