]> git.mxchange.org Git - friendica.git/commitdiff
Add error message when setting config to existing value
authorMatthew Exon <git.mexon@spamgourmet.com>
Mon, 26 Apr 2021 18:20:51 +0000 (20:20 +0200)
committerMatthew Exon <git.mexon@spamgourmet.com>
Sat, 1 May 2021 19:10:10 +0000 (21:10 +0200)
src/Console/Config.php
tests/src/Console/ConfigConsoleTest.php

index d9fab41c147ec7098df7a9c116bd3013964cc122..a97574c976056de1a0b8f64011d101a5077f4cd0 100644 (file)
@@ -128,6 +128,10 @@ HELP;
                                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);
                        if ($result) {
                                $this->out("{$cat}.{$key} <= " .
index 5c670aedfcd4c26f0d1ab55e58112abe300c348a..bea4399b3ac333c47ba93d49209ec2d7ac07989c 100644 (file)
@@ -65,8 +65,13 @@ class ConfigConsoleTest extends ConsoleTest
                $this->configMock
                        ->shouldReceive('get')
                        ->with('config', 'test')
-                       ->andReturn('now')
+                       ->andReturn('old')
                        ->twice();
+               $this->configMock
+                       ->shouldReceive('get')
+                       ->with('config', 'test')
+                       ->andReturn('now')
+                       ->once();
 
                $console = new Config($this->appMode, $this->configMock, $this->consoleArgv);
                $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);
        }
 
+       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()
        {
                $console = new Config($this->appMode, $this->configMock, $this->consoleArgv);
@@ -171,7 +193,7 @@ CONF;
                        ->shouldReceive('get')
                        ->with('test', 'it')
                        ->andReturn(null)
-                       ->once();
+                       ->twice();
                $console = new Config($this->appMode, $this->configMock, [$this->consoleArgv]);
                $console->setArgument(0, 'test');
                $console->setArgument(1, 'it');