Merge branch 'versioncomp'

* versioncomp:
  Correctly treat dev versions for other types of comparisons and add tests
  Remove useless ternary operator
  Prevent seeing dev versions as equal when they are not, fixes #848
main
Nils Adermann 12 years ago
commit 302948db3e

@ -49,7 +49,7 @@ class DefaultPolicy implements PolicyInterface
public function selectPreferedPackages(Pool $pool, array $installedMap, array $literals) public function selectPreferedPackages(Pool $pool, array $installedMap, array $literals)
{ {
$packages = $this->groupLiteralsByNamePreferInstalled($pool,$installedMap, $literals); $packages = $this->groupLiteralsByNamePreferInstalled($pool, $installedMap, $literals);
foreach ($packages as &$literals) { foreach ($packages as &$literals) {
$policy = $this; $policy = $this;

@ -44,6 +44,15 @@ class VersionConstraint extends SpecificConstraint
$this->version = $version; $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 * @param VersionConstraint $provider
@ -62,7 +71,7 @@ class VersionConstraint extends SpecificConstraint
// these kinds of comparisons always have a solution // these kinds of comparisons always have a solution
if ($isNonEqualOp || $isProviderNonEqualOp) { if ($isNonEqualOp || $isProviderNonEqualOp) {
return !$isEqualOp && !$isProviderEqualOp 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 // an example for the condition is <= 2.0 & < 1.0
@ -71,7 +80,7 @@ class VersionConstraint extends SpecificConstraint
return true; 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 // special case, e.g. require >= 1.0 and provide < 1.0
// 1.0 >= 1.0 but 1.0 is outside of the provided interval // 1.0 >= 1.0 but 1.0 is outside of the provided interval
if ($provider->version == $this->version && $provider->operator == $providerNoEqualOp && $this->operator != $noEqualOp) { if ($provider->version == $this->version && $provider->operator == $providerNoEqualOp && $this->operator != $noEqualOp) {

@ -33,6 +33,13 @@ class VersionConstraintTest extends \PHPUnit_Framework_TestCase
array('!=', '1', '<=', '1'), array('!=', '1', '<=', '1'),
array('!=', '1', '>', '1'), array('!=', '1', '>', '1'),
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'),
); );
} }
@ -61,6 +68,10 @@ class VersionConstraintTest extends \PHPUnit_Framework_TestCase
array('==', '2', '<', '2'), array('==', '2', '<', '2'),
array('!=', '1', '==', '1'), array('!=', '1', '==', '1'),
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…
Cancel
Save