Merge branch 'gh/pr/102' into v0.8

This commit is contained in:
Daniele Alessandri
2013-02-08 12:37:43 +01:00
3 changed files with 109 additions and 1 deletions
+2 -1
View File
@@ -35,8 +35,9 @@ class ServerClient extends AbstractCommand
switch (strtoupper($args[0])) {
case 'LIST':
return $this->parseClientList($data);
case 'KILL':
case 'GETNAME':
case 'SETNAME':
default:
return $data;
}
+26
View File
@@ -159,6 +159,32 @@ abstract class CommandTestCase extends StandardTestCase
$this->assertEquals($this->getExpectedId(), $command->getId());
}
/**
* @param string $expectedVersion
* @param string $message Optional message.
* @throws \RuntimeException when unable to retrieve server info or redis version
* @throws \PHPUnit_Framework_SkippedTestError when expected redis version is not met
*/
protected function markTestSkippedOnRedisVersionBelow($expectedVersion, $message = '')
{
$client = $this->getClient();
$info = array_change_key_case($client->info());
if (isset($info['server']['redis_version'])) {
// Redis >= 2.6
$version = $info['server']['redis_version'];
} else if (isset($info['redis_version'])) {
// Redis < 2.6
$version = $info['redis_version'];
} else {
throw new \RuntimeException('Unable to retrieve server info');
}
if (version_compare($version, $expectedVersion) <= -1) {
$this->markTestSkipped($message ?: "Test requires Redis $expectedVersion, current is $version.");
}
}
/**
* @group disconnected
*/
+81
View File
@@ -63,6 +63,32 @@ class ServerClientTest extends CommandTestCase
$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
*/
@@ -117,6 +143,61 @@ BUFFER;
$this->assertArrayHasKey('psub', $clients[0]);
}
/**
* @group connected
*/
public function testGetsNameOfConnection()
{
$this->markTestSkippedOnRedisVersionBelow('2.6.9');
$redis = $this->getClient();
$clientName = $redis->client('GETNAME');
$this->assertNull($clientName);
$expectedConnectionName = 'foo-bar';
$this->assertTrue($redis->client('SETNAME', $expectedConnectionName));
$this->assertEquals($expectedConnectionName, $redis->client('GETNAME'));
}
/**
* @group connected
*/
public function testSetsNameOfConnection()
{
$this->markTestSkippedOnRedisVersionBelow('2.6.9');
$redis = $this->getClient();
$expectedConnectionName = 'foo-baz';
$this->assertTrue($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
* @expectedException Predis\ServerException
* @dataProvider invalidConnectionNameProvider
*/
public function testInvalidSetNameOfConnection($invalidConnectionName)
{
$this->markTestSkippedOnRedisVersionBelow('2.6.9');
$redis = $this->getClient();
$redis->client('SETNAME', $invalidConnectionName);
}
/**
* @group connected
* @expectedException Predis\ServerException