Skip to content

Commit 8ce1acd

Browse files
committed
Merge branch '1.x' into 2.x
* 1.x: feat: add ability to skip package.json synchronization
2 parents c5941c6 + 5cc9859 commit 8ce1acd

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
@@ -502,6 +502,12 @@ public function finish(string $rootDir, ?string $originalComposerJsonHash = null
502502

503503
private function synchronizePackageJson(string $rootDir)
504504
{
505+
if (!($this->composer->getPackage()->getExtra()['symfony/flex']['synchronize_package_json'] ?? true)) {
506+
$this->io->writeError('<info>Skip synchronizing package.json with PHP packages</>');
507+
508+
return;
509+
}
510+
505511
if (!$this->downloader->isEnabled()) {
506512
$this->io->writeError('<warning>Synchronizing package.json is disabled: "symfony/flex" not found in the root composer.json</>');
507513

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)