diff --git a/src/FileSystem/ComposerJsonPackageVersionUpdater.php b/src/FileSystem/ComposerJsonPackageVersionUpdater.php index d378b73..f66dd9b 100644 --- a/src/FileSystem/ComposerJsonPackageVersionUpdater.php +++ b/src/FileSystem/ComposerJsonPackageVersionUpdater.php @@ -19,14 +19,15 @@ public static function update(string $composerJsonContents, string $packageName, sprintf('"%s": "%s"', $packageName, $newVersion) ); - $suggestContent = Strings::match($composerJsonContents, '#"suggest"\s*:\s*{[^}]*}#'); - - if ($suggestContent !== null) { - $allChanges = Strings::replace( - $allChanges, - '#"suggest"\s*:\s*{[^}]*}#', - $suggestContent[0] - ); + $skippedKeys = ['suggest', 'replace', 'provide', 'conflict']; + + foreach ($skippedKeys as $skippedKey) { + $regexKeyContent = sprintf('#"%s"\s*:\s*{[^}]*}#', $skippedKey); + $skippedContent = Strings::match($composerJsonContents, $regexKeyContent); + + if ($skippedContent !== null) { + $allChanges = Strings::replace($allChanges, $regexKeyContent, $skippedContent[0]); + } } return $allChanges; diff --git a/tests/ComposerProcessor/RaiseToInstalledComposerProcessor/Fixture/skip-conflict.json b/tests/ComposerProcessor/RaiseToInstalledComposerProcessor/Fixture/skip-conflict.json new file mode 100644 index 0000000..cfe563c --- /dev/null +++ b/tests/ComposerProcessor/RaiseToInstalledComposerProcessor/Fixture/skip-conflict.json @@ -0,0 +1,8 @@ +{ + "require-dev": { + "illuminate/container": "^9.0" + }, + "conflict": { + "illuminate/container": "<9.0" + } +} diff --git a/tests/ComposerProcessor/RaiseToInstalledComposerProcessor/RaiseToInstalledComposerProcessorTest.php b/tests/ComposerProcessor/RaiseToInstalledComposerProcessor/RaiseToInstalledComposerProcessorTest.php index c7c5d32..ba13208 100644 --- a/tests/ComposerProcessor/RaiseToInstalledComposerProcessor/RaiseToInstalledComposerProcessorTest.php +++ b/tests/ComposerProcessor/RaiseToInstalledComposerProcessor/RaiseToInstalledComposerProcessorTest.php @@ -102,6 +102,35 @@ public function testSkipSuggestChange(string $file, string $changedFileContent): $this->assertSame($changedFileContent, $changedPackageVersionsResult->getComposerJsonContents()); } + public function testSkipConflictChange(): void + { + $composerJsonContents = FileSystem::read(__DIR__ . '/Fixture/skip-conflict.json'); + + $changedPackageVersionsResult = $this->raiseToInstalledComposerProcessor->process($composerJsonContents); + + $changedPackageVersion = $changedPackageVersionsResult->getChangedPackageVersions()[0]; + + $this->assertSame('illuminate/container', $changedPackageVersion->getPackageName()); + $this->assertSame('^9.0', $changedPackageVersion->getOldVersion()); + $this->assertSame('^12.19', $changedPackageVersion->getNewVersion()); + + $this->assertSame( + <<<'JSON' + { + "require-dev": { + "illuminate/container": "^12.19" + }, + "conflict": { + "illuminate/container": "<9.0" + } + } + + JSON + , + $changedPackageVersionsResult->getComposerJsonContents() + ); + } + public function testSinglePiped(): void { $composerJsonContents = FileSystem::read(__DIR__ . '/Fixture/single-piped.json');