Skip to content

Commit 791e814

Browse files
wuchen90fabpot
authored andcommitted
feat: add ability to skip package.json synchronization
1 parent 0491870 commit 791e814

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

src/Flex.php

+6
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,12 @@ public function finish(string $rootDir, ?string $originalComposerJsonHash = null
600600

601601
private function synchronizePackageJson(string $rootDir)
602602
{
603+
if (!($this->composer->getPackage()->getExtra()['symfony/flex']['synchronize_package_json'] ?? true)) {
604+
$this->io->writeError('<info>Skip synchronizing package.json with PHP packages</>');
605+
606+
return;
607+
}
608+
603609
if (!$this->downloader->isEnabled()) {
604610
$this->io->writeError('<warning>Synchronizing package.json is disabled: "symfony/flex" not found in the root composer.json</>');
605611

tests/FlexTest.php

+41
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,47 @@ class_exists(LockArrayRepository::class) ? LockArrayRepository::class : Reposito
310310
$this->assertSame('2.3', $recipes['doctrine/doctrine-bundle']->getVersion());
311311
}
312312

313+
public function testInstallWithPackageJsonToSynchronizeSkipped()
314+
{
315+
$io = new BufferIO('', OutputInterface::VERBOSITY_VERBOSE);
316+
$rootPackage = $this->mockRootPackage([
317+
'symfony/flex' => ['synchronize_package_json' => false],
318+
]);
319+
320+
$flex = $this->mockFlex($io, $rootPackage);
321+
$flex->install($this->mockFlexEvent());
322+
323+
$this->assertStringContainsString(
324+
'Skip synchronizing package.json with PHP packages',
325+
$io->getOutput(),
326+
);
327+
}
328+
329+
/**
330+
* @dataProvider getDataForTestInstallWithoutPackageJsonToSynchronizeSkipped
331+
*/
332+
public function testInstallWithoutPackageJsonToSynchronizeSkipped(array $extra)
333+
{
334+
$io = new BufferIO('', OutputInterface::VERBOSITY_VERBOSE);
335+
$rootPackage = $this->mockRootPackage($extra);
336+
337+
$flex = $this->mockFlex($io, $rootPackage);
338+
$flex->install($this->mockFlexEvent());
339+
340+
$this->assertStringNotContainsString(
341+
'Skip synchronizing package.json with PHP packages',
342+
$io->getOutput(),
343+
);
344+
}
345+
346+
public function getDataForTestInstallWithoutPackageJsonToSynchronizeSkipped(): array
347+
{
348+
return [
349+
'default_behavior' => [[]],
350+
'with_config_explicitly_set' => [['symfony/flex' => ['synchronize_package_json' => true]]],
351+
];
352+
}
353+
313354
public static function getTestPackages(): array
314355
{
315356
return [

0 commit comments

Comments
 (0)