Skip to content

Commit 47bd48d

Browse files
authored
[ComposerProcessor] Skip change under "replace", "conflict", "provide" config in composer.json for RaiseToInstalledComposerProcessor (#28)
* [ComposerProcessor] Skip change under "replace", "conflict", "provide" config in composer.json for RaiseToInstalledComposerProcessor * add test fixture
1 parent 3305810 commit 47bd48d

File tree

3 files changed

+46
-8
lines changed

3 files changed

+46
-8
lines changed

src/FileSystem/ComposerJsonPackageVersionUpdater.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@ public static function update(string $composerJsonContents, string $packageName,
1919
sprintf('"%s": "%s"', $packageName, $newVersion)
2020
);
2121

22-
$suggestContent = Strings::match($composerJsonContents, '#"suggest"\s*:\s*{[^}]*}#');
23-
24-
if ($suggestContent !== null) {
25-
$allChanges = Strings::replace(
26-
$allChanges,
27-
'#"suggest"\s*:\s*{[^}]*}#',
28-
$suggestContent[0]
29-
);
22+
$skippedKeys = ['suggest', 'replace', 'provide', 'conflict'];
23+
24+
foreach ($skippedKeys as $skippedKey) {
25+
$regexKeyContent = sprintf('#"%s"\s*:\s*{[^}]*}#', $skippedKey);
26+
$skippedContent = Strings::match($composerJsonContents, $regexKeyContent);
27+
28+
if ($skippedContent !== null) {
29+
$allChanges = Strings::replace($allChanges, $regexKeyContent, $skippedContent[0]);
30+
}
3031
}
3132

3233
return $allChanges;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"require-dev": {
3+
"illuminate/container": "^9.0"
4+
},
5+
"conflict": {
6+
"illuminate/container": "<9.0"
7+
}
8+
}

tests/ComposerProcessor/RaiseToInstalledComposerProcessor/RaiseToInstalledComposerProcessorTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,35 @@ public function testSkipSuggestChange(string $file, string $changedFileContent):
102102
$this->assertSame($changedFileContent, $changedPackageVersionsResult->getComposerJsonContents());
103103
}
104104

105+
public function testSkipConflictChange(): void
106+
{
107+
$composerJsonContents = FileSystem::read(__DIR__ . '/Fixture/skip-conflict.json');
108+
109+
$changedPackageVersionsResult = $this->raiseToInstalledComposerProcessor->process($composerJsonContents);
110+
111+
$changedPackageVersion = $changedPackageVersionsResult->getChangedPackageVersions()[0];
112+
113+
$this->assertSame('illuminate/container', $changedPackageVersion->getPackageName());
114+
$this->assertSame('^9.0', $changedPackageVersion->getOldVersion());
115+
$this->assertSame('^12.19', $changedPackageVersion->getNewVersion());
116+
117+
$this->assertSame(
118+
<<<'JSON'
119+
{
120+
"require-dev": {
121+
"illuminate/container": "^12.19"
122+
},
123+
"conflict": {
124+
"illuminate/container": "<9.0"
125+
}
126+
}
127+
128+
JSON
129+
,
130+
$changedPackageVersionsResult->getComposerJsonContents()
131+
);
132+
}
133+
105134
public function testSinglePiped(): void
106135
{
107136
$composerJsonContents = FileSystem::read(__DIR__ . '/Fixture/single-piped.json');

0 commit comments

Comments
 (0)