1
0
Fork 0

Merge pull request #6945 from localheinz/fix/remove-main-key

Fix: Remove key when value is null
pull/6955/head
Jordi Boggiano 2017-12-29 15:25:34 +01:00 committed by GitHub
commit ad27182618
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

View File

@ -417,7 +417,7 @@ class JsonManipulator
{
$decoded = JsonFile::parseJson($this->contents);
if (!isset($decoded[$key])) {
if (!array_key_exists($key, $decoded)) {
return true;
}

View File

@ -2310,6 +2310,22 @@ class JsonManipulatorTest extends TestCase
', $manipulator->getContents());
}
public function testRemoveMainKeyRemovesKeyWhereValueIsNull()
{
$manipulator = new JsonManipulator(json_encode(array(
'foo' => 9000,
'bar' => null,
)));
$manipulator->removeMainKey('bar');
$expected = json_encode(array(
'foo' => 9000,
));
$this->assertJsonStringEqualsJsonString($expected, $manipulator->getContents());
}
public function testIndentDetection()
{
$manipulator = new JsonManipulator('{