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
36 /** @var IConfig|\Mockery\LegacyMockInterface|MockInterface */
39 protected function setUp()
43 \Mockery::getConfiguration()->setConstantsMap([
45 'DBCONFIGAVAILABLE' => 0
49 $this->appMode = \Mockery::mock(App\Mode::class);
50 $this->appMode->shouldReceive('has')
53 $this->configMock = \Mockery::mock(IConfig::class);
56 function testSetGetKeyValue()
59 ->shouldReceive('set')
60 ->with('config', 'test', 'now')
64 ->shouldReceive('get')
65 ->with('config', 'test')
69 $console = new Config($this->appMode, $this->configMock, $this->consoleArgv);
70 $console->setArgument(0, 'config');
71 $console->setArgument(1, 'test');
72 $console->setArgument(2, 'now');
73 $txt = $this->dumpExecute($console);
74 $this->assertEquals("config.test <= now\n", $txt);
77 ->shouldReceive('get')
78 ->with('config', 'test')
82 $console = new Config($this->appMode, $this->configMock, [$this->consoleArgv]);
83 $console->setArgument(0, 'config');
84 $console->setArgument(1, 'test');
85 $txt = $this->dumpExecute($console);
86 $this->assertEquals("config.test => now\n", $txt);
89 ->shouldReceive('get')
90 ->with('config', 'test')
94 $console = new Config($this->appMode, $this->configMock, $this->consoleArgv);
95 $console->setArgument(0, 'config');
96 $console->setArgument(1, 'test');
97 $txt = $this->dumpExecute($console);
98 $this->assertEquals("config.test => \n", $txt);
101 function testSetArrayValue() {
102 $testArray = [1, 2, 3];
104 ->shouldReceive('get')
105 ->with('config', 'test')
106 ->andReturn($testArray)
109 $console = new Config($this->appMode, $this->configMock, $this->consoleArgv);
110 $console->setArgument(0, 'config');
111 $console->setArgument(1, 'test');
112 $console->setArgument(2, 'now');
113 $txt = $this->dumpExecute($console);
115 $this->assertEquals("[Error] config.test is an array and can't be set using this command.\n", $txt);
118 function testTooManyArguments() {
119 $console = new Config($this->appMode, $this->configMock, $this->consoleArgv);
120 $console->setArgument(0, 'config');
121 $console->setArgument(1, 'test');
122 $console->setArgument(2, 'it');
123 $console->setArgument(3, 'now');
124 $txt = $this->dumpExecute($console);
125 $assertion = '[Warning] Too many arguments';
126 $firstline = substr($txt, 0, strlen($assertion));
127 $this->assertEquals($assertion, $firstline);
130 function testVerbose() {
132 ->shouldReceive('get')
136 $console = new Config($this->appMode, $this->configMock, $this->consoleArgv);
137 $console->setArgument(0, 'test');
138 $console->setArgument(1, 'it');
139 $console->setOption('v', 1);
140 $executable = $this->consoleArgv[0];
142 Executable: {$executable}
143 Class: Friendica\Console\Config
154 $txt = $this->dumpExecute($console);
155 $this->assertEquals($assertion, $txt);
158 function testUnableToSet() {
160 ->shouldReceive('set')
161 ->with('test', 'it', 'now')
165 ->shouldReceive('get')
169 $console = new Config($this->appMode, $this->configMock, [$this->consoleArgv]);
170 $console->setArgument(0, 'test');
171 $console->setArgument(1, 'it');
172 $console->setArgument(2, 'now');
173 $txt = $this->dumpExecute($console);
174 $this->assertSame("Unable to set test.it\n", $txt);
177 public function testGetHelp()
179 // Usable to purposely fail if new commands are added without taking tests into account
181 console config - Manage site configuration
183 bin/console config [-h|--help|-?] [-v]
184 bin/console config <category> [-h|--help|-?] [-v]
185 bin/console config <category> <key> [-h|--help|-?] [-v]
186 bin/console config <category> <key> <value> [-h|--help|-?] [-v]
190 Lists all config values
192 bin/console config <category>
193 Lists all config values in the provided category
195 bin/console config <category> <key>
196 Shows the value of the provided key in the category
198 bin/console config <category> <key> <value>
199 Sets the value of the provided key in the category
202 Setting config entries which are manually set in config/local.config.php may result in
203 conflict between database settings and the manual startup settings.
206 -h|--help|-? Show help information
207 -v Show more debug information.
210 $console = new Config($this->appMode, $this->configMock, [$this->consoleArgv]);
211 $console->setOption('help', true);
213 $txt = $this->dumpExecute($console);
215 $this->assertEquals($txt, $theHelp);