diff --git a/src/Composer/Installer.php b/src/Composer/Installer.php index eb6e0ee03..1816e7ee2 100644 --- a/src/Composer/Installer.php +++ b/src/Composer/Installer.php @@ -162,7 +162,7 @@ class Installer if ($this->update || !$this->locker->isLocked()) { $updatedLock = $this->locker->setLockData( $this->repositoryManager->getLocalRepository()->getPackages(), - $this->repositoryManager->getLocalDevRepository()->getPackages(), + $this->devMode ? $this->repositoryManager->getLocalDevRepository()->getPackages() : null, $aliases ); if ($updatedLock) { @@ -206,7 +206,7 @@ class Installer foreach ($links as $link) { $request->install($link->getTarget(), $link->getConstraint()); } - } elseif ($this->locker->isLocked()) { + } elseif ($this->locker->isLocked($devMode)) { $installFromLock = true; $this->io->write('Installing '.($devMode ? 'dev ': '').'dependencies from lock file'); diff --git a/src/Composer/Package/Locker.php b/src/Composer/Package/Locker.php index 5f11e419d..032c6a05c 100644 --- a/src/Composer/Package/Locker.php +++ b/src/Composer/Package/Locker.php @@ -45,11 +45,21 @@ class Locker /** * Checks whether locker were been locked (lockfile found). * + * @param Boolean $dev true to check if dev packages are locked * @return Boolean */ - public function isLocked() + public function isLocked($dev = false) { - return $this->lockFile->exists(); + if (!$this->lockFile->exists()) { + return false; + } + + $data = $this->getLockData(); + if ($dev) { + return isset($data['packages-dev']); + } + + return isset($data['packages']); } /** @@ -67,6 +77,7 @@ class Locker /** * Searches and returns an array of locked packages, retrieved from registered repositories. * + * @param Boolean $dev true to retrieve the locked dev packages * @return array */ public function getLockedPackages($dev = false) @@ -109,7 +120,7 @@ class Locker public function getLockData() { - if (!$this->isLocked()) { + if (!$this->lockFile->exists()) { throw new \LogicException('No lockfile found. Unable to read locked packages'); } @@ -124,22 +135,24 @@ class Locker * Locks provided data into lockfile. * * @param array $packages array of packages - * @param array $packages array of dev packages + * @param mixed $packages array of dev packages or null if installed without --dev * @param array $aliases array of aliases * * @return Boolean */ - public function setLockData(array $packages, array $devPackages, array $aliases) + public function setLockData(array $packages, $devPackages, array $aliases) { $lock = array( 'hash' => $this->hash, - 'packages' => array(), - 'packages-dev' => array(), + 'packages' => null, + 'packages-dev' => null, 'aliases' => $aliases, ); $lock['packages'] = $this->lockPackages($packages); - $lock['packages-dev'] = $this->lockPackages($devPackages); + if (null !== $devPackages) { + $lock['packages-dev'] = $this->lockPackages($devPackages); + } if (!$this->isLocked() || $lock !== $this->getLockData()) { $this->lockFile->write($lock); diff --git a/tests/Composer/Test/Package/LockerTest.php b/tests/Composer/Test/Package/LockerTest.php index a4cbb6e1d..729da4b93 100644 --- a/tests/Composer/Test/Package/LockerTest.php +++ b/tests/Composer/Test/Package/LockerTest.php @@ -22,9 +22,13 @@ class LockerTest extends \PHPUnit_Framework_TestCase $locker = new Locker($json, $this->createRepositoryManagerMock(), 'md5'); $json - ->expects($this->once()) + ->expects($this->any()) ->method('exists') ->will($this->returnValue(true)); + $json + ->expects($this->any()) + ->method('read') + ->will($this->returnValue(array('packages' => array()))); $this->assertTrue($locker->isLocked()); }