diff --git a/src/Composer/Command/InstallCommand.php b/src/Composer/Command/InstallCommand.php index 0cded236d..fa0431b64 100644 --- a/src/Composer/Command/InstallCommand.php +++ b/src/Composer/Command/InstallCommand.php @@ -86,21 +86,13 @@ EOT $request = new Request($pool); if ($update) { $output->writeln('Updating dependencies.'); - $listedPackages = array(); $installedPackages = $installedRepo->getPackages(); $links = $this->collectLinks($input, $composer->getPackage()); foreach ($links as $link) { - $listedPackages[] = $link->getTarget(); - foreach ($installedPackages as $package) { if ($package->getName() === $link->getTarget()) { - $constraint = new VersionConstraint('=', $package->getVersion()); - if ($link->getConstraint()->matches($constraint)) { - continue 2; - } - // TODO this should just update to the exact version (once constraints are available on update, see #125) - $request->remove($package->getName(), $constraint); + $request->update($package->getName(), new VersionConstraint('=', $package->getVersion())); break; } } diff --git a/tests/Composer/Test/DependencyResolver/SolverTest.php b/tests/Composer/Test/DependencyResolver/SolverTest.php index 04e70be36..c2ed0f2bf 100644 --- a/tests/Composer/Test/DependencyResolver/SolverTest.php +++ b/tests/Composer/Test/DependencyResolver/SolverTest.php @@ -139,6 +139,40 @@ class SolverTest extends TestCase $this->checkSolverResult(array()); } + public function testSolverUpdateConstrained() + { + $this->repoInstalled->addPackage($packageA = $this->getPackage('A', '1.0')); + $this->repo->addPackage($newPackageA = $this->getPackage('A', '1.2')); + $this->repo->addPackage($this->getPackage('A', '2.0')); + $this->reposComplete(); + + $this->request->install('A', new VersionConstraint('<', '2.0.0.0')); + $this->request->update('A'); + + $this->checkSolverResult(array(array( + 'job' => 'update', + 'from' => $packageA, + 'to' => $newPackageA, + ))); + } + + public function testSolverUpdateFullyConstrained() + { + $this->repoInstalled->addPackage($packageA = $this->getPackage('A', '1.0')); + $this->repo->addPackage($newPackageA = $this->getPackage('A', '1.2')); + $this->repo->addPackage($this->getPackage('A', '2.0')); + $this->reposComplete(); + + $this->request->install('A', new VersionConstraint('<', '2.0.0.0')); + $this->request->update('A', new VersionConstraint('=', '1.0.0.0')); + + $this->checkSolverResult(array(array( + 'job' => 'update', + 'from' => $packageA, + 'to' => $newPackageA, + ))); + } + public function testSolverAllJobs() { $this->repoInstalled->addPackage($packageD = $this->getPackage('D', '1.0'));