123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224 |
- <?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;
- /**
- * @group commands
- * @group realm-server
- */
- class CLIENT_Test extends PredisCommandTestCase
- {
- /**
- * {@inheritdoc}
- */
- protected function getExpectedCommand()
- {
- return 'Predis\Command\Redis\CLIENT';
- }
- /**
- * {@inheritdoc}
- */
- protected function getExpectedId()
- {
- return 'CLIENT';
- }
- /**
- * @group disconnected
- */
- public function testFilterArgumentsOfClientKill()
- {
- $arguments = array('kill', '127.0.0.1:45393');
- $expected = array('kill', '127.0.0.1:45393');
- $command = $this->getCommand();
- $command->setArguments($arguments);
- $this->assertSame($expected, $command->getArguments());
- }
- /**
- * @group disconnected
- */
- public function testFilterArgumentsOfClientList()
- {
- $arguments = array('list');
- $expected = array('list');
- $command = $this->getCommand();
- $command->setArguments($arguments);
- $this->assertSame($expected, $command->getArguments());
- }
- /**
- * @group disconnected
- */
- public function testFilterArgumentsOfClientGetname()
- {
- $arguments = $expected = array('getname');
- $command = $this->getCommand();
- $command->setArguments($arguments);
- $this->assertSame($expected, $command->getArguments());
- }
- /**
- * @group disconnected
- */
- public function testFilterArgumentsOfClientSetname()
- {
- $arguments = $expected = array('setname', 'connection-a');
- $command = $this->getCommand();
- $command->setArguments($arguments);
- $this->assertSame($expected, $command->getArguments());
- }
- /**
- * @group disconnected
- */
- public function testParseResponseOfClientKill()
- {
- $command = $this->getCommand();
- $command->setArguments(array('kill'));
- $this->assertSame(true, $command->parseResponse(true));
- }
- /**
- * @group disconnected
- */
- public function testParseResponseOfClientList()
- {
- $command = $this->getCommand();
- $command->setArguments(array('list'));
- $raw = <<<BUFFER
- addr=127.0.0.1:45393 fd=6 idle=0 flags=N db=0 sub=0 psub=0
- addr=127.0.0.1:45394 fd=7 idle=0 flags=N db=0 sub=0 psub=0
- addr=127.0.0.1:45395 fd=8 idle=0 flags=N db=0 sub=0 psub=0
- BUFFER;
- $parsed = array(
- array('addr' => '127.0.0.1:45393', 'fd' => '6', 'idle' => '0', 'flags' => 'N', 'db' => '0', 'sub' => '0', 'psub' => '0'),
- array('addr' => '127.0.0.1:45394', 'fd' => '7', 'idle' => '0', 'flags' => 'N', 'db' => '0', 'sub' => '0', 'psub' => '0'),
- array('addr' => '127.0.0.1:45395', 'fd' => '8', 'idle' => '0', 'flags' => 'N', 'db' => '0', 'sub' => '0', 'psub' => '0'),
- );
- $this->assertSame($parsed, $command->parseResponse($raw));
- }
- /**
- * @group connected
- * @requiresRedisVersion >= 2.4.0
- */
- public function testReturnsListOfConnectedClients()
- {
- $redis = $this->getClient();
- $this->assertInternalType('array', $clients = $redis->client('LIST'));
- $this->assertGreaterThanOrEqual(1, count($clients));
- $this->assertInternalType('array', $clients[0]);
- $this->assertArrayHasKey('addr', $clients[0]);
- $this->assertArrayHasKey('fd', $clients[0]);
- $this->assertArrayHasKey('idle', $clients[0]);
- $this->assertArrayHasKey('flags', $clients[0]);
- $this->assertArrayHasKey('db', $clients[0]);
- $this->assertArrayHasKey('sub', $clients[0]);
- $this->assertArrayHasKey('psub', $clients[0]);
- }
- /**
- * @group connected
- * @requiresRedisVersion >= 2.6.9
- */
- public function testGetsNameOfConnection()
- {
- $redis = $this->getClient();
- $clientName = $redis->client('GETNAME');
- $this->assertNull($clientName);
- $expectedConnectionName = 'foo-bar';
- $this->assertEquals('OK', $redis->client('SETNAME', $expectedConnectionName));
- $this->assertEquals($expectedConnectionName, $redis->client('GETNAME'));
- }
- /**
- * @group connected
- * @requiresRedisVersion >= 2.6.9
- */
- public function testSetsNameOfConnection()
- {
- $redis = $this->getClient();
- $expectedConnectionName = 'foo-baz';
- $this->assertEquals('OK', $redis->client('SETNAME', $expectedConnectionName));
- $this->assertEquals($expectedConnectionName, $redis->client('GETNAME'));
- }
- /**
- * @return array
- */
- public function invalidConnectionNameProvider()
- {
- return array(
- array('foo space'),
- array('foo \n'),
- array('foo $'),
- );
- }
- /**
- * @group connected
- * @requiresRedisVersion >= 2.6.9
- * @dataProvider invalidConnectionNameProvider
- *
- * @expectedException \Predis\Response\ServerException
- *
- * @param string $invalidConnectionName
- */
- public function testInvalidSetNameOfConnection($invalidConnectionName)
- {
- $redis = $this->getClient();
- $redis->client('SETNAME', $invalidConnectionName);
- }
- /**
- * @group connected
- * @requiresRedisVersion >= 2.4.0
- * @expectedException \Predis\Response\ServerException
- */
- public function testThrowsExceptioOnWrongModifier()
- {
- $redis = $this->getClient();
- $redis->client('FOO');
- }
- /**
- * @group connected
- * @requiresRedisVersion >= 2.4.0
- * @expectedException \Predis\Response\ServerException
- * @expectedExceptionMessage ERR No such client
- */
- public function testThrowsExceptionWhenKillingUnknownClient()
- {
- $redis = $this->getClient();
- $redis->client('KILL', '127.0.0.1:65535');
- }
- }
|