Skip to content
Extraits de code Groupes Projets
Valider 218e898c rédigé par Thomas Steur's avatar Thomas Steur
Parcourir les fichiers

refs #4967 handle whitespace

parent 8fb9e31d
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -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;
}
......
......@@ -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'));
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter