mirror of
https://github.com/predis/predis.git
synced 2026-08-23 21:39:42 +00:00
[tests] Fix version check to work on Redis < 2.6.0.
INFO does not have the concept of sections prior to 2.6.0 while our test suite can be run against 2.4.0 (provided that phpunit.xml uses the correct server profile), so we need to make sure that the check does not break with prior version of Redis even if this is unlikely to happen at this point. Also changed a bit the naming of variables since things are already pretty much explicit in this context.
This commit is contained in:
@@ -160,30 +160,28 @@ abstract class CommandTestCase extends StandardTestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $expectedRedisVersion
|
||||
* @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($expectedRedisVersion, $message = '')
|
||||
protected function markTestSkippedOnRedisVersionBelow($expectedVersion, $message = '')
|
||||
{
|
||||
$client = $this->getClient();
|
||||
$serverInfo = $client->info('SERVER');
|
||||
$serverInfo = array_change_key_case($serverInfo);
|
||||
if (!isset($serverInfo['server'])
|
||||
|| !isset($serverInfo['server']['redis_version']))
|
||||
{
|
||||
$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');
|
||||
}
|
||||
$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);
|
||||
|
||||
if (version_compare($version, $expectedVersion) <= -1) {
|
||||
$this->markTestSkipped($message ?: "Test requires Redis $expectedVersion, current is $version.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user