123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- <?php
- /*
- * This file is part of the Predis package.
- *
- * (c) Daniele Alessandri <suppakilla@gmail.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
- namespace Predis\Command\Redis;
- use Predis\Response\Status;
- /**
- * @group commands
- * @group realm-server
- */
- class COMMAND_Test extends PredisCommandTestCase
- {
- /**
- * {@inheritdoc}
- */
- protected function getExpectedCommand()
- {
- return 'Predis\Command\Redis\COMMAND';
- }
- /**
- * {@inheritdoc}
- */
- protected function getExpectedId()
- {
- return 'COMMAND';
- }
- /**
- * @group disconnected
- */
- public function testFilterArguments()
- {
- $arguments = array('INFO', 'DEL');
- $expected = array('INFO', 'DEL');
- $command = $this->getCommand();
- $command->setArguments($arguments);
- $this->assertSame($expected, $command->getArguments());
- }
- /**
- * @group disconnected
- */
- public function testParseResponse()
- {
- $raw = array(
- array('get', 2, array(new Status('readonly'), new Status('fast')), 1, 1, 1),
- array('set', -3, array(new Status('write'), new Status('denyoom')), 1, 1, 1),
- array('watch', -2, array(new Status('readonly'), new Status('noscript'), new Status('fast')), 1, -1, 1),
- array('unwatch', 1, array(new Status('readonly'), new Status('noscript'), new Status('fast')), 0, 0, 0),
- array('info', -1, array(new Status('readonly'), new Status('loading'), new Status('stale')), 0, 0, 0),
- );
- $expected = $raw;
- $command = $this->getCommand();
- $this->assertSame($expected, $command->parseResponse($raw));
- }
- /**
- * @group disconnected
- */
- public function testParseEmptyResponse()
- {
- $raw = array(null);
- $expected = array(null);
- $command = $this->getCommand();
- $this->assertSame($expected, $command->parseResponse($raw));
- }
- /**
- * @group connected
- * @requiresRedisVersion >= 2.8.13
- */
- public function testReturnsEmptyCommandInfoOnNonExistingCommand()
- {
- $redis = $this->getClient();
- $this->assertCount(1, $response = $redis->command('INFO', 'FOOBAR'));
- $this->assertSame(array(null), $response);
- }
- /**
- * @group connected
- * @requiresRedisVersion >= 2.8.13
- */
- public function testReturnsCommandInfoOnExistingCommand()
- {
- $redis = $this->getClient();
- // NOTE: we use assertEquals instead of assertSame because Redis returns
- // flags as +STATUS responses, represented by Predis with instances of
- // Predis\Response\Status instead of plain strings. This class responds
- // to __toString() so the string conversion is implicit, but assertSame
- // checks for strict equality while assertEquals is loose.
- $expected = array(array('get', 2, array('readonly', 'fast'), 1, 1, 1));
- $this->assertCount(1, $response = $redis->command('INFO', 'GET'));
- $this->assertEquals($expected, $response);
- }
- /**
- * @group connected
- * @requiresRedisVersion >= 2.8.13
- */
- public function testReturnsListOfCommandInfoWithNoArguments()
- {
- $redis = $this->getClient();
- $this->assertGreaterThan(100, count($response = $redis->command()));
- }
- }
|