Browse Source

Merge pull request #328 from naderman/update-all

Update all
Jordi Boggiano 13 years ago
parent
commit
bb160a3162

+ 2 - 7
src/Composer/Command/InstallCommand.php

@@ -119,14 +119,9 @@ EOT
             $installedPackages = $installedRepo->getPackages();
             $links = $this->collectLinks($composer->getPackage(), $noInstallRecommends, $installSuggests);
 
-            foreach ($links as $link) {
-                foreach ($installedPackages as $package) {
-                    if ($package->getName() === $link->getTarget()) {
-                        $request->update($package->getName(), new VersionConstraint('=', $package->getVersion()));
-                        break;
-                    }
-                }
+            $request->updateAll();
 
+            foreach ($links as $link) {
                 $request->install($link->getTarget(), $link->getConstraint());
             }
         } elseif ($composer->getLocker()->isLocked()) {

+ 5 - 0
src/Composer/DependencyResolver/Request.php

@@ -55,6 +55,11 @@ class Request
         );
     }
 
+    public function updateAll()
+    {
+        $this->jobs[] = array('cmd' => 'update-all', 'packages' => array());
+    }
+
     public function getJobs()
     {
         return $this->jobs;

+ 8 - 0
src/Composer/DependencyResolver/Solver.php

@@ -952,6 +952,14 @@ class Solver
                         break;
                 }
             }
+
+            switch ($job['cmd']) {
+                case 'update-all':
+                    foreach ($installedPackages as $package) {
+                        $this->updateMap[$package->getId()] = true;
+                    }
+                break;
+            }
         }
 
         foreach ($installedPackages as $package) {

+ 12 - 0
tests/Composer/Test/DependencyResolver/RequestTest.php

@@ -46,4 +46,16 @@ class RequestTest extends TestCase
             ),
             $request->getJobs());
     }
+
+    public function testUpdateAll()
+    {
+        $pool = new Pool;
+        $request = new Request($pool);
+
+        $request->updateAll();
+
+        $this->assertEquals(
+            array(array('cmd' => 'update-all', 'packages' => array())),
+            $request->getJobs());
+    }
 }

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

@@ -165,6 +165,26 @@ class SolverTest extends TestCase
         ));
     }
 
+    public function testSolverUpdateAll()
+    {
+        $this->repoInstalled->addPackage($packageA = $this->getPackage('A', '1.0'));
+        $this->repoInstalled->addPackage($packageB = $this->getPackage('B', '1.0'));
+        $this->repo->addPackage($newPackageA = $this->getPackage('A', '1.1'));
+        $this->repo->addPackage($newPackageB = $this->getPackage('B', '1.1'));
+
+        $packageA->setRequires(array(new Link('A', 'B', null, 'requires')));
+
+        $this->reposComplete();
+
+        $this->request->install('A');
+        $this->request->updateAll();
+
+        $this->checkSolverResult(array(
+            array('job' => 'update', 'from' => $packageB, 'to' => $newPackageB),
+            array('job' => 'update', 'from' => $packageA, 'to' => $newPackageA),
+        ));
+    }
+
     public function testSolverUpdateCurrent()
     {
         $this->repoInstalled->addPackage($this->getPackage('A', '1.0'));