ServerCommandTest.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. use Predis\Response\Status;
  12. /**
  13. * @group commands
  14. * @group realm-server
  15. */
  16. class ServerCommandTest extends PredisCommandTestCase
  17. {
  18. /**
  19. * {@inheritdoc}
  20. */
  21. protected function getExpectedCommand()
  22. {
  23. return 'Predis\Command\ServerCommand';
  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. */
  72. public function testReturnsEmptyCommandInfoOnNonExistingCommand()
  73. {
  74. $redis = $this->getClient();
  75. $this->assertCount(1, $response = $redis->command('INFO', 'FOOBAR'));
  76. $this->assertSame(array(null), $response);
  77. }
  78. /**
  79. * @group connected
  80. */
  81. public function testReturnsCommandInfoOnExistingCommand()
  82. {
  83. $redis = $this->getClient();
  84. // NOTE: we use assertEquals instead of assertSame because Redis returns
  85. // flags as +STATUS responses, represented by Predis with instances of
  86. // Predis\Response\Status instead of plain strings. This class responds
  87. // to __toString() so the string conversion is implicit, but assertSame
  88. // checks for strict equality while assertEquals is loose.
  89. $expected = array(array('command', 0, array('readonly', 'loading', 'stale'), 0, 0, 0));
  90. $this->assertCount(1, $response = $redis->command('INFO', 'COMMAND'));
  91. $this->assertEquals($expected, $response);
  92. }
  93. /**
  94. * @group connected
  95. */
  96. public function testReturnsListOfCommandInfoWithNoArguments()
  97. {
  98. $redis = $this->getClient();
  99. $this->assertGreaterThan(100, count($response = $redis->command()));
  100. }
  101. }