Skip to content

Commit 5d506a0

Browse files
MAGETWO-61778: Implement config:set command
1 parent b82710d commit 5d506a0

File tree

6 files changed

+24
-136
lines changed

6 files changed

+24
-136
lines changed

app/code/Magento/Config/Console/Command/ConfigSet/ConfigSetProcessorInterface.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,25 @@
55
*/
66
namespace Magento\Config\Console\Command\ConfigSet;
77

8+
use Magento\Config\Console\Command\ConfigSetCommand;
89
use Magento\Framework\Exception\CouldNotSaveException;
9-
use Symfony\Component\Console\Input\InputInterface;
1010

1111
/**
1212
* Allows to process different flows of config:set command.
1313
*
14-
* @see \Magento\Config\Console\Command\ConfigSetCommand
14+
* @see ConfigSetCommand
1515
*/
1616
interface ConfigSetProcessorInterface
1717
{
1818
/**
1919
* Processes config:set command.
2020
*
21-
* @param InputInterface $input An input console parameter
21+
* @param string $path The configuration path in format group/section/field_name
22+
* @param string $value The configuration value
23+
* @param string $scope The configuration scope (default, website, or store)
24+
* @param string $scopeCode The scope code
2225
* @return void
2326
* @throws CouldNotSaveException An exception on processing error
2427
*/
25-
public function process(InputInterface $input);
28+
public function process($path, $value, $scope, $scopeCode);
2629
}

app/code/Magento/Config/Console/Command/ConfigSet/DefaultProcessor.php

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
use Magento\Framework\App\DeploymentConfig;
1414
use Magento\Framework\Exception\CouldNotSaveException;
1515
use Magento\Store\Model\ScopeInterface;
16-
use Symfony\Component\Console\Input\InputInterface;
1716

1817
/**
1918
* Processes default flow of config:set command.
@@ -66,17 +65,8 @@ public function __construct(
6665
*
6766
* {@inheritdoc}
6867
*/
69-
public function process(InputInterface $input)
68+
public function process($path, $value, $scope, $scopeCode)
7069
{
71-
try {
72-
$path = $input->getArgument(ConfigSetCommand::ARG_PATH);
73-
$value = $input->getArgument(ConfigSetCommand::ARG_VALUE);
74-
$scope = $input->getOption(ConfigSetCommand::OPTION_SCOPE);
75-
$scopeCode = $input->getOption(ConfigSetCommand::OPTION_SCOPE_CODE);
76-
} catch (\Exception $exception) {
77-
throw new CouldNotSaveException(__('%1', $exception->getMessage()), $exception);
78-
}
79-
8070
if (!$this->deploymentConfig->isAvailable()) {
8171
throw new CouldNotSaveException(
8272
__(

app/code/Magento/Config/Console/Command/ConfigSet/LockProcessor.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,14 @@
66
namespace Magento\Config\Console\Command\ConfigSet;
77

88
use Magento\Config\App\Config\Type\System;
9-
use Magento\Config\Console\Command\ConfigSetCommand;
109
use Magento\Config\Model\Config\Structure;
11-
use Magento\Config\Model\Config\Structure\Element\Field;
1210
use Magento\Framework\App\Config\ConfigPathResolver;
1311
use Magento\Framework\App\Config\Value;
1412
use Magento\Framework\App\Config\ValueFactory;
1513
use Magento\Framework\App\DeploymentConfig;
1614
use Magento\Framework\Config\File\ConfigFilePool;
1715
use Magento\Framework\Exception\CouldNotSaveException;
1816
use Magento\Framework\Stdlib\ArrayManager;
19-
use Symfony\Component\Console\Input\InputInterface;
2017

2118
/**
2219
* Processes file lock flow of config:set command.
@@ -99,16 +96,11 @@ public function __construct(
9996
*
10097
* {@inheritdoc}
10198
*/
102-
public function process(InputInterface $input)
99+
public function process($path, $value, $scope, $scopeCode)
103100
{
104101
try {
105-
$path = $input->getArgument(ConfigSetCommand::ARG_PATH);
106-
$value = $input->getArgument(ConfigSetCommand::ARG_VALUE);
107-
$scope = $input->getOption(ConfigSetCommand::OPTION_SCOPE);
108-
$scopeCode = $input->getOption(ConfigSetCommand::OPTION_SCOPE_CODE);
109-
110102
$configPath = $this->configPathResolver->resolve($path, $scope, $scopeCode, System::CONFIG_TYPE);
111-
/** @var Field $field */
103+
/** @var Structure\Element\Field $field */
112104
$field = $this->deploymentConfig->isAvailable()
113105
? $this->configStructure->getElement($path)
114106
: null;

app/code/Magento/Config/Console/Command/ConfigSetCommand.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ protected function configure()
9090
static::OPTION_SCOPE_CODE,
9191
null,
9292
InputArgument::OPTIONAL,
93-
'Scope code (required only if scope code is not \'default\')'
93+
'Scope code (required only if scope is not \'default\')'
9494
),
9595
new InputOption(
9696
static::OPTION_LOCK,
@@ -127,7 +127,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
127127
: 'Value was saved.';
128128

129129
// The processing flow depends on --lock option.
130-
$processor->process($input);
130+
$processor->process(
131+
$input->getArgument(ConfigSetCommand::ARG_PATH),
132+
$input->getArgument(ConfigSetCommand::ARG_VALUE),
133+
$input->getOption(ConfigSetCommand::OPTION_SCOPE),
134+
$input->getOption(ConfigSetCommand::OPTION_SCOPE_CODE)
135+
);
131136

132137
$output->writeln('<info>' . $message . '</info>');
133138

app/code/Magento/Config/Test/Unit/Console/Command/ConfigSet/DefaultProcessorTest.php

Lines changed: 3 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,13 @@
77

88
use Magento\Config\App\Config\Type\System;
99
use Magento\Config\Console\Command\ConfigSet\DefaultProcessor;
10-
use Magento\Config\Console\Command\ConfigSetCommand;
1110
use Magento\Config\Model\Config;
1211
use Magento\Config\Model\ConfigFactory;
1312
use Magento\Framework\App\Config\ConfigPathResolver;
1413
use Magento\Framework\App\Config\ScopeConfigInterface;
1514
use Magento\Framework\App\DeploymentConfig;
1615
use Magento\Store\Model\ScopeInterface;
1716
use PHPUnit_Framework_MockObject_MockObject as Mock;
18-
use Symfony\Component\Console\Input\InputInterface;
1917

2018
/**
2119
* Test for DefaultProcessor.
@@ -50,11 +48,6 @@ class DefaultProcessorTest extends \PHPUnit_Framework_TestCase
5048
*/
5149
private $configPathResolverMock;
5250

53-
/**
54-
* @var InputInterface|Mock
55-
*/
56-
private $inputMock;
57-
5851
/**
5952
* @inheritdoc
6053
*/
@@ -70,8 +63,6 @@ protected function setUp()
7063
$this->deploymentConfigMock = $this->getMockBuilder(DeploymentConfig::class)
7164
->disableOriginalConstructor()
7265
->getMock();
73-
$this->inputMock = $this->getMockBuilder(InputInterface::class)
74-
->getMockForAbstractClass();
7566
$this->configPathResolverMock = $this->getMockBuilder(ConfigPathResolver::class)
7667
->disableOriginalConstructor()
7768
->getMock();
@@ -98,18 +89,6 @@ protected function setUp()
9889
*/
9990
public function testProcess($path, $value, $scope, $scopeCode)
10091
{
101-
$this->inputMock->expects($this->any())
102-
->method('getArgument')
103-
->willReturnMap([
104-
[ConfigSetCommand::ARG_PATH, $path],
105-
[ConfigSetCommand::ARG_VALUE, $value]
106-
]);
107-
$this->inputMock->expects($this->any())
108-
->method('getOption')
109-
->willReturnMap([
110-
[ConfigSetCommand::OPTION_SCOPE, $scope],
111-
[ConfigSetCommand::OPTION_SCOPE_CODE, $scopeCode],
112-
]);
11392
$this->configPathResolverMock->expects($this->once())
11493
->method('resolve')
11594
->with($path, $scope, $scopeCode, System::CONFIG_TYPE)
@@ -125,7 +104,7 @@ public function testProcess($path, $value, $scope, $scopeCode)
125104
$this->configMock->expects($this->once())
126105
->method('save');
127106

128-
$this->model->process($this->inputMock);
107+
$this->model->process($path, $value, $scope, $scopeCode);
129108
}
130109

131110
/**
@@ -149,25 +128,13 @@ public function testProcessNotInstalled()
149128
$path = 'test/test/test';
150129
$value = 'value';
151130

152-
$this->inputMock->expects($this->any())
153-
->method('getArgument')
154-
->willReturnMap([
155-
[ConfigSetCommand::ARG_PATH, $path],
156-
[ConfigSetCommand::ARG_VALUE, $value]
157-
]);
158-
$this->inputMock->expects($this->any())
159-
->method('getOption')
160-
->willReturnMap([
161-
[ConfigSetCommand::OPTION_SCOPE, ScopeConfigInterface::SCOPE_TYPE_DEFAULT],
162-
[ConfigSetCommand::OPTION_SCOPE_CODE, null],
163-
]);
164131
$this->deploymentConfigMock->expects($this->once())
165132
->method('isAvailable')
166133
->willReturn(false);
167134
$this->configMock->expects($this->never())
168135
->method('save');
169136

170-
$this->model->process($this->inputMock);
137+
$this->model->process($path, $value, ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null);
171138
}
172139

173140
/**
@@ -179,18 +146,6 @@ public function testProcessLockedValue()
179146
$path = 'test/test/test';
180147
$value = 'value';
181148

182-
$this->inputMock->expects($this->any())
183-
->method('getArgument')
184-
->willReturnMap([
185-
[ConfigSetCommand::ARG_PATH, $path],
186-
[ConfigSetCommand::ARG_VALUE, $value]
187-
]);
188-
$this->inputMock->expects($this->any())
189-
->method('getOption')
190-
->willReturnMap([
191-
[ConfigSetCommand::OPTION_SCOPE, ScopeConfigInterface::SCOPE_TYPE_DEFAULT],
192-
[ConfigSetCommand::OPTION_SCOPE_CODE, null],
193-
]);
194149
$this->deploymentConfigMock->expects($this->once())
195150
->method('isAvailable')
196151
->willReturn(true);
@@ -204,6 +159,6 @@ public function testProcessLockedValue()
204159
->method('resolve')
205160
->willReturn('system/default/test/test/test');
206161

207-
$this->model->process($this->inputMock);
162+
$this->model->process($path, $value, ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null);
208163
}
209164
}

app/code/Magento/Config/Test/Unit/Console/Command/ConfigSet/LockProcessorTest.php

Lines changed: 4 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
namespace Magento\Config\Test\Unit\Console\Command\ConfigSet;
77

88
use Magento\Config\Console\Command\ConfigSet\LockProcessor;
9-
use Magento\Config\Console\Command\ConfigSetCommand;
109
use Magento\Config\Model\Config\Structure;
1110
use Magento\Config\Model\Config\Structure\Element\Field;
1211
use Magento\Framework\App\Config\ConfigPathResolver;
@@ -19,7 +18,6 @@
1918
use Magento\Framework\Stdlib\ArrayManager;
2019
use Magento\Store\Model\ScopeInterface;
2120
use PHPUnit_Framework_MockObject_MockObject as Mock;
22-
use Symfony\Component\Console\Input\InputInterface;
2321

2422
/**
2523
* Test for LockProcessor.
@@ -49,11 +47,6 @@ class LockProcessorTest extends \PHPUnit_Framework_TestCase
4947
*/
5048
private $arrayManagerMock;
5149

52-
/**
53-
* @var InputInterface|Mock
54-
*/
55-
private $inputMock;
56-
5750
/**
5851
* @var ConfigPathResolver|Mock
5952
*/
@@ -93,8 +86,6 @@ protected function setUp()
9386
$this->arrayManagerMock = $this->getMockBuilder(ArrayManager::class)
9487
->disableOriginalConstructor()
9588
->getMock();
96-
$this->inputMock = $this->getMockBuilder(InputInterface::class)
97-
->getMockForAbstractClass();
9889
$this->configPathResolver = $this->getMockBuilder(ConfigPathResolver::class)
9990
->disableOriginalConstructor()
10091
->getMock();
@@ -143,18 +134,6 @@ protected function setUp()
143134
*/
144135
public function testProcess($path, $value, $scope, $scopeCode)
145136
{
146-
$this->inputMock->expects($this->any())
147-
->method('getArgument')
148-
->willReturnMap([
149-
[ConfigSetCommand::ARG_PATH, $path],
150-
[ConfigSetCommand::ARG_VALUE, $value],
151-
]);
152-
$this->inputMock->expects($this->any())
153-
->method('getOption')
154-
->willReturnMap([
155-
[ConfigSetCommand::OPTION_SCOPE, $scope],
156-
[ConfigSetCommand::OPTION_SCOPE_CODE, $scopeCode]
157-
]);
158137
$this->fieldMock->expects($this->once())
159138
->method('hasBackendModel')
160139
->willReturn(true);
@@ -206,7 +185,7 @@ public function testProcess($path, $value, $scope, $scopeCode)
206185
$this->valueMock->expects($this->once())
207186
->method('afterSave');
208187

209-
$this->model->process($this->inputMock);
188+
$this->model->process($path, $value, $scope, $scopeCode);
210189
}
211190

212191
/**
@@ -226,18 +205,6 @@ public function testProcessBackendModelNotExists()
226205
$path = 'test/test/test';
227206
$value = 'value';
228207

229-
$this->inputMock->expects($this->any())
230-
->method('getArgument')
231-
->willReturnMap([
232-
[ConfigSetCommand::ARG_PATH, $path],
233-
[ConfigSetCommand::ARG_VALUE, $value],
234-
]);
235-
$this->inputMock->expects($this->any())
236-
->method('getOption')
237-
->willReturnMap([
238-
[ConfigSetCommand::OPTION_SCOPE, ScopeConfigInterface::SCOPE_TYPE_DEFAULT],
239-
[ConfigSetCommand::OPTION_SCOPE_CODE, 'test_scope_code']
240-
]);
241208
$this->fieldMock->expects($this->once())
242209
->method('hasBackendModel')
243210
->willReturn(false);
@@ -282,7 +249,7 @@ public function testProcessBackendModelNotExists()
282249
false
283250
);
284251

285-
$this->model->process($this->inputMock);
252+
$this->model->process($path, $value, ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null);
286253
}
287254

288255
/**
@@ -294,18 +261,6 @@ public function testProcessNotReadableFs()
294261
$path = 'test/test/test';
295262
$value = 'value';
296263

297-
$this->inputMock->expects($this->any())
298-
->method('getArgument')
299-
->willReturnMap([
300-
[ConfigSetCommand::ARG_PATH, $path],
301-
[ConfigSetCommand::ARG_VALUE, $value],
302-
]);
303-
$this->inputMock->expects($this->any())
304-
->method('getOption')
305-
->willReturnMap([
306-
[ConfigSetCommand::OPTION_SCOPE, ScopeConfigInterface::SCOPE_TYPE_DEFAULT],
307-
[ConfigSetCommand::OPTION_SCOPE_CODE, 'test_scope_code'],
308-
]);
309264
$this->fieldMock->expects($this->once())
310265
->method('hasBackendModel')
311266
->willReturn(true);
@@ -326,7 +281,7 @@ public function testProcessNotReadableFs()
326281
->method('saveConfig')
327282
->willThrowException(new FileSystemException(__('Filesystem is not writable.')));
328283

329-
$this->model->process($this->inputMock);
284+
$this->model->process($path, $value, ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null);
330285
}
331286

332287
/**
@@ -338,18 +293,6 @@ public function testCustomException()
338293
$path = 'test/test/test';
339294
$value = 'value';
340295

341-
$this->inputMock->expects($this->any())
342-
->method('getArgument')
343-
->willReturnMap([
344-
[ConfigSetCommand::ARG_PATH, $path],
345-
[ConfigSetCommand::ARG_VALUE, $value],
346-
]);
347-
$this->inputMock->expects($this->any())
348-
->method('getOption')
349-
->willReturnMap([
350-
[ConfigSetCommand::OPTION_SCOPE, ScopeConfigInterface::SCOPE_TYPE_DEFAULT],
351-
[ConfigSetCommand::OPTION_SCOPE_CODE, 'test_scope_code']
352-
]);
353296
$this->fieldMock->expects($this->once())
354297
->method('hasBackendModel')
355298
->willReturn(true);
@@ -369,6 +312,6 @@ public function testCustomException()
369312
$this->deploymentConfigWriterMock->expects($this->never())
370313
->method('saveConfig');
371314

372-
$this->model->process($this->inputMock);
315+
$this->model->process($path, $value, ScopeConfigInterface::SCOPE_TYPE_DEFAULT, null);
373316
}
374317
}

0 commit comments

Comments
 (0)