From 5cd4f41424847deaccc6009258b0d8014e525ef3 Mon Sep 17 00:00:00 2001 From: Daniele Alessandri Date: Tue, 7 Jul 2015 17:43:49 +0200 Subject: [PATCH] [tests] Fix base test case class to handle required Redis versions. This change is needed due to some internal changes in one of the latest minor releases of PHPUnit 4.x that essentially broke how we were checking for the required Redis version from method annotations. --- tests/PHPUnit/PredisTestCase.php | 42 +++++++++++++------------------- 1 file changed, 17 insertions(+), 25 deletions(-) diff --git a/tests/PHPUnit/PredisTestCase.php b/tests/PHPUnit/PredisTestCase.php index 6240697a..ac871798 100644 --- a/tests/PHPUnit/PredisTestCase.php +++ b/tests/PHPUnit/PredisTestCase.php @@ -256,7 +256,7 @@ abstract class PredisTestCase extends \PHPUnit_Framework_TestCase /** * */ - protected function setRequiredRedisVersionFromAnnotation() + protected function getRequiredRedisServerVersion() { $annotations = $this->getAnnotations(); @@ -264,49 +264,41 @@ abstract class PredisTestCase extends \PHPUnit_Framework_TestCase !empty($annotations['method']['requiresRedisVersion']) && in_array('connected', $annotations['method']['group']) ) { - $this->predisRequirements['requiresRedisVersion'] = $annotations['method']['requiresRedisVersion'][0]; + return $annotations['method']['requiresRedisVersion'][0]; } + + return null; } /** * */ - protected function checkRequiredRedisVersion() + protected function checkRequiredRedisServerVersion() { - if (!isset($this->predisRequirements['requiresRedisVersion'])) { + if (!$requiredVersion = $this->getRequiredRedisServerVersion()) { return; } - $srvVersion = $this->getRedisServerVersion(); - $expectation = explode(' ', $this->predisRequirements['requiresRedisVersion'], 2); + $serverVersion = $this->getRedisServerVersion(); + $requiredVersion = explode(' ', $requiredVersion, 2); - if (count($expectation) === 1) { - $expOperator = '>='; - $expVersion = $expectation[0]; + if (count($requiredVersion) === 1) { + $reqOperator = '>='; + $reqVersion = $requiredVersion[0]; } else { - $expOperator = $expectation[0]; - $expVersion = $expectation[1]; + $reqOperator = $requiredVersion[0]; + $reqVersion = $requiredVersion[1]; } - $comparation = version_compare($srvVersion, $expVersion); + $comparation = version_compare($serverVersion, $reqVersion); - if (!$match = eval("return $comparation $expOperator 0;")) { + if (!$match = eval("return $comparation $reqOperator 0;")) { $this->markTestSkipped( - "This test requires Redis $expOperator $expVersion but the current version is $srvVersion." + "This test requires Redis $reqOperator $reqVersion but the current version is $serverVersion." ); } } - /** - * {@inheritdoc} - */ - protected function setRequirementsFromAnnotation() - { - parent::setRequirementsFromAnnotation(); - - $this->setRequiredRedisVersionFromAnnotation(); - } - /** * {@inheritdoc} */ @@ -314,6 +306,6 @@ abstract class PredisTestCase extends \PHPUnit_Framework_TestCase { parent::checkRequirements(); - $this->checkRequiredRedisVersion(); + $this->checkRequiredRedisServerVersion(); } }