Pārlūkot izejas kodu

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
Nils Adermann 13 gadi atpakaļ
vecāks
revīzija
302948db3e

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

+ 11 - 2
src/Composer/Package/LinkConstraint/VersionConstraint.php

@@ -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
@@ -62,7 +71,7 @@ class VersionConstraint extends SpecificConstraint
         // 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
@@ -71,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) {

+ 11 - 0
tests/Composer/Test/Package/LinkConstraint/VersionConstraintTest.php

@@ -33,6 +33,13 @@ class VersionConstraintTest extends \PHPUnit_Framework_TestCase
             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('!=', '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'),
         );
     }