Преглед на файлове

Add '<>' operator for Version Parser

Alexey Prilipko преди 12 години
родител
ревизия
e130386612

+ 1 - 1
src/Composer/Package/Version/VersionParser.php

@@ -228,7 +228,7 @@ class VersionParser
         }
 
         // match operators constraints
-        if (preg_match('{^(>=?|<=?|==?)?\s*(.*)}', $constraint, $matches)) {
+        if (preg_match('{^(<>|!=|>=?|<=?|==?)?\s*(.*)}', $constraint, $matches)) {
             try {
                 $version = $this->normalize($matches[2]);
 

+ 24 - 0
tests/Composer/Test/DependencyResolver/SolverTest.php

@@ -115,6 +115,30 @@ class SolverTest extends TestCase
         ));
     }
 
+    public function testSolverInstallHonoursNotEqualOperator()
+    {
+        $this->repo->addPackage($packageA = $this->getPackage('A', '1.0'));
+        $this->repo->addPackage($packageB = $this->getPackage('B', '1.0'));
+        $this->repo->addPackage($newPackageB11 = $this->getPackage('B', '1.1'));
+        $this->repo->addPackage($newPackageB12 = $this->getPackage('B', '1.2'));
+        $this->repo->addPackage($newPackageB13 = $this->getPackage('B', '1.3'));
+
+        $packageA->setRequires(array(
+            new Link('A', 'B', $this->getVersionConstraint('<=', '1.3'), 'requires'),
+            new Link('A', 'B', $this->getVersionConstraint('<>', '1.3'), 'requires'),
+            new Link('A', 'B', $this->getVersionConstraint('!=', '1.2'), 'requires'),
+        ));
+
+        $this->reposComplete();
+
+        $this->request->install('A');
+
+        $this->checkSolverResult(array(
+            array('job' => 'install', 'package' => $newPackageB11),
+            array('job' => 'install', 'package' => $packageA),
+        ));
+    }
+
     public function testSolverInstallWithDepsInOrder()
     {
         $this->repo->addPackage($packageA = $this->getPackage('A', '1.0'));

+ 2 - 0
tests/Composer/Test/Package/Version/VersionParserTest.php

@@ -143,6 +143,8 @@ class VersionParserTest extends \PHPUnit_Framework_TestCase
             'match any/2'       => array('*.*',         new MultiConstraint(array())),
             'match any/3'       => array('*.x.*',       new MultiConstraint(array())),
             'match any/4'       => array('x.x.x.*',     new MultiConstraint(array())),
+            'not equal'         => array('<>1.0.0',     new VersionConstraint('<>', '1.0.0.0')),
+            'not equal/2'       => array('!=1.0.0',     new VersionConstraint('!=', '1.0.0.0')),
             'greater than'      => array('>1.0.0',      new VersionConstraint('>', '1.0.0.0')),
             'lesser than'       => array('<1.2.3.4',    new VersionConstraint('<', '1.2.3.4')),
             'less/eq than'      => array('<=1.2.3',     new VersionConstraint('<=', '1.2.3.0')),