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;
28 use Mockery\MockInterface;
30 class ConfigConsoleTest extends ConsoleTest
33 * @var App\Mode|MockInterface $appMode
37 protected function setUp()
41 \Mockery::getConfiguration()->setConstantsMap([
43 'DBCONFIGAVAILABLE' => 0
47 $this->appMode = \Mockery::mock(App\Mode::class);
48 $this->appMode->shouldReceive('has')
51 $this->configMock = \Mockery::mock(IConfig::class);
54 function testSetGetKeyValue()
57 ->shouldReceive('set')
58 ->with('config', 'test', 'now')
62 ->shouldReceive('get')
63 ->with('config', 'test')
67 $console = new Config($this->appMode, $this->configMock, $this->consoleArgv);
68 $console->setArgument(0, 'config');
69 $console->setArgument(1, 'test');
70 $console->setArgument(2, 'now');
71 $txt = $this->dumpExecute($console);
72 $this->assertEquals("config.test <= now\n", $txt);
75 ->shouldReceive('get')
76 ->with('config', 'test')
80 $console = new Config($this->appMode, $this->configMock, [$this->consoleArgv]);
81 $console->setArgument(0, 'config');
82 $console->setArgument(1, 'test');
83 $txt = $this->dumpExecute($console);
84 $this->assertEquals("config.test => now\n", $txt);
87 ->shouldReceive('get')
88 ->with('config', 'test')
92 $console = new Config($this->appMode, $this->configMock, $this->consoleArgv);
93 $console->setArgument(0, 'config');
94 $console->setArgument(1, 'test');
95 $txt = $this->dumpExecute($console);
96 $this->assertEquals("config.test => \n", $txt);
99 function testSetArrayValue() {
100 $testArray = [1, 2, 3];
102 ->shouldReceive('get')
103 ->with('config', 'test')
104 ->andReturn($testArray)
107 $console = new Config($this->appMode, $this->configMock, $this->consoleArgv);
108 $console->setArgument(0, 'config');
109 $console->setArgument(1, 'test');
110 $console->setArgument(2, 'now');
111 $txt = $this->dumpExecute($console);
113 $this->assertEquals("[Error] config.test is an array and can't be set using this command.\n", $txt);
116 function testTooManyArguments() {
117 $console = new Config($this->appMode, $this->configMock, $this->consoleArgv);
118 $console->setArgument(0, 'config');
119 $console->setArgument(1, 'test');
120 $console->setArgument(2, 'it');
121 $console->setArgument(3, 'now');
122 $txt = $this->dumpExecute($console);
123 $assertion = '[Warning] Too many arguments';
124 $firstline = substr($txt, 0, strlen($assertion));
125 $this->assertEquals($assertion, $firstline);
128 function testVerbose() {
130 ->shouldReceive('get')
134 $console = new Config($this->appMode, $this->configMock, $this->consoleArgv);
135 $console->setArgument(0, 'test');
136 $console->setArgument(1, 'it');
137 $console->setOption('v', 1);
138 $executable = $this->consoleArgv[0];
140 Executable: {$executable}
141 Class: Friendica\Console\Config
152 $txt = $this->dumpExecute($console);
153 $this->assertEquals($assertion, $txt);
156 function testUnableToSet() {
158 ->shouldReceive('set')
159 ->with('test', 'it', 'now')
163 ->shouldReceive('get')
167 $console = new Config($this->appMode, $this->configMock, [$this->consoleArgv]);
168 $console->setArgument(0, 'test');
169 $console->setArgument(1, 'it');
170 $console->setArgument(2, 'now');
171 $txt = $this->dumpExecute($console);
172 $this->assertSame("Unable to set test.it\n", $txt);
175 public function testGetHelp()
177 // Usable to purposely fail if new commands are added without taking tests into account
179 console config - Manage site configuration
181 bin/console config [-h|--help|-?] [-v]
182 bin/console config <category> [-h|--help|-?] [-v]
183 bin/console config <category> <key> [-h|--help|-?] [-v]
184 bin/console config <category> <key> <value> [-h|--help|-?] [-v]
188 Lists all config values
190 bin/console config <category>
191 Lists all config values in the provided category
193 bin/console config <category> <key>
194 Shows the value of the provided key in the category
196 bin/console config <category> <key> <value>
197 Sets the value of the provided key in the category
200 Setting config entries which are manually set in config/local.config.php may result in
201 conflict between database settings and the manual startup settings.
204 -h|--help|-? Show help information
205 -v Show more debug information.
208 $console = new Config($this->appMode, $this->configMock, [$this->consoleArgv]);
209 $console->setOption('help', true);
211 $txt = $this->dumpExecute($console);
213 $this->assertEquals($txt, $theHelp);