Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Flex.php
Original file line number Diff line number Diff line change
Expand Up @@ -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('<info>Skip synchronizing package.json with PHP packages</>');

return;
}

if (!$this->downloader->isEnabled()) {
$this->io->writeError('<warning>Synchronizing package.json is disabled: "symfony/flex" not found in the root composer.json</>');

Expand Down
41 changes: 41 additions & 0 deletions tests/FlexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down
Loading