1
0
Fork 0

Add '!=' handling to VersionConstraint::matchSpecific

pull/808/head
Alexey Prilipko 2012-06-19 23:37:29 +11:00
parent e130386612
commit 9f08764e9a
2 changed files with 24 additions and 0 deletions

View File

@ -36,6 +36,10 @@ class VersionConstraint extends SpecificConstraint
$operator = '==';
}
if ('<>' === $operator) {
$operator = '!=';
}
$this->operator = $operator;
$this->version = $version;
}
@ -49,6 +53,18 @@ class VersionConstraint extends SpecificConstraint
$noEqualOp = str_replace('=', '', $this->operator);
$providerNoEqualOp = str_replace('=', '', $provider->operator);
$isEqualOp = '==' === $this->operator;
$isNonEqualOp = '!=' === $this->operator;
$isProviderEqualOp = '==' === $provider->operator;
$isProviderNonEqualOp = '!=' === $provider->operator;
// '!=' operator is match when other operator is not '==' operator or version is not match
// these kinds of comparisons always have a solution
if ($isNonEqualOp || $isProviderNonEqualOp) {
return !$isEqualOp && !$isProviderEqualOp
|| version_compare($provider->version, $this->version, '!=');
}
// an example for the condition is <= 2.0 & < 1.0
// these kinds of comparisons always have a solution
if ($this->operator != '==' && $noEqualOp == $providerNoEqualOp) {

View File

@ -27,6 +27,12 @@ class VersionConstraintTest extends \PHPUnit_Framework_TestCase
array('<=', '2', '>=', '1'),
array('>=', '1', '<=', '2'),
array('==', '2', '>=', '2'),
array('!=', '1', '!=', '1'),
array('!=', '1', '==', '2'),
array('!=', '1', '<', '1'),
array('!=', '1', '<=', '1'),
array('!=', '1', '>', '1'),
array('!=', '1', '>=', '1'),
);
}
@ -53,6 +59,8 @@ class VersionConstraintTest extends \PHPUnit_Framework_TestCase
array('<=', '1', '>=', '2'),
array('>=', '2', '<=', '1'),
array('==', '2', '<', '2'),
array('!=', '1', '==', '1'),
array('==', '1', '!=', '1'),
);
}