COMMAND_Test.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. use Predis\Response\Status;
  12. /**
  13. * @group commands
  14. * @group realm-server
  15. */
  16. class COMMAND_Test extends PredisCommandTestCase
  17. {
  18. /**
  19. * {@inheritdoc}
  20. */
  21. protected function getExpectedCommand()
  22. {
  23. return 'Predis\Command\Redis\COMMAND';
  24. }
  25. /**
  26. * {@inheritdoc}
  27. */
  28. protected function getExpectedId()
  29. {
  30. return 'COMMAND';
  31. }
  32. /**
  33. * @group disconnected
  34. */
  35. public function testFilterArguments()
  36. {
  37. $arguments = array('INFO', 'DEL');
  38. $expected = array('INFO', 'DEL');
  39. $command = $this->getCommand();
  40. $command->setArguments($arguments);
  41. $this->assertSame($expected, $command->getArguments());
  42. }
  43. /**
  44. * @group disconnected
  45. */
  46. public function testParseResponse()
  47. {
  48. $raw = array(
  49. array('get', 2, array(new Status('readonly'), new Status('fast')), 1, 1, 1),
  50. array('set', -3, array(new Status('write'), new Status('denyoom')), 1, 1, 1),
  51. array('watch', -2, array(new Status('readonly'), new Status('noscript'), new Status('fast')), 1, -1, 1),
  52. array('unwatch', 1, array(new Status('readonly'), new Status('noscript'), new Status('fast')), 0, 0, 0),
  53. array('info', -1, array(new Status('readonly'), new Status('loading'), new Status('stale')), 0, 0, 0),
  54. );
  55. $expected = $raw;
  56. $command = $this->getCommand();
  57. $this->assertSame($expected, $command->parseResponse($raw));
  58. }
  59. /**
  60. * @group disconnected
  61. */
  62. public function testParseEmptyResponse()
  63. {
  64. $raw = array(null);
  65. $expected = array(null);
  66. $command = $this->getCommand();
  67. $this->assertSame($expected, $command->parseResponse($raw));
  68. }
  69. /**
  70. * @group connected
  71. * @requiresRedisVersion >= 2.8.13
  72. */
  73. public function testReturnsEmptyCommandInfoOnNonExistingCommand()
  74. {
  75. $redis = $this->getClient();
  76. $this->assertCount(1, $response = $redis->command('INFO', 'FOOBAR'));
  77. $this->assertSame(array(null), $response);
  78. }
  79. /**
  80. * @group connected
  81. * @requiresRedisVersion >= 2.8.13
  82. */
  83. public function testReturnsCommandInfoOnExistingCommand()
  84. {
  85. $redis = $this->getClient();
  86. // NOTE: we use assertEquals instead of assertSame because Redis returns
  87. // flags as +STATUS responses, represented by Predis with instances of
  88. // Predis\Response\Status instead of plain strings. This class responds
  89. // to __toString() so the string conversion is implicit, but assertSame
  90. // checks for strict equality while assertEquals is loose.
  91. $expected = array(array('get', 2, array('readonly', 'fast'), 1, 1, 1));
  92. $this->assertCount(1, $response = $redis->command('INFO', 'GET'));
  93. $this->assertEquals($expected, $response);
  94. }
  95. /**
  96. * @group connected
  97. * @requiresRedisVersion >= 2.8.13
  98. */
  99. public function testReturnsListOfCommandInfoWithNoArguments()
  100. {
  101. $redis = $this->getClient();
  102. $this->assertGreaterThan(100, count($response = $redis->command()));
  103. }
  104. }