Add '!=' handling to VersionConstraint::matchSpecific
parent
e130386612
commit
9f08764e9a
|
@ -36,6 +36,10 @@ class VersionConstraint extends SpecificConstraint
|
||||||
$operator = '==';
|
$operator = '==';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ('<>' === $operator) {
|
||||||
|
$operator = '!=';
|
||||||
|
}
|
||||||
|
|
||||||
$this->operator = $operator;
|
$this->operator = $operator;
|
||||||
$this->version = $version;
|
$this->version = $version;
|
||||||
}
|
}
|
||||||
|
@ -49,6 +53,18 @@ class VersionConstraint extends SpecificConstraint
|
||||||
$noEqualOp = str_replace('=', '', $this->operator);
|
$noEqualOp = str_replace('=', '', $this->operator);
|
||||||
$providerNoEqualOp = str_replace('=', '', $provider->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
|
// an example for the condition is <= 2.0 & < 1.0
|
||||||
// these kinds of comparisons always have a solution
|
// these kinds of comparisons always have a solution
|
||||||
if ($this->operator != '==' && $noEqualOp == $providerNoEqualOp) {
|
if ($this->operator != '==' && $noEqualOp == $providerNoEqualOp) {
|
||||||
|
|
|
@ -27,6 +27,12 @@ class VersionConstraintTest extends \PHPUnit_Framework_TestCase
|
||||||
array('<=', '2', '>=', '1'),
|
array('<=', '2', '>=', '1'),
|
||||||
array('>=', '1', '<=', '2'),
|
array('>=', '1', '<=', '2'),
|
||||||
array('==', '2', '>=', '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('<=', '1', '>=', '2'),
|
||||||
array('>=', '2', '<=', '1'),
|
array('>=', '2', '<=', '1'),
|
||||||
array('==', '2', '<', '2'),
|
array('==', '2', '<', '2'),
|
||||||
|
array('!=', '1', '==', '1'),
|
||||||
|
array('==', '1', '!=', '1'),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue