ServerConfigTest.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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;
  11. /**
  12. * @group commands
  13. * @group realm-server
  14. */
  15. class ServerConfigTest extends PredisCommandTestCase
  16. {
  17. /**
  18. * {@inheritdoc}
  19. */
  20. protected function getExpectedCommand()
  21. {
  22. return 'Predis\Command\ServerConfig';
  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. */
  73. public function testReturnsListOfConfigurationValues()
  74. {
  75. $redis = $this->getClient();
  76. $this->assertInternalType('array', $configs = $redis->config('GET', '*'));
  77. $this->assertGreaterThan(1, count($configs));
  78. $this->assertArrayHasKey('loglevel', $configs);
  79. $this->assertArrayHasKey('appendonly', $configs);
  80. $this->assertArrayHasKey('dbfilename', $configs);
  81. }
  82. /**
  83. * @group connected
  84. */
  85. public function testReturnsListOfOneConfigurationEntry()
  86. {
  87. $redis = $this->getClient();
  88. $this->assertInternalType('array', $configs = $redis->config('GET', 'dbfilename'));
  89. $this->assertEquals(1, count($configs));
  90. $this->assertArrayHasKey('dbfilename', $configs);
  91. }
  92. /**
  93. * @group connected
  94. */
  95. public function testReturnsEmptyListOnUnknownConfigurationEntry()
  96. {
  97. $redis = $this->getClient();
  98. $this->assertSame(array(), $redis->config('GET', 'foobar'));
  99. }
  100. /**
  101. * @group connected
  102. */
  103. public function testReturnsTrueOnSuccessfulConfiguration()
  104. {
  105. $redis = $this->getClient();
  106. $previous = $redis->config('GET', 'loglevel');
  107. $this->assertEquals('OK', $redis->config('SET', 'loglevel', 'notice'));
  108. $this->assertSame(array('loglevel' => 'notice'), $redis->config('GET', 'loglevel'));
  109. // We set the loglevel configuration to the previous value.
  110. $redis->config('SET', 'loglevel', $previous['loglevel']);
  111. }
  112. /**
  113. * @group connected
  114. * @expectedException \Predis\Response\ServerException
  115. * @expectedExceptionMessage ERR Unsupported CONFIG parameter: foo
  116. */
  117. public function testThrowsExceptionWhenSettingUnknownConfiguration()
  118. {
  119. $redis = $this->getClient();
  120. $redis->config('SET', 'foo', 'bar');
  121. }
  122. /**
  123. * @group connected
  124. */
  125. public function testReturnsTrueOnResetstat()
  126. {
  127. $redis = $this->getClient();
  128. $this->assertEquals('OK', $redis->config('RESETSTAT'));
  129. }
  130. /**
  131. * @group connected
  132. * @expectedException \Predis\Response\ServerException
  133. */
  134. public function testThrowsExceptionOnUnknownSubcommand()
  135. {
  136. $redis = $this->getClient();
  137. $redis->config('FOO');
  138. }
  139. }