Browse Source

Prevent seeing dev versions as equal when they are not, fixes #848

Jordi Boggiano 12 years ago
parent
commit
2f7130200a

+ 1 - 1
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;

+ 5 - 0
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) {

+ 2 - 0
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'),
         );
     }