diff --git a/src/Composer/Json/JsonManipulator.php b/src/Composer/Json/JsonManipulator.php index 809cea57a..2e0f70411 100644 --- a/src/Composer/Json/JsonManipulator.php +++ b/src/Composer/Json/JsonManipulator.php @@ -430,6 +430,9 @@ class JsonManipulator if ($subName !== null) { $curVal = json_decode($matches['content'], true); unset($curVal[$name][$subName]); + if ($curVal[$name] === []) { + $curVal[$name] = new \ArrayObject(); + } $childrenClean = $this->format($curVal, 0, true); } diff --git a/tests/Composer/Test/Command/ConfigCommandTest.php b/tests/Composer/Test/Command/ConfigCommandTest.php index 27ee92b4a..cf3a55acc 100644 --- a/tests/Composer/Test/Command/ConfigCommandTest.php +++ b/tests/Composer/Test/Command/ConfigCommandTest.php @@ -82,6 +82,11 @@ class ConfigCommandTest extends TestCase ['setting-key' => 'preferred-install.foo/*', '--unset' => true], ['config' => ['preferred-install' => []]], ]; + yield 'unset platform' => [ + ['config' => ['platform' => ['php' => '7.2.5'], 'platform-check' => false]], + ['setting-key' => 'platform.php', '--unset' => true], + ['config' => ['platform' => [], 'platform-check' => false]], + ]; yield 'set extra with merge' => [ [], ['setting-key' => 'extra.patches.foo/bar', 'setting-value' => ['{"123":"value"}'], '--json' => true, '--merge' => true],