3 * @copyright Copyright (C) 2010-2022, the Friendica project
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\Capability\IManageConfigValues;
29 use Mockery\LegacyMockInterface;
30 use Mockery\MockInterface;
32 class ConfigConsoleTest extends ConsoleTest
35 * @var App\Mode|MockInterface $appMode
38 /** @var IManageConfigValues|LegacyMockInterface|MockInterface */
41 protected function setUp() : void
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(IManageConfigValues::class);
58 public function testSetGetKeyValue()
61 ->shouldReceive('set')
62 ->with('config', 'test', 'now')
66 ->shouldReceive('get')
67 ->with('config', 'test')
71 ->shouldReceive('get')
72 ->with('config', 'test')
76 $console = new Config($this->appMode, $this->configMock, $this->consoleArgv);
77 $console->setArgument(0, 'config');
78 $console->setArgument(1, 'test');
79 $console->setArgument(2, 'now');
80 $txt = $this->dumpExecute($console);
81 self::assertEquals("config.test <= now\n", $txt);
84 ->shouldReceive('get')
85 ->with('config', 'test')
89 $console = new Config($this->appMode, $this->configMock, [$this->consoleArgv]);
90 $console->setArgument(0, 'config');
91 $console->setArgument(1, 'test');
92 $txt = $this->dumpExecute($console);
93 self::assertEquals("config.test => now\n", $txt);
96 ->shouldReceive('get')
97 ->with('config', 'test')
101 $console = new Config($this->appMode, $this->configMock, $this->consoleArgv);
102 $console->setArgument(0, 'config');
103 $console->setArgument(1, 'test');
104 $txt = $this->dumpExecute($console);
105 self::assertEquals("config.test => \n", $txt);
108 public function testSetArrayValue()
110 $testArray = [1, 2, 3];
112 ->shouldReceive('get')
113 ->with('config', 'test')
114 ->andReturn($testArray)
117 $console = new Config($this->appMode, $this->configMock, $this->consoleArgv);
118 $console->setArgument(0, 'config');
119 $console->setArgument(1, 'test');
120 $console->setArgument(2, 'now');
121 $txt = $this->dumpExecute($console);
123 self::assertEquals("[Error] config.test is an array and can't be set using this command.\n", $txt);
126 public function testSetExistingValue()
129 ->shouldReceive('get')
130 ->with('config', 'test')
134 $console = new Config($this->appMode, $this->configMock, $this->consoleArgv);
135 $console->setArgument(0, 'config');
136 $console->setArgument(1, 'test');
137 $console->setArgument(2, 'now');
138 $txt = $this->dumpExecute($console);
140 self::assertEquals("[Error] config.test already set to now.\n", $txt);
143 public function testTooManyArguments()
145 $console = new Config($this->appMode, $this->configMock, $this->consoleArgv);
146 $console->setArgument(0, 'config');
147 $console->setArgument(1, 'test');
148 $console->setArgument(2, 'it');
149 $console->setArgument(3, 'now');
150 $txt = $this->dumpExecute($console);
151 $assertion = '[Warning] Too many arguments';
152 $firstline = substr($txt, 0, strlen($assertion));
153 self::assertEquals($assertion, $firstline);
156 public function testVerbose()
159 ->shouldReceive('get')
163 $console = new Config($this->appMode, $this->configMock, $this->consoleArgv);
164 $console->setArgument(0, 'test');
165 $console->setArgument(1, 'it');
166 $console->setOption('v', 1);
167 $executable = $this->consoleArgv[0];
169 Executable: {$executable}
170 Class: Friendica\Console\Config
181 $txt = $this->dumpExecute($console);
182 self::assertEquals($assertion, $txt);
185 public function testUnableToSet()
188 ->shouldReceive('set')
189 ->with('test', 'it', 'now')
193 ->shouldReceive('get')
197 $console = new Config($this->appMode, $this->configMock, [$this->consoleArgv]);
198 $console->setArgument(0, 'test');
199 $console->setArgument(1, 'it');
200 $console->setArgument(2, 'now');
201 $txt = $this->dumpExecute($console);
202 self::assertSame("Unable to set test.it\n", $txt);
205 public function testGetHelp()
207 // Usable to purposely fail if new commands are added without taking tests into account
209 console config - Manage site configuration
211 bin/console config [-h|--help|-?] [-v]
212 bin/console config <category> [-h|--help|-?] [-v]
213 bin/console config <category> <key> [-h|--help|-?] [-v]
214 bin/console config <category> <key> <value> [-h|--help|-?] [-v]
218 Lists all config values
220 bin/console config <category>
221 Lists all config values in the provided category
223 bin/console config <category> <key>
224 Shows the value of the provided key in the category
226 bin/console config <category> <key> <value>
227 Sets the value of the provided key in the category
230 Setting config entries which are manually set in config/local.config.php may result in
231 conflict between database settings and the manual startup settings.
234 -h|--help|-? Show help information
235 -v Show more debug information.
238 $console = new Config($this->appMode, $this->configMock, [$this->consoleArgv]);
239 $console->setOption('help', true);
241 $txt = $this->dumpExecute($console);
243 self::assertEquals($txt, $theHelp);