Fix locking behavior with --dev
parent
f63df842b3
commit
a1306091f2
|
@ -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('<info>Installing '.($devMode ? 'dev ': '').'dependencies from lock file</info>');
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue