mirror of
https://github.com/predis/predis.git
synced 2026-08-23 06:41:55 +00:00
dc14c29676
Now we follow a Symfony2-like naming convention for namespaces, interfaces and classes sticking with one clear rule. - Renamed namespaces: - Predis\Network - Predis\Profiles - Predis\Iterators - Predis\Options - Predis\Commands - Predis\Commands\Processors - Renamed interfaces: - Predis\IReplyObject - Predis\IRedisServerError - Predis\IConnectionFactory - Predis\IConnectionParameters - Predis\Options\IOption - Predis\Options\IClientOptions - Predis\Profile\IServerProfile - Predis\Pipeline\IPipelineExecutor - Predis\Distribution\INodeKeyGenerator - Predis\Distribution\IDistributionStrategy - Predis\Protocol\IProtocolProcessor - Predis\Protocol\IResponseReader - Predis\Protocol\IResponseHandler - Predis\Protocol\ICommandSerializer - Predis\Protocol\IComposableProtocolProcessor - Predis\Network\IConnection - Predis\Network\IConnectionSingle - Predis\Network\IConnectionComposable - Predis\Network\IConnectionCluster - Predis\Network\IConnectionReplication - Predis\Commands\ICommand - Predis\Commands\IPrefixable - Predis\Command\Processor\ICommandProcessor - Predis\Command\Processor\ICommandProcessorChain - Predis\Command\Processor\IProcessingSupport - Renamed Classes: - Predis\Commands\Command - Predis\Network\ConnectionBase - Classes moved to different namespaces: - Predis\MonitorContext Meh
143 lines
3.7 KiB
PHP
143 lines
3.7 KiB
PHP
<?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;
|
|
|
|
use \PHPUnit_Framework_TestCase as StandardTestCase;
|
|
|
|
/**
|
|
* @group commands
|
|
* @group realm-server
|
|
*/
|
|
class ServerClientTest extends CommandTestCase
|
|
{
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
protected function getExpectedCommand()
|
|
{
|
|
return 'Predis\Command\ServerClient';
|
|
}
|
|
|
|
/**
|
|
* {@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 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
|
|
*/
|
|
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
|
|
* @expectedException Predis\ServerException
|
|
*/
|
|
public function testThrowsExceptioOnWrongModifier()
|
|
{
|
|
$redis = $this->getClient();
|
|
|
|
$this->assertTrue($redis->client('FOO'));
|
|
}
|
|
|
|
/**
|
|
* @group connected
|
|
* @expectedException Predis\ServerException
|
|
* @expectedExceptionMessage ERR No such client
|
|
*/
|
|
public function testThrowsExceptionWhenKillingUnknownClient()
|
|
{
|
|
$redis = $this->getClient();
|
|
|
|
$this->assertTrue($redis->client('KILL', '127.0.0.1:65535'));
|
|
}
|
|
}
|