From d47d9eb25380ed5bc4b08a8ab664fb62c69f2bbb Mon Sep 17 00:00:00 2001 From: David Zuelke Date: Mon, 7 Jul 2014 19:51:00 +0200 Subject: [PATCH] remember prefer-stable setting in composer.lock --- src/Composer/Installer.php | 5 +++-- src/Composer/Package/Locker.php | 10 +++++++++- .../Fixtures/installer/install-dev-using-dist.test | 1 + .../Fixtures/installer/install-from-empty-lock.test | 3 ++- .../installer/install-missing-alias-from-lock.test | 3 ++- ...ial-update-downgrades-non-whitelisted-unstable.test | 2 ++ .../Fixtures/installer/partial-update-from-lock.test | 2 ++ .../installer/partial-update-without-lock.test | 1 + .../Test/Fixtures/installer/update-alias-lock.test | 4 +++- .../installer/update-whitelist-reads-lock.test | 3 ++- .../updating-dev-from-lock-removes-old-deps.test | 3 ++- .../updating-dev-updates-url-and-reference.test | 4 +++- tests/Composer/Test/Package/LockerTest.php | 5 +++-- 13 files changed, 35 insertions(+), 11 deletions(-) diff --git a/src/Composer/Installer.php b/src/Composer/Installer.php index fac713226..eb4db08c4 100644 --- a/src/Composer/Installer.php +++ b/src/Composer/Installer.php @@ -277,7 +277,8 @@ class Installer $platformDevReqs, $aliases, $this->package->getMinimumStability(), - $this->package->getStabilityFlags() + $this->package->getStabilityFlags(), + $this->package->getPreferStable() ); if ($updatedLock) { $this->io->write('Writing lock file'); @@ -647,7 +648,7 @@ class Installer private function createPolicy() { - return new DefaultPolicy($this->package->getPreferStable()); + return new DefaultPolicy((!$this->update && $this->locker->isLocked()) ? $this->locker->getPreferStable() : $this->package->getPreferStable()); } private function createRequest(Pool $pool, RootPackageInterface $rootPackage, PlatformRepository $platformRepo) diff --git a/src/Composer/Package/Locker.php b/src/Composer/Package/Locker.php index 2aa36187f..bee955288 100644 --- a/src/Composer/Package/Locker.php +++ b/src/Composer/Package/Locker.php @@ -173,6 +173,13 @@ class Locker return isset($lockData['stability-flags']) ? $lockData['stability-flags'] : array(); } + public function getPreferStable() + { + $lockData = $this->getLockData(); + + return isset($lockData['prefer-stable']) ? $lockData['prefer-stable'] : false; + } + public function getAliases() { $lockData = $this->getLockData(); @@ -206,7 +213,7 @@ class Locker * * @return bool */ - public function setLockData(array $packages, $devPackages, array $platformReqs, $platformDevReqs, array $aliases, $minimumStability, array $stabilityFlags) + public function setLockData(array $packages, $devPackages, array $platformReqs, $platformDevReqs, array $aliases, $minimumStability, array $stabilityFlags, $preferStable) { $lock = array( '_readme' => array('This file locks the dependencies of your project to a known state', @@ -218,6 +225,7 @@ class Locker 'aliases' => array(), 'minimum-stability' => $minimumStability, 'stability-flags' => $stabilityFlags, + 'prefer-stable' => $preferStable, ); foreach ($aliases as $package => $versions) { diff --git a/tests/Composer/Test/Fixtures/installer/install-dev-using-dist.test b/tests/Composer/Test/Fixtures/installer/install-dev-using-dist.test index fe7582b42..af4eed811 100644 --- a/tests/Composer/Test/Fixtures/installer/install-dev-using-dist.test +++ b/tests/Composer/Test/Fixtures/installer/install-dev-using-dist.test @@ -47,6 +47,7 @@ install --prefer-dist "stability-flags": { "a/a": 20 }, + "prefer-stable": false, "platform": [], "platform-dev": [] } diff --git a/tests/Composer/Test/Fixtures/installer/install-from-empty-lock.test b/tests/Composer/Test/Fixtures/installer/install-from-empty-lock.test index 65b3fe80b..88c3e8fa7 100644 --- a/tests/Composer/Test/Fixtures/installer/install-from-empty-lock.test +++ b/tests/Composer/Test/Fixtures/installer/install-from-empty-lock.test @@ -24,7 +24,8 @@ Requirements from the composer file are not installed if the lock file is presen "packages-dev": null, "aliases": [], "minimum-stability": "stable", - "stability-flags": [] + "stability-flags": [], + "prefer-stable": false } --RUN-- install diff --git a/tests/Composer/Test/Fixtures/installer/install-missing-alias-from-lock.test b/tests/Composer/Test/Fixtures/installer/install-missing-alias-from-lock.test index e5ddacf20..298846609 100644 --- a/tests/Composer/Test/Fixtures/installer/install-missing-alias-from-lock.test +++ b/tests/Composer/Test/Fixtures/installer/install-missing-alias-from-lock.test @@ -32,7 +32,8 @@ Installing an old alias that doesn't exist anymore from a lock is possible "packages-dev": null, "aliases": [], "minimum-stability": "dev", - "stability-flags": [] + "stability-flags": [], + "prefer-stable": false } --RUN-- install diff --git a/tests/Composer/Test/Fixtures/installer/partial-update-downgrades-non-whitelisted-unstable.test b/tests/Composer/Test/Fixtures/installer/partial-update-downgrades-non-whitelisted-unstable.test index fb618ebe3..f9fd5058a 100644 --- a/tests/Composer/Test/Fixtures/installer/partial-update-downgrades-non-whitelisted-unstable.test +++ b/tests/Composer/Test/Fixtures/installer/partial-update-downgrades-non-whitelisted-unstable.test @@ -35,6 +35,7 @@ Partial update from lock file should apply lock file and downgrade unstable pack "stability-flags": { "b/unstable": 15 }, + "prefer-stable": false, "platform": [], "platform-dev": [] } @@ -57,6 +58,7 @@ update c/uptodate "aliases": [], "minimum-stability": "stable", "stability-flags": [], + "prefer-stable": false, "platform": [], "platform-dev": [] } diff --git a/tests/Composer/Test/Fixtures/installer/partial-update-from-lock.test b/tests/Composer/Test/Fixtures/installer/partial-update-from-lock.test index 51368b861..5b904f9b5 100644 --- a/tests/Composer/Test/Fixtures/installer/partial-update-from-lock.test +++ b/tests/Composer/Test/Fixtures/installer/partial-update-from-lock.test @@ -35,6 +35,7 @@ Partial update from lock file should update everything to the state of the lock, "stability-flags": { "b/unstable": 15 }, + "prefer-stable": false, "platform": [], "platform-dev": [] } @@ -57,6 +58,7 @@ update b/unstable "aliases": [], "minimum-stability": "stable", "stability-flags": [], + "prefer-stable": false, "platform": [], "platform-dev": [] } diff --git a/tests/Composer/Test/Fixtures/installer/partial-update-without-lock.test b/tests/Composer/Test/Fixtures/installer/partial-update-without-lock.test index 146277d02..224e58f7d 100644 --- a/tests/Composer/Test/Fixtures/installer/partial-update-without-lock.test +++ b/tests/Composer/Test/Fixtures/installer/partial-update-without-lock.test @@ -42,6 +42,7 @@ update b/unstable "aliases": [], "minimum-stability": "stable", "stability-flags": [], + "prefer-stable": false, "platform": [], "platform-dev": [] } diff --git a/tests/Composer/Test/Fixtures/installer/update-alias-lock.test b/tests/Composer/Test/Fixtures/installer/update-alias-lock.test index ad9451c6f..0fc5fe301 100644 --- a/tests/Composer/Test/Fixtures/installer/update-alias-lock.test +++ b/tests/Composer/Test/Fixtures/installer/update-alias-lock.test @@ -38,7 +38,8 @@ Update aliased package does not mess up the lock file "packages-dev": null, "aliases": [], "minimum-stability": "dev", - "stability-flags": [] + "stability-flags": [], + "prefer-stable": false } --INSTALLED-- [ @@ -64,6 +65,7 @@ update "aliases": [], "minimum-stability": "dev", "stability-flags": [], + "prefer-stable": false, "platform": [], "platform-dev": [] } diff --git a/tests/Composer/Test/Fixtures/installer/update-whitelist-reads-lock.test b/tests/Composer/Test/Fixtures/installer/update-whitelist-reads-lock.test index d73b93557..3bc189015 100644 --- a/tests/Composer/Test/Fixtures/installer/update-whitelist-reads-lock.test +++ b/tests/Composer/Test/Fixtures/installer/update-whitelist-reads-lock.test @@ -31,7 +31,8 @@ Limited update takes rules from lock if available, and not from the installed re "packages-dev": null, "aliases": [], "minimum-stability": "stable", - "stability-flags": [] + "stability-flags": [], + "prefer-stable": false } --INSTALLED-- [ diff --git a/tests/Composer/Test/Fixtures/installer/updating-dev-from-lock-removes-old-deps.test b/tests/Composer/Test/Fixtures/installer/updating-dev-from-lock-removes-old-deps.test index f5c4ccc24..bd94617bc 100644 --- a/tests/Composer/Test/Fixtures/installer/updating-dev-from-lock-removes-old-deps.test +++ b/tests/Composer/Test/Fixtures/installer/updating-dev-from-lock-removes-old-deps.test @@ -19,7 +19,8 @@ Installing locked dev packages should remove old dependencies "packages-dev": null, "aliases": [], "minimum-stability": "dev", - "stability-flags": [] + "stability-flags": [], + "prefer-stable": false } --INSTALLED-- [ diff --git a/tests/Composer/Test/Fixtures/installer/updating-dev-updates-url-and-reference.test b/tests/Composer/Test/Fixtures/installer/updating-dev-updates-url-and-reference.test index 3eb701719..849296850 100644 --- a/tests/Composer/Test/Fixtures/installer/updating-dev-updates-url-and-reference.test +++ b/tests/Composer/Test/Fixtures/installer/updating-dev-updates-url-and-reference.test @@ -31,7 +31,8 @@ Updating a dev package for new reference updates the url and reference "packages-dev": null, "aliases": [], "minimum-stability": "dev", - "stability-flags": {"a/a":20} + "stability-flags": {"a/a":20}, + "prefer-stable": false } --INSTALLED-- [ @@ -57,6 +58,7 @@ update "aliases": [], "minimum-stability": "dev", "stability-flags": {"a/a":20}, + "prefer-stable": false, "platform": [], "platform-dev": [] } diff --git a/tests/Composer/Test/Package/LockerTest.php b/tests/Composer/Test/Package/LockerTest.php index b530eaf41..7e1d2d3b1 100644 --- a/tests/Composer/Test/Package/LockerTest.php +++ b/tests/Composer/Test/Package/LockerTest.php @@ -134,9 +134,10 @@ class LockerTest extends \PHPUnit_Framework_TestCase 'stability-flags' => array(), 'platform' => array(), 'platform-dev' => array(), + 'prefer-stable' => false, )); - $locker->setLockData(array($package1, $package2), array(), array(), array(), array(), 'dev', array()); + $locker->setLockData(array($package1, $package2), array(), array(), array(), array(), 'dev', array(), false); } public function testLockBadPackages() @@ -155,7 +156,7 @@ class LockerTest extends \PHPUnit_Framework_TestCase $this->setExpectedException('LogicException'); - $locker->setLockData(array($package1), array(), array(), array(), array(), 'dev', array()); + $locker->setLockData(array($package1), array(), array(), array(), array(), 'dev', array(), false); } public function testIsFresh()