From 5bfbff867c48eb40f685db9a306afc236e98f8e0 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Mon, 28 May 2012 18:57:59 +0200 Subject: [PATCH] Root requires are not taken into account in locked installs, fixes #669 --- src/Composer/Installer.php | 6 +++- .../Fixtures/installer/aliased-priority.test | 2 +- .../installer/install-from-empty-lock.test | 32 +++++++++++++++++++ tests/Composer/Test/InstallerTest.php | 12 +++++-- 4 files changed, 47 insertions(+), 5 deletions(-) create mode 100644 tests/Composer/Test/Fixtures/installer/install-from-empty-lock.test diff --git a/src/Composer/Installer.php b/src/Composer/Installer.php index e8924756b..a3fe7a439 100644 --- a/src/Composer/Installer.php +++ b/src/Composer/Installer.php @@ -141,10 +141,14 @@ class Installer } // create installed repo, this contains all local packages + platform packages (php & extensions) + $installedRootPackage = clone $this->package; + $installedRootPackage->setRequires(array()); + $installedRootPackage->setDevRequires(array()); + $repos = array_merge( $this->repositoryManager->getLocalRepositories(), array( - new InstalledArrayRepository(array($this->package)), + new InstalledArrayRepository(array($installedRootPackage)), new PlatformRepository(), ) ); diff --git a/tests/Composer/Test/Fixtures/installer/aliased-priority.test b/tests/Composer/Test/Fixtures/installer/aliased-priority.test index 35af86fcd..55da1ee71 100644 --- a/tests/Composer/Test/Fixtures/installer/aliased-priority.test +++ b/tests/Composer/Test/Fixtures/installer/aliased-priority.test @@ -47,8 +47,8 @@ Aliases take precedence over default package --RUN-- install --EXPECT-- -Installing a/b (dev-master forked) Marking a/b (1.0.x-dev forked) as installed, alias of a/b (dev-master forked) +Installing a/b (dev-master forked) Marking a/c (dev-master feat.f) as installed, alias of a/c (dev-feature-foo feat.f) Installing a/a (dev-master master) Installing a/c (dev-feature-foo feat.f) diff --git a/tests/Composer/Test/Fixtures/installer/install-from-empty-lock.test b/tests/Composer/Test/Fixtures/installer/install-from-empty-lock.test new file mode 100644 index 000000000..d754651a0 --- /dev/null +++ b/tests/Composer/Test/Fixtures/installer/install-from-empty-lock.test @@ -0,0 +1,32 @@ +--TEST-- +Requirements from the composer file are not installed if the lock file is present +--COMPOSER-- +{ + "repositories": [ + { + "type": "package", + "package": [ + { "name": "required", "version": "1.0.0" }, + { "name": "newly-required", "version": "1.0.0" } + ] + } + ], + "require": { + "required": "1.0.0", + "newly-required": "1.0.0" + } +} +--LOCK-- +{ + "packages": [ + { "package": "required", "version": "1.0.0" } + ], + "packages-dev": null, + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [] +} +--RUN-- +install +--EXPECT-- +Installing required (1.0.0) \ No newline at end of file diff --git a/tests/Composer/Test/InstallerTest.php b/tests/Composer/Test/InstallerTest.php index 6de28f45f..f94a6092b 100644 --- a/tests/Composer/Test/InstallerTest.php +++ b/tests/Composer/Test/InstallerTest.php @@ -124,7 +124,7 @@ class InstallerTest extends TestCase /** * @dataProvider getIntegrationTests */ - public function testIntegration($file, $message, $condition, $composer, $lock, $installed, $installedDev, $run, $expect) + public function testIntegration($file, $message, $condition, $composerConfig, $lock, $installed, $installedDev, $run, $expect) { if ($condition) { eval('$res = '.$condition.';'); @@ -141,7 +141,7 @@ class InstallerTest extends TestCase $output .= $text . ($newline ? "\n":""); })); - $composer = FactoryMock::create($io, $composer); + $composer = FactoryMock::create($io, $composerConfig); $jsonMock = $this->getMockBuilder('Composer\Json\JsonFile')->disableOriginalConstructor()->getMock(); $jsonMock->expects($this->any()) @@ -167,8 +167,11 @@ class InstallerTest extends TestCase $lockJsonMock->expects($this->any()) ->method('read') ->will($this->returnValue($lock)); + $lockJsonMock->expects($this->any()) + ->method('exists') + ->will($this->returnValue(true)); - $locker = new Locker($lockJsonMock, $repositoryManager, isset($lock['hash']) ? $lock['hash'] : ''); + $locker = new Locker($lockJsonMock, $repositoryManager, md5(json_encode($composerConfig))); $composer->setLocker($locker); $autoloadGenerator = $this->getMock('Composer\Autoload\AutoloadGenerator'); @@ -245,6 +248,9 @@ class InstallerTest extends TestCase $composer = JsonFile::parseJson($match['composer']); if (!empty($match['lock'])) { $lock = JsonFile::parseJson($match['lock']); + if (!isset($lock['hash'])) { + $lock['hash'] = md5(json_encode($composer)); + } } if (!empty($match['installed'])) { $installed = JsonFile::parseJson($match['installed']);