Browse Source

Add a few solver tests regarding "replace"

Jordi Boggiano 13 years ago
parent
commit
40cc5fea1d
1 changed files with 54 additions and 0 deletions
  1. 54 0
      tests/Composer/Test/DependencyResolver/SolverTest.php

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

@@ -231,6 +231,60 @@ class SolverTest extends \PHPUnit_Framework_TestCase
         ));
     }
 
+    public function testSkipReplacerOfExistingPackage()
+    {
+        $this->repo->addPackage($packageA = new MemoryPackage('A', '1.0'));
+        $this->repo->addPackage($packageQ = new MemoryPackage('Q', '1.0'));
+        $this->repo->addPackage($packageB = new MemoryPackage('B', '1.0'));
+        $packageA->setRequires(array(new Link('A', 'B', new VersionConstraint('>=', '1.0'), 'requires')));
+        $packageQ->setReplaces(array(new Link('Q', 'B', new VersionConstraint('>=', '1.0'), 'replaces')));
+
+        $this->reposComplete();
+
+        $this->request->install('A');
+
+        $this->checkSolverResult(array(
+            array('job' => 'install', 'package' => $packageB),
+            array('job' => 'install', 'package' => $packageA),
+        ));
+    }
+
+    public function testInstallReplacerOfMissingPackage()
+    {
+        $this->repo->addPackage($packageA = new MemoryPackage('A', '1.0'));
+        $this->repo->addPackage($packageQ = new MemoryPackage('Q', '1.0'));
+        $packageA->setRequires(array(new Link('A', 'B', new VersionConstraint('>=', '1.0'), 'requires')));
+        $packageQ->setReplaces(array(new Link('Q', 'B', new VersionConstraint('>=', '1.0'), 'replaces')));
+
+        $this->reposComplete();
+
+        $this->request->install('A');
+
+        $this->checkSolverResult(array(
+            array('job' => 'install', 'package' => $packageQ),
+            array('job' => 'install', 'package' => $packageA),
+        ));
+    }
+
+    public function testSkipReplacedPackageIfReplacerIsSelected()
+    {
+        $this->repo->addPackage($packageA = new MemoryPackage('A', '1.0'));
+        $this->repo->addPackage($packageQ = new MemoryPackage('Q', '1.0'));
+        $this->repo->addPackage($packageB = new MemoryPackage('B', '1.0'));
+        $packageA->setRequires(array(new Link('A', 'B', new VersionConstraint('>=', '1.0'), 'requires')));
+        $packageQ->setReplaces(array(new Link('Q', 'B', new VersionConstraint('>=', '1.0'), 'replaces')));
+
+        $this->reposComplete();
+
+        $this->request->install('A');
+        $this->request->install('Q');
+
+        $this->checkSolverResult(array(
+            array('job' => 'install', 'package' => $packageQ),
+            array('job' => 'install', 'package' => $packageA),
+        ));
+    }
+
     public function testInstallCircularRequire()
     {
         $this->repo->addPackage($packageA = new MemoryPackage('A', '1.0'));