Merge pull request #10191 from mexon/mat/user-config-console-command
Add error message when setting config to existing value
This commit is contained in:
commit
cd97f6f25f
|
@ -128,6 +128,10 @@ HELP;
|
||||||
throw new RuntimeException("$cat.$key is an array and can't be set using this command.");
|
throw new RuntimeException("$cat.$key is an array and can't be set using this command.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($this->config->get($cat, $key) === $value) {
|
||||||
|
throw new RuntimeException("$cat.$key already set to $value.");
|
||||||
|
}
|
||||||
|
|
||||||
$result = $this->config->set($cat, $key, $value);
|
$result = $this->config->set($cat, $key, $value);
|
||||||
if ($result) {
|
if ($result) {
|
||||||
$this->out("{$cat}.{$key} <= " .
|
$this->out("{$cat}.{$key} <= " .
|
||||||
|
|
|
@ -65,8 +65,13 @@ class ConfigConsoleTest extends ConsoleTest
|
||||||
$this->configMock
|
$this->configMock
|
||||||
->shouldReceive('get')
|
->shouldReceive('get')
|
||||||
->with('config', 'test')
|
->with('config', 'test')
|
||||||
->andReturn('now')
|
->andReturn('old')
|
||||||
->twice();
|
->twice();
|
||||||
|
$this->configMock
|
||||||
|
->shouldReceive('get')
|
||||||
|
->with('config', 'test')
|
||||||
|
->andReturn('now')
|
||||||
|
->once();
|
||||||
|
|
||||||
$console = new Config($this->appMode, $this->configMock, $this->consoleArgv);
|
$console = new Config($this->appMode, $this->configMock, $this->consoleArgv);
|
||||||
$console->setArgument(0, 'config');
|
$console->setArgument(0, 'config');
|
||||||
|
@ -118,6 +123,23 @@ class ConfigConsoleTest extends ConsoleTest
|
||||||
self::assertEquals("[Error] config.test is an array and can't be set using this command.\n", $txt);
|
self::assertEquals("[Error] config.test is an array and can't be set using this command.\n", $txt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testSetExistingValue()
|
||||||
|
{
|
||||||
|
$this->configMock
|
||||||
|
->shouldReceive('get')
|
||||||
|
->with('config', 'test')
|
||||||
|
->andReturn('now')
|
||||||
|
->twice();
|
||||||
|
|
||||||
|
$console = new Config($this->appMode, $this->configMock, $this->consoleArgv);
|
||||||
|
$console->setArgument(0, 'config');
|
||||||
|
$console->setArgument(1, 'test');
|
||||||
|
$console->setArgument(2, 'now');
|
||||||
|
$txt = $this->dumpExecute($console);
|
||||||
|
|
||||||
|
self::assertEquals("[Error] config.test already set to now.\n", $txt);
|
||||||
|
}
|
||||||
|
|
||||||
public function testTooManyArguments()
|
public function testTooManyArguments()
|
||||||
{
|
{
|
||||||
$console = new Config($this->appMode, $this->configMock, $this->consoleArgv);
|
$console = new Config($this->appMode, $this->configMock, $this->consoleArgv);
|
||||||
|
@ -171,7 +193,7 @@ CONF;
|
||||||
->shouldReceive('get')
|
->shouldReceive('get')
|
||||||
->with('test', 'it')
|
->with('test', 'it')
|
||||||
->andReturn(null)
|
->andReturn(null)
|
||||||
->once();
|
->twice();
|
||||||
$console = new Config($this->appMode, $this->configMock, [$this->consoleArgv]);
|
$console = new Config($this->appMode, $this->configMock, [$this->consoleArgv]);
|
||||||
$console->setArgument(0, 'test');
|
$console->setArgument(0, 'test');
|
||||||
$console->setArgument(1, 'it');
|
$console->setArgument(1, 'it');
|
||||||
|
|
Loading…
Reference in a new issue