Merge remote-tracking branch 'adrianosferreira/add-suggest-in-json-by-cli'
commit
f203b3eb41
|
@ -601,6 +601,18 @@ EOT
|
|||
return 0;
|
||||
}
|
||||
|
||||
if (preg_match('/^suggest\.(.+)/', $settingKey, $matches)) {
|
||||
if ($input->getOption('unset')) {
|
||||
$this->configSource->removeProperty($settingKey);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
$this->configSource->addProperty($settingKey, $values[0]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// handle platform
|
||||
if (preg_match('/^platform\.(.+)/', $settingKey, $matches)) {
|
||||
if ($input->getOption('unset')) {
|
||||
|
|
|
@ -167,6 +167,10 @@ class JsonManipulator
|
|||
|
||||
public function addProperty($name, $value)
|
||||
{
|
||||
if (substr($name, 0, 8) === 'suggest.') {
|
||||
return $this->addSubNode('suggest', substr($name, 8), $value);
|
||||
}
|
||||
|
||||
if (substr($name, 0, 6) === 'extra.') {
|
||||
return $this->addSubNode('extra', substr($name, 6), $value);
|
||||
}
|
||||
|
@ -180,6 +184,10 @@ class JsonManipulator
|
|||
|
||||
public function removeProperty($name)
|
||||
{
|
||||
if (substr($name, 0, 8) === 'suggest.') {
|
||||
return $this->removeSubNode('suggest', substr($name, 8));
|
||||
}
|
||||
|
||||
if (substr($name, 0, 6) === 'extra.') {
|
||||
return $this->removeSubNode('extra', substr($name, 6));
|
||||
}
|
||||
|
|
|
@ -1814,6 +1814,46 @@ class JsonManipulatorTest extends TestCase
|
|||
', $manipulator->getContents());
|
||||
}
|
||||
|
||||
public function testAddSuggestWithPackage()
|
||||
{
|
||||
$manipulator = new JsonManipulator('{
|
||||
"repositories": [
|
||||
{
|
||||
"type": "package",
|
||||
"package": {
|
||||
"authors": [],
|
||||
"extra": {
|
||||
"package-xml": "package.xml"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"suggest": {
|
||||
"package": "Description"
|
||||
}
|
||||
}');
|
||||
|
||||
$this->assertTrue($manipulator->addProperty('suggest.new-package', 'new-description'));
|
||||
$this->assertEquals('{
|
||||
"repositories": [
|
||||
{
|
||||
"type": "package",
|
||||
"package": {
|
||||
"authors": [],
|
||||
"extra": {
|
||||
"package-xml": "package.xml"
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"suggest": {
|
||||
"package": "Description",
|
||||
"new-package": "new-description"
|
||||
}
|
||||
}
|
||||
', $manipulator->getContents());
|
||||
}
|
||||
|
||||
public function testAddRepositoryCanInitializeEmptyRepositories()
|
||||
{
|
||||
$manipulator = new JsonManipulator('{
|
||||
|
|
Loading…
Reference in New Issue