From 2f7130200adfe876e94884a524ae1cf61cd20e93 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 11 Jul 2012 20:25:22 +0200 Subject: [PATCH] Prevent seeing dev versions as equal when they are not, fixes #848 --- src/Composer/DependencyResolver/DefaultPolicy.php | 2 +- src/Composer/Package/LinkConstraint/VersionConstraint.php | 5 +++++ .../Test/Package/LinkConstraint/VersionConstraintTest.php | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Composer/DependencyResolver/DefaultPolicy.php b/src/Composer/DependencyResolver/DefaultPolicy.php index 108a8d44e..5d5e3653f 100644 --- a/src/Composer/DependencyResolver/DefaultPolicy.php +++ b/src/Composer/DependencyResolver/DefaultPolicy.php @@ -49,7 +49,7 @@ class DefaultPolicy implements PolicyInterface 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) { $policy = $this; diff --git a/src/Composer/Package/LinkConstraint/VersionConstraint.php b/src/Composer/Package/LinkConstraint/VersionConstraint.php index e88c418b3..d4e0e257a 100644 --- a/src/Composer/Package/LinkConstraint/VersionConstraint.php +++ b/src/Composer/Package/LinkConstraint/VersionConstraint.php @@ -58,6 +58,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 ? true : false; + } + // '!=' 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) { diff --git a/tests/Composer/Test/Package/LinkConstraint/VersionConstraintTest.php b/tests/Composer/Test/Package/LinkConstraint/VersionConstraintTest.php index cdd6e67f5..55bceda2d 100644 --- a/tests/Composer/Test/Package/LinkConstraint/VersionConstraintTest.php +++ b/tests/Composer/Test/Package/LinkConstraint/VersionConstraintTest.php @@ -33,6 +33,7 @@ class VersionConstraintTest extends \PHPUnit_Framework_TestCase array('!=', '1', '<=', '1'), array('!=', '1', '>', '1'), array('!=', '1', '>=', '1'), + array('==', 'dev-foo-bar', '==', 'dev-foo-bar'), ); } @@ -61,6 +62,7 @@ class VersionConstraintTest extends \PHPUnit_Framework_TestCase array('==', '2', '<', '2'), array('!=', '1', '==', '1'), array('==', '1', '!=', '1'), + array('==', 'dev-foo-dist', '==', 'dev-foo-zist'), ); }