1
0
Fork 0
mirror of https://github.com/composer/composer synced 2025-05-09 00:22:53 +00:00

Allow JsonManipulator::addMainKey to update top level keys as well

This commit is contained in:
Jordi Boggiano 2013-05-12 13:24:18 +02:00
parent 7f7d13450e
commit 3bd6af690d
2 changed files with 93 additions and 12 deletions

View file

@ -611,6 +611,57 @@ class JsonManipulatorTest extends \PHPUnit_Framework_TestCase
}
}
}
', $manipulator->getContents());
}
public function testAddMainKey()
{
$manipulator = new JsonManipulator('{
"foo": "bar"
}');
$this->assertTrue($manipulator->addMainKey('bar', 'baz'));
$this->assertEquals('{
"foo": "bar",
"bar": "baz"
}
', $manipulator->getContents());
}
public function testUpdateMainKey()
{
$manipulator = new JsonManipulator('{
"foo": "bar"
}');
$this->assertTrue($manipulator->addMainKey('foo', 'baz'));
$this->assertEquals('{
"foo": "baz"
}
', $manipulator->getContents());
}
public function testUpdateMainKey2()
{
$manipulator = new JsonManipulator('{
"a": {
"foo": "bar",
"baz": "qux"
},
"foo": "bar",
"baz": "bar"
}');
$this->assertTrue($manipulator->addMainKey('foo', 'baz'));
$this->assertTrue($manipulator->addMainKey('baz', 'quux'));
$this->assertEquals('{
"a": {
"foo": "bar",
"baz": "qux"
},
"foo": "baz",
"baz": "quux"
}
', $manipulator->getContents());
}
}