From 98b254a3ec22d3d4916abf8f2b84fd2c289baad2 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 2 Dec 2014 09:18:44 +0100 Subject: [PATCH] split update --prefer-lowest and --prefer-stable --- src/Composer/Command/UpdateCommand.php | 6 ++-- src/Composer/Installer.php | 31 +++++++++++++------ .../update-prefer-lowest-stable.test | 2 +- tests/Composer/Test/InstallerTest.php | 3 +- 4 files changed, 28 insertions(+), 14 deletions(-) diff --git a/src/Composer/Command/UpdateCommand.php b/src/Composer/Command/UpdateCommand.php index cf3cf8ca2..5e83658c9 100644 --- a/src/Composer/Command/UpdateCommand.php +++ b/src/Composer/Command/UpdateCommand.php @@ -47,7 +47,8 @@ class UpdateCommand extends Command new InputOption('verbose', 'v|vv|vvv', InputOption::VALUE_NONE, 'Shows more details including new commits pulled in when updating packages.'), new InputOption('optimize-autoloader', 'o', InputOption::VALUE_NONE, 'Optimize autoloader during autoloader dump.'), new InputOption('ignore-platform-reqs', null, InputOption::VALUE_NONE, 'Ignore platform requirements (php & ext- packages).'), - new InputOption('prefer-lowest-stable', null, InputOption::VALUE_NONE, 'Forces all packages to their lowest stable version.'), + new InputOption('prefer-stable', null, InputOption::VALUE_NONE, 'Prefer stable versions of dependencies.'), + new InputOption('prefer-lowest', null, InputOption::VALUE_NONE, 'Prefer lowest versions of dependencies.'), )) ->setHelp(<<update command reads the composer.json file from the @@ -122,7 +123,8 @@ EOT ->setUpdateWhitelist($input->getOption('lock') ? array('lock') : $input->getArgument('packages')) ->setWhitelistDependencies($input->getOption('with-dependencies')) ->setIgnorePlatformRequirements($input->getOption('ignore-platform-reqs')) - ->setPreferLowestStable($input->getOption('prefer-lowest-stable')) + ->setPreferStable($input->getOption('prefer-stable')) + ->setPreferLowest($input->getOption('prefer-lowest')) ; if ($input->getOption('no-plugins')) { diff --git a/src/Composer/Installer.php b/src/Composer/Installer.php index cfc995fe2..58459f7a6 100644 --- a/src/Composer/Installer.php +++ b/src/Composer/Installer.php @@ -107,7 +107,8 @@ class Installer protected $update = false; protected $runScripts = true; protected $ignorePlatformReqs = false; - protected $preferLowestStable = false; + protected $preferStable = false; + protected $preferLowest = false; /** * Array of package names/globs flagged for update * @@ -702,11 +703,8 @@ class Installer // old lock file without prefer stable will return null // so in this case we use the composer.json info if (null === $preferStable) { - if ($this->preferLowestStable) { - $preferStable = $preferLowest = true; - } else { - $preferStable = $this->package->getPreferStable(); - } + $preferStable = $this->preferStable || $this->package->getPreferStable(); + $preferLowest = $this->preferLowest; } return new DefaultPolicy($preferStable, $preferLowest); @@ -1251,14 +1249,27 @@ class Installer } /** - * Should packages be forced to their lowest stable version when updating? + * Should packages be prefered in a stable version when updating? * - * @param boolean $preferLowestStable + * @param boolean $preferStable * @return Installer */ - public function setPreferLowestStable($preferLowestStable = true) + public function setPreferStable($preferStable = true) { - $this->preferLowestStable = (boolean) $preferLowestStable; + $this->preferStable = (boolean) $preferStable; + + return $this; + } + + /** + * Should packages be prefered in a lowest version when updating? + * + * @param boolean $preferLowest + * @return Installer + */ + public function setPreferLowest($preferLowest = true) + { + $this->preferLowest = (boolean) $preferLowest; return $this; } diff --git a/tests/Composer/Test/Fixtures/installer/update-prefer-lowest-stable.test b/tests/Composer/Test/Fixtures/installer/update-prefer-lowest-stable.test index b511fdf72..00efd5688 100644 --- a/tests/Composer/Test/Fixtures/installer/update-prefer-lowest-stable.test +++ b/tests/Composer/Test/Fixtures/installer/update-prefer-lowest-stable.test @@ -34,7 +34,7 @@ Updates packages to their lowest stable version { "name": "a/b", "version": "1.0.1" } ] --RUN-- -update --prefer-lowest-stable +update --prefer-lowest --prefer-stable --EXPECT-- Updating a/a (1.0.0-rc1) to a/a (1.0.1) Updating a/b (1.0.1) to a/b (1.0.0) diff --git a/tests/Composer/Test/InstallerTest.php b/tests/Composer/Test/InstallerTest.php index 27e1d84b9..9bf2c01a7 100644 --- a/tests/Composer/Test/InstallerTest.php +++ b/tests/Composer/Test/InstallerTest.php @@ -217,7 +217,8 @@ class InstallerTest extends TestCase ->setDryRun($input->getOption('dry-run')) ->setUpdateWhitelist($input->getArgument('packages')) ->setWhitelistDependencies($input->getOption('with-dependencies')) - ->setPreferLowestStable($input->getOption('prefer-lowest-stable')) + ->setPreferStable($input->getOption('prefer-stable')) + ->setPreferLowest($input->getOption('prefer-lowest')) ->setIgnorePlatformRequirements($input->getOption('ignore-platform-reqs')); return $installer->run();