From 60df8925174dfb385368efbbfd2d19c7f372c2cd Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 21 Feb 2019 12:27:02 +0100 Subject: [PATCH] Store dev mode in installed.json, fixes #3008 --- .travis.yml | 2 +- src/Composer/Installer.php | 4 ++-- src/Composer/Repository/FilesystemRepository.php | 15 ++++++++++----- .../Repository/WritableArrayRepository.php | 2 +- .../Repository/WritableRepositoryInterface.php | 4 +++- .../Mock/InstalledFilesystemRepositoryMock.php | 2 +- .../Test/Repository/FilesystemRepositoryTest.php | 5 +++-- 7 files changed, 21 insertions(+), 13 deletions(-) diff --git a/.travis.yml b/.travis.yml index a06922904..c732f9421 100644 --- a/.travis.yml +++ b/.travis.yml @@ -62,7 +62,7 @@ script: - ls -d tests/Composer/Test/* | grep -v TestCase.php | parallel --gnu --keep-order 'echo "Running {} tests"; ./vendor/bin/phpunit -c tests/complete.phpunit.xml --colors=always {} || (echo -e "\e[41mFAILED\e[0m {}" && exit 1);' # Run PHPStan - if [[ $PHPSTAN == "1" ]]; then - composer require --dev phpstan/phpstan-shim:^0.11 --ignore-platform-reqs && + bin/composer require --dev phpstan/phpstan-shim:^0.11 --ignore-platform-reqs && vendor/bin/phpstan.phar analyse src tests --configuration=phpstan/config.neon --autoload-file=phpstan/autoload.php; fi diff --git a/src/Composer/Installer.php b/src/Composer/Installer.php index fc877f18e..4dddd9505 100644 --- a/src/Composer/Installer.php +++ b/src/Composer/Installer.php @@ -616,7 +616,7 @@ class Installer } if ($this->executeOperations || $this->writeLock) { - $localRepo->write(); + $localRepo->write($this->devMode); } $event = 'Composer\Installer\PackageEvents::POST_PACKAGE_'.strtoupper($jobType); @@ -628,7 +628,7 @@ class Installer if ($this->executeOperations) { // force source/dist urls to be updated for all packages $this->processPackageUrls($pool, $policy, $localRepo, $repositories); - $localRepo->write(); + $localRepo->write($this->devMode); } return array(0, $devPackages); diff --git a/src/Composer/Repository/FilesystemRepository.php b/src/Composer/Repository/FilesystemRepository.php index bde55aad3..9dbac5f76 100644 --- a/src/Composer/Repository/FilesystemRepository.php +++ b/src/Composer/Repository/FilesystemRepository.php @@ -49,7 +49,12 @@ class FilesystemRepository extends WritableArrayRepository } try { - $packages = $this->file->read(); + $data = $this->file->read(); + if (isset($data['packages'])) { + $packages = $data['packages']; + } else { + $packages = $data; + } if (!is_array($packages)) { throw new \UnexpectedValueException('Could not parse package list from the repository'); @@ -74,16 +79,16 @@ class FilesystemRepository extends WritableArrayRepository /** * Writes writable repository. */ - public function write() + public function write($devMode) { - $data = array(); + $data = array('packages' => array(), 'dev' => $devMode); $dumper = new ArrayDumper(); foreach ($this->getCanonicalPackages() as $package) { - $data[] = $dumper->dump($package); + $data['packages'][] = $dumper->dump($package); } - usort($data, function ($a, $b) { + usort($data['packages'], function ($a, $b) { return strcmp($a['name'], $b['name']); }); diff --git a/src/Composer/Repository/WritableArrayRepository.php b/src/Composer/Repository/WritableArrayRepository.php index 041e40562..284f9bcb0 100644 --- a/src/Composer/Repository/WritableArrayRepository.php +++ b/src/Composer/Repository/WritableArrayRepository.php @@ -24,7 +24,7 @@ class WritableArrayRepository extends ArrayRepository implements WritableReposit /** * {@inheritDoc} */ - public function write() + public function write($devMode) { } diff --git a/src/Composer/Repository/WritableRepositoryInterface.php b/src/Composer/Repository/WritableRepositoryInterface.php index 4500005d9..4fb3d0c66 100644 --- a/src/Composer/Repository/WritableRepositoryInterface.php +++ b/src/Composer/Repository/WritableRepositoryInterface.php @@ -23,8 +23,10 @@ interface WritableRepositoryInterface extends RepositoryInterface { /** * Writes repository (f.e. to the disc). + * + * @param bool $devMode Whether dev requirements were included or not in this installation */ - public function write(); + public function write($devMode); /** * Adds package to the repository. diff --git a/tests/Composer/Test/Mock/InstalledFilesystemRepositoryMock.php b/tests/Composer/Test/Mock/InstalledFilesystemRepositoryMock.php index 9c11dc307..8c8c280e8 100644 --- a/tests/Composer/Test/Mock/InstalledFilesystemRepositoryMock.php +++ b/tests/Composer/Test/Mock/InstalledFilesystemRepositoryMock.php @@ -20,7 +20,7 @@ class InstalledFilesystemRepositoryMock extends InstalledFilesystemRepository { } - public function write() + public function write($devMode) { } } diff --git a/tests/Composer/Test/Repository/FilesystemRepositoryTest.php b/tests/Composer/Test/Repository/FilesystemRepositoryTest.php index be8b0d0a9..4d8d7c103 100644 --- a/tests/Composer/Test/Repository/FilesystemRepositoryTest.php +++ b/tests/Composer/Test/Repository/FilesystemRepositoryTest.php @@ -95,11 +95,12 @@ class FilesystemRepositoryTest extends TestCase ->expects($this->once()) ->method('write') ->with(array( - array('name' => 'mypkg', 'type' => 'library', 'version' => '0.1.10', 'version_normalized' => '0.1.10.0'), + 'packages' => array(array('name' => 'mypkg', 'type' => 'library', 'version' => '0.1.10', 'version_normalized' => '0.1.10.0')), + 'dev' => true, )); $repository->addPackage($this->getPackage('mypkg', '0.1.10')); - $repository->write(); + $repository->write(true); } private function createJsonFileMock()