Correctly treat dev versions for other types of comparisons and add tests
parent
bbdbfc97ea
commit
560c3254d4
|
@ -44,6 +44,15 @@ class VersionConstraint extends SpecificConstraint
|
|||
$this->version = $version;
|
||||
}
|
||||
|
||||
public function versionCompare($a, $b, $operator)
|
||||
{
|
||||
if ('dev-' === substr($a, 0, 4) && 'dev-' === substr($b, 0, 4)) {
|
||||
return $operator == '==' && $a === $b;
|
||||
}
|
||||
|
||||
return version_compare($a, $b, $operator);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param VersionConstraint $provider
|
||||
|
@ -58,16 +67,11 @@ class VersionConstraint extends SpecificConstraint
|
|||
$isProviderEqualOp = '==' === $provider->operator;
|
||||
$isProviderNonEqualOp = '!=' === $provider->operator;
|
||||
|
||||
// dev- versions can not be compared with version_compare
|
||||
if ('dev-' === substr($provider->version, 0, 4) && 'dev-' === substr($this->version, 0, 4)) {
|
||||
return $isEqualOp && $isProviderEqualOp && $provider->version === $this->version;
|
||||
}
|
||||
|
||||
// '!=' 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, '!=');
|
||||
|| $this->versionCompare($provider->version, $this->version, '!=');
|
||||
}
|
||||
|
||||
// an example for the condition is <= 2.0 & < 1.0
|
||||
|
@ -76,7 +80,7 @@ class VersionConstraint extends SpecificConstraint
|
|||
return true;
|
||||
}
|
||||
|
||||
if (version_compare($provider->version, $this->version, $this->operator)) {
|
||||
if ($this->versionCompare($provider->version, $this->version, $this->operator)) {
|
||||
// special case, e.g. require >= 1.0 and provide < 1.0
|
||||
// 1.0 >= 1.0 but 1.0 is outside of the provided interval
|
||||
if ($provider->version == $this->version && $provider->operator == $providerNoEqualOp && $this->operator != $noEqualOp) {
|
||||
|
|
|
@ -34,6 +34,12 @@ class VersionConstraintTest extends \PHPUnit_Framework_TestCase
|
|||
array('!=', '1', '>', '1'),
|
||||
array('!=', '1', '>=', '1'),
|
||||
array('==', 'dev-foo-bar', '==', 'dev-foo-bar'),
|
||||
array('==', 'dev-foo-xyz', '==', 'dev-foo-xyz'),
|
||||
array('>=', 'dev-foo-bar', '>=', 'dev-foo-xyz'),
|
||||
array('<=', 'dev-foo-bar', '<', 'dev-foo-xyz'),
|
||||
array('!=', 'dev-foo-bar', '<', 'dev-foo-xyz'),
|
||||
array('>=', 'dev-foo-bar', '!=', 'dev-foo-bar'),
|
||||
array('!=', 'dev-foo-bar', '!=', 'dev-foo-xyz'),
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -63,6 +69,9 @@ class VersionConstraintTest extends \PHPUnit_Framework_TestCase
|
|||
array('!=', '1', '==', '1'),
|
||||
array('==', '1', '!=', '1'),
|
||||
array('==', 'dev-foo-dist', '==', 'dev-foo-zist'),
|
||||
array('==', 'dev-foo-bist', '==', 'dev-foo-aist'),
|
||||
array('<=', 'dev-foo-bist', '>=', 'dev-foo-aist'),
|
||||
array('>=', 'dev-foo-bist', '<', 'dev-foo-aist'),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue