diff --git a/src/Flex.php b/src/Flex.php index afec54ae..bcbe819a 100644 --- a/src/Flex.php +++ b/src/Flex.php @@ -600,6 +600,12 @@ public function finish(string $rootDir, ?string $originalComposerJsonHash = null private function synchronizePackageJson(string $rootDir) { + if (!($this->composer->getPackage()->getExtra()['symfony/flex']['synchronize_package_json'] ?? true)) { + $this->io->writeError('Skip synchronizing package.json with PHP packages'); + + return; + } + if (!$this->downloader->isEnabled()) { $this->io->writeError('Synchronizing package.json is disabled: "symfony/flex" not found in the root composer.json'); diff --git a/tests/FlexTest.php b/tests/FlexTest.php index cabb08a4..f4a315ba 100644 --- a/tests/FlexTest.php +++ b/tests/FlexTest.php @@ -310,6 +310,47 @@ class_exists(LockArrayRepository::class) ? LockArrayRepository::class : Reposito $this->assertSame('2.3', $recipes['doctrine/doctrine-bundle']->getVersion()); } + public function testInstallWithPackageJsonToSynchronizeSkipped() + { + $io = new BufferIO('', OutputInterface::VERBOSITY_VERBOSE); + $rootPackage = $this->mockRootPackage([ + 'symfony/flex' => ['synchronize_package_json' => false], + ]); + + $flex = $this->mockFlex($io, $rootPackage); + $flex->install($this->mockFlexEvent()); + + $this->assertStringContainsString( + 'Skip synchronizing package.json with PHP packages', + $io->getOutput(), + ); + } + + /** + * @dataProvider getDataForTestInstallWithoutPackageJsonToSynchronizeSkipped + */ + public function testInstallWithoutPackageJsonToSynchronizeSkipped(array $extra) + { + $io = new BufferIO('', OutputInterface::VERBOSITY_VERBOSE); + $rootPackage = $this->mockRootPackage($extra); + + $flex = $this->mockFlex($io, $rootPackage); + $flex->install($this->mockFlexEvent()); + + $this->assertStringNotContainsString( + 'Skip synchronizing package.json with PHP packages', + $io->getOutput(), + ); + } + + public function getDataForTestInstallWithoutPackageJsonToSynchronizeSkipped(): array + { + return [ + 'default_behavior' => [[]], + 'with_config_explicitly_set' => [['symfony/flex' => ['synchronize_package_json' => true]]], + ]; + } + public static function getTestPackages(): array { return [