ServerConfigTest.php 4.2 KB

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