diff --git a/core/Plugin/Dependency.php b/core/Plugin/Dependency.php index 733c1be2c0f57bfa4ea57ff44faffefcb09b6bde..0448f8a721c4f73b9548992ae696b86ccf309162 100644 --- a/core/Plugin/Dependency.php +++ b/core/Plugin/Dependency.php @@ -49,6 +49,7 @@ class Dependency public function getMissingVersions($currentVersion, $requiredVersion) { + $currentVersion = trim($currentVersion); $requiredVersions = explode(',' , (string) $requiredVersion); $missingVersions = array(); @@ -56,11 +57,13 @@ class Dependency foreach ($requiredVersions as $required) { $comparison = '>='; + $required = trim($required); if (preg_match('{^(<>|!=|>=?|<=?|==?)\s*(.*)}', $required, $matches)) { $required = $matches[2]; - $comparison = $matches[1]; + $comparison = trim($matches[1]); } + if (false === version_compare($currentVersion, $required, $comparison)) { $missingVersions[] = $comparison . $required; } diff --git a/tests/PHPUnit/Core/DependencyTest.php b/tests/PHPUnit/Core/DependencyTest.php index 4444d33424ac7213429b0578d9c41b6315b9a8cf..3bd1bd579379abba74aa8998bdaaf4a3f4aa436a 100644 --- a/tests/PHPUnit/Core/DependencyTest.php +++ b/tests/PHPUnit/Core/DependencyTest.php @@ -149,6 +149,14 @@ class DependencyTest extends PHPUnit_Framework_TestCase $this->assertMissingVersion('5.5', '', array()); } + public function test_getMissingVersion_shouldIgnoreAnyWhitespace() + { + $this->assertMissingVersion('5.5 ', '5.5', array()); + $this->assertMissingVersion(' 5.5 ', '5.5', array()); + $this->assertMissingVersion('5.5', ' 5.5', array()); + $this->assertMissingVersion('5.5', ' 5.5 ', array()); + } + public function test_getMissingVersion_NoComparisonDefined_ShouldUseGreatherThanOrEqualByDefault() { $this->assertMissingVersion('5.4', '5.2', array()); @@ -214,6 +222,15 @@ class DependencyTest extends PHPUnit_Framework_TestCase $this->assertMissingVersion('5.4', '<2.0,>=9.0', array('<2.0', '>=9.0')); } + public function test_getMissingVersion_AND_Condition_shouldIgnoreAnyWhitespace() + { + $this->assertMissingVersion('5.2', '5.5 , 5.4, 5.3', array('>=5.5', '>=5.4', '>=5.3')); + $this->assertMissingVersion('5.5', '5.5 , 5.4, 5.3', array()); + $this->assertMissingVersion(' 5.2 ', '5.5 , 5.4, 5.3', array('>=5.5', '>=5.4', '>=5.3')); + $this->assertMissingVersion(' 5.2 ', '>5.5 , <5.4, ==5.3', array('>5.5', '==5.3')); + $this->assertMissingVersion(' 5.2 ', '>5.5 , !=5.4, ==5.3', array('>5.5', '==5.3')); + } + public function test_getMissingVersion() { $this->assertMissingVersion('5.2', '<5.2,>9.0', array('<5.2', '>9.0'));