CONFIG_Test.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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\Command\Redis;
  11. /**
  12. * @group commands
  13. * @group realm-server
  14. */
  15. class CONFIG_Test extends PredisCommandTestCase
  16. {
  17. /**
  18. * {@inheritdoc}
  19. */
  20. protected function getExpectedCommand()
  21. {
  22. return 'Predis\Command\Redis\CONFIG';
  23. }
  24. /**
  25. * {@inheritdoc}
  26. */
  27. protected function getExpectedId()
  28. {
  29. return 'CONFIG';
  30. }
  31. /**
  32. * @group disconnected
  33. */
  34. public function testFilterArguments()
  35. {
  36. $arguments = array('GET', 'slowlog');
  37. $expected = array('GET', 'slowlog');
  38. $command = $this->getCommand();
  39. $command->setArguments($arguments);
  40. $this->assertSame($expected, $command->getArguments());
  41. }
  42. /**
  43. * @group disconnected
  44. */
  45. public function testParseResponseOfConfigGet()
  46. {
  47. $raw = array('slowlog-log-slower-than', '10000', 'slowlog-max-len', '64', 'loglevel', 'verbose');
  48. $expected = array(
  49. 'slowlog-log-slower-than' => '10000',
  50. 'slowlog-max-len' => '64',
  51. 'loglevel' => 'verbose',
  52. );
  53. $command = $this->getCommand();
  54. $this->assertSame($expected, $command->parseResponse($raw));
  55. }
  56. /**
  57. * @group disconnected
  58. */
  59. public function testParseResponseOfConfigSet()
  60. {
  61. $this->assertSame('OK', $this->getCommand()->parseResponse('OK'));
  62. }
  63. /**
  64. * @group disconnected
  65. */
  66. public function testParseResponseOfConfigResetstat()
  67. {
  68. $this->assertSame('OK', $this->getCommand()->parseResponse('OK'));
  69. }
  70. /**
  71. * @group connected
  72. * @requiresRedisVersion >= 2.0.0
  73. */
  74. public function testReturnsListOfConfigurationValues()
  75. {
  76. $redis = $this->getClient();
  77. $this->assertInternalType('array', $configs = $redis->config('GET', '*'));
  78. $this->assertGreaterThan(1, count($configs));
  79. $this->assertArrayHasKey('loglevel', $configs);
  80. $this->assertArrayHasKey('appendonly', $configs);
  81. $this->assertArrayHasKey('dbfilename', $configs);
  82. }
  83. /**
  84. * @group connected
  85. * @requiresRedisVersion >= 2.0.0
  86. */
  87. public function testReturnsListOfOneConfigurationEntry()
  88. {
  89. $redis = $this->getClient();
  90. $this->assertInternalType('array', $configs = $redis->config('GET', 'dbfilename'));
  91. $this->assertEquals(1, count($configs));
  92. $this->assertArrayHasKey('dbfilename', $configs);
  93. }
  94. /**
  95. * @group connected
  96. * @requiresRedisVersion >= 2.0.0
  97. */
  98. public function testReturnsEmptyListOnUnknownConfigurationEntry()
  99. {
  100. $redis = $this->getClient();
  101. $this->assertSame(array(), $redis->config('GET', 'foobar'));
  102. }
  103. /**
  104. * @group connected
  105. * @requiresRedisVersion >= 2.0.0
  106. */
  107. public function testReturnsTrueOnSuccessfulConfiguration()
  108. {
  109. $redis = $this->getClient();
  110. $previous = $redis->config('GET', 'loglevel');
  111. $this->assertEquals('OK', $redis->config('SET', 'loglevel', 'notice'));
  112. $this->assertSame(array('loglevel' => 'notice'), $redis->config('GET', 'loglevel'));
  113. // We set the loglevel configuration to the previous value.
  114. $redis->config('SET', 'loglevel', $previous['loglevel']);
  115. }
  116. /**
  117. * @group connected
  118. * @requiresRedisVersion >= 2.0.0
  119. * @expectedException \Predis\Response\ServerException
  120. * @expectedExceptionMessage ERR Unsupported CONFIG parameter: foo
  121. */
  122. public function testThrowsExceptionWhenSettingUnknownConfiguration()
  123. {
  124. $redis = $this->getClient();
  125. $redis->config('SET', 'foo', 'bar');
  126. }
  127. /**
  128. * @group connected
  129. * @requiresRedisVersion >= 2.0.0
  130. */
  131. public function testReturnsTrueOnResetstat()
  132. {
  133. $redis = $this->getClient();
  134. $this->assertEquals('OK', $redis->config('RESETSTAT'));
  135. }
  136. /**
  137. * @group connected
  138. * @requiresRedisVersion >= 2.0.0
  139. * @expectedException \Predis\Response\ServerException
  140. */
  141. public function testThrowsExceptionOnUnknownSubcommand()
  142. {
  143. $redis = $this->getClient();
  144. $redis->config('FOO');
  145. }
  146. }