mirror of
https://github.com/predis/predis.git
synced 2026-09-15 04:47:01 +00:00
Added PHPUnit utility method markTestSkippedOnRedisVersionBelow and applied it where necessary
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user