3 * @copyright Copyright (C) 2020, Friendica
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Test\src\Console;
25 use Friendica\App\Mode;
26 use Friendica\Console\Config;
27 use Friendica\Core\Config\IConfig;
29 use Mockery\LegacyMockInterface;
30 use Mockery\MockInterface;
32 class ConfigConsoleTest extends ConsoleTest
35 * @var App\Mode|MockInterface $appMode
38 /** @var IConfig|LegacyMockInterface|MockInterface */
41 protected function setUp()
45 Mockery::getConfiguration()->setConstantsMap([
47 'DBCONFIGAVAILABLE' => 0,
51 $this->appMode = Mockery::mock(App\Mode::class);
52 $this->appMode->shouldReceive('has')
55 $this->configMock = Mockery::mock(IConfig::class);
58 public function testSetGetKeyValue()
61 ->shouldReceive('set')
62 ->with('config', 'test', 'now')
66 ->shouldReceive('get')
67 ->with('config', 'test')
71 $console = new Config($this->appMode, $this->configMock, $this->consoleArgv);
72 $console->setArgument(0, 'config');
73 $console->setArgument(1, 'test');
74 $console->setArgument(2, 'now');
75 $txt = $this->dumpExecute($console);
76 self::assertEquals("config.test <= now\n", $txt);
79 ->shouldReceive('get')
80 ->with('config', 'test')
84 $console = new Config($this->appMode, $this->configMock, [$this->consoleArgv]);
85 $console->setArgument(0, 'config');
86 $console->setArgument(1, 'test');
87 $txt = $this->dumpExecute($console);
88 self::assertEquals("config.test => now\n", $txt);
91 ->shouldReceive('get')
92 ->with('config', 'test')
96 $console = new Config($this->appMode, $this->configMock, $this->consoleArgv);
97 $console->setArgument(0, 'config');
98 $console->setArgument(1, 'test');
99 $txt = $this->dumpExecute($console);
100 self::assertEquals("config.test => \n", $txt);
103 public function testSetArrayValue()
105 $testArray = [1, 2, 3];
107 ->shouldReceive('get')
108 ->with('config', 'test')
109 ->andReturn($testArray)
112 $console = new Config($this->appMode, $this->configMock, $this->consoleArgv);
113 $console->setArgument(0, 'config');
114 $console->setArgument(1, 'test');
115 $console->setArgument(2, 'now');
116 $txt = $this->dumpExecute($console);
118 self::assertEquals("[Error] config.test is an array and can't be set using this command.\n", $txt);
121 public function testTooManyArguments()
123 $console = new Config($this->appMode, $this->configMock, $this->consoleArgv);
124 $console->setArgument(0, 'config');
125 $console->setArgument(1, 'test');
126 $console->setArgument(2, 'it');
127 $console->setArgument(3, 'now');
128 $txt = $this->dumpExecute($console);
129 $assertion = '[Warning] Too many arguments';
130 $firstline = substr($txt, 0, strlen($assertion));
131 self::assertEquals($assertion, $firstline);
134 public function testVerbose()
137 ->shouldReceive('get')
141 $console = new Config($this->appMode, $this->configMock, $this->consoleArgv);
142 $console->setArgument(0, 'test');
143 $console->setArgument(1, 'it');
144 $console->setOption('v', 1);
145 $executable = $this->consoleArgv[0];
147 Executable: {$executable}
148 Class: Friendica\Console\Config
159 $txt = $this->dumpExecute($console);
160 self::assertEquals($assertion, $txt);
163 public function testUnableToSet()
166 ->shouldReceive('set')
167 ->with('test', 'it', 'now')
171 ->shouldReceive('get')
175 $console = new Config($this->appMode, $this->configMock, [$this->consoleArgv]);
176 $console->setArgument(0, 'test');
177 $console->setArgument(1, 'it');
178 $console->setArgument(2, 'now');
179 $txt = $this->dumpExecute($console);
180 self::assertSame("Unable to set test.it\n", $txt);
183 public function testGetHelp()
185 // Usable to purposely fail if new commands are added without taking tests into account
187 console config - Manage site configuration
189 bin/console config [-h|--help|-?] [-v]
190 bin/console config <category> [-h|--help|-?] [-v]
191 bin/console config <category> <key> [-h|--help|-?] [-v]
192 bin/console config <category> <key> <value> [-h|--help|-?] [-v]
196 Lists all config values
198 bin/console config <category>
199 Lists all config values in the provided category
201 bin/console config <category> <key>
202 Shows the value of the provided key in the category
204 bin/console config <category> <key> <value>
205 Sets the value of the provided key in the category
208 Setting config entries which are manually set in config/local.config.php may result in
209 conflict between database settings and the manual startup settings.
212 -h|--help|-? Show help information
213 -v Show more debug information.
216 $console = new Config($this->appMode, $this->configMock, [$this->consoleArgv]);
217 $console->setOption('help', true);
219 $txt = $this->dumpExecute($console);
221 self::assertEquals($txt, $theHelp);