Added PHPUnit utility method markTestSkippedOnRedisVersionBelow and applied it where necessary

This commit is contained in:
Raphael Stolt
2013-02-07 22:46:25 +01:00
parent 1536455fea
commit 06d5475129
2 changed files with 34 additions and 0 deletions
+28
View File
@@ -159,6 +159,34 @@ abstract class CommandTestCase extends StandardTestCase
$this->assertEquals($this->getExpectedId(), $command->getId());
}
/**
* @param string $expectedRedisVersion
* @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($expectedRedisVersion, $message = '')
{
$client = $this->getClient();
$serverInfo = $client->info('SERVER');
$serverInfo = array_change_key_case($serverInfo);
if (!isset($serverInfo['server'])
|| !isset($serverInfo['server']['redis_version']))
{
throw new \RuntimeException('Unable to retrieve server info');
}
$serverVersion = $serverInfo['server']['redis_version'];
if (version_compare($serverVersion, $expectedRedisVersion) <= -1) {
if ($message === '') {
$message = sprintf(
'Test skipped as required Redis version %s was not met.',
$expectedRedisVersion
);
}
throw new \PHPUnit_Framework_SkippedTestError($message);
}
}
/**
* @group disconnected
*/
@@ -148,6 +148,8 @@ BUFFER;
*/
public function testGetsNameOfConnection()
{
$this->markTestSkippedOnRedisVersionBelow('2.6.9');
$redis = $this->getClient();
$clientName = $redis->client('GETNAME');
$this->assertNull($clientName);
@@ -162,6 +164,8 @@ BUFFER;
*/
public function testSetsNameOfConnection()
{
$this->markTestSkippedOnRedisVersionBelow('2.6.9');
$redis = $this->getClient();
$expectedConnectionName = 'foo-baz';
@@ -188,6 +192,8 @@ BUFFER;
*/
public function testInvalidSetNameOfConnection($invalidConnectionName)
{
$this->markTestSkippedOnRedisVersionBelow('2.6.9');
$redis = $this->getClient();
$redis->client('SETNAME', $invalidConnectionName);
}