ServerConfigTest.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. $command = $this->getCommand();
  62. $this->assertTrue($command->parseResponse(true));
  63. }
  64. /**
  65. * @group disconnected
  66. */
  67. public function testParseResponseOfConfigResetstat()
  68. {
  69. $command = $this->getCommand();
  70. $this->assertTrue($command->parseResponse(true));
  71. }
  72. /**
  73. * @group connected
  74. */
  75. public function testReturnsListOfConfigurationValues()
  76. {
  77. $redis = $this->getClient();
  78. $this->assertInternalType('array', $configs = $redis->config('GET', '*'));
  79. $this->assertGreaterThan(1, count($configs));
  80. $this->assertArrayHasKey('loglevel', $configs);
  81. $this->assertArrayHasKey('appendonly', $configs);
  82. $this->assertArrayHasKey('dbfilename', $configs);
  83. }
  84. /**
  85. * @group connected
  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. */
  97. public function testReturnsEmptyListOnUnknownConfigurationEntry()
  98. {
  99. $redis = $this->getClient();
  100. $this->assertSame(array(), $redis->config('GET', 'foobar'));
  101. }
  102. /**
  103. * @group connected
  104. */
  105. public function testReturnsTrueOnSuccessfulConfiguration()
  106. {
  107. $redis = $this->getClient();
  108. $previous = $redis->config('GET', 'loglevel');
  109. $this->assertTrue($redis->config('SET', 'loglevel', 'notice'));
  110. $this->assertSame(array('loglevel' => 'notice'), $redis->config('GET', 'loglevel'));
  111. // We set the loglevel configuration to the previous value.
  112. $redis->config('SET', 'loglevel', $previous['loglevel']);
  113. }
  114. /**
  115. * @group connected
  116. * @expectedException Predis\ServerException
  117. * @expectedExceptionMessage ERR Unsupported CONFIG parameter: foo
  118. */
  119. public function testThrowsExceptionWhenSettingUnknownConfiguration()
  120. {
  121. $redis = $this->getClient();
  122. $this->assertFalse($redis->config('SET', 'foo', 'bar'));
  123. }
  124. /**
  125. * @group connected
  126. */
  127. public function testReturnsTrueOnResetstat()
  128. {
  129. $redis = $this->getClient();
  130. $this->assertTrue($redis->config('RESETSTAT'));
  131. }
  132. /**
  133. * @group connected
  134. * @expectedException Predis\ServerException
  135. */
  136. public function testThrowsExceptionOnUnknownSubcommand()
  137. {
  138. $redis = $this->getClient();
  139. $this->assertFalse($redis->config('FOO'));
  140. }
  141. }