Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add ability to skip package.json synchronization #1032

Open
wants to merge 1 commit into
base: 2.x
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions src/Flex.php
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,14 @@ public function finish(string $rootDir, ?string $originalComposerJsonHash = null

private function synchronizePackageJson(string $rootDir)
{
$synchronizePackageJson = $this->composer->getPackage()->getExtra()['symfony/flex']['synchronize_package_json'] ?? true;

if (!$synchronizePackageJson) {
$this->io->writeError('<info>Skip synchronizing package.json with PHP packages</>');

return;
}

$rootDir = realpath($rootDir);
$vendorDir = trim((new Filesystem())->makePathRelative($this->config->get('vendor-dir'), $rootDir), '/');

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