3 namespace Friendica\Test\src\Core\Console;
5 use Friendica\App\Mode;
6 use Friendica\Core\Console\Config;
9 * @runTestsInSeparateProcesses
10 * @preserveGlobalState disabled
13 class ConfigConsoleTest extends ConsoleTest
15 protected function setUp()
19 $this->mockApp($this->root);
21 \Mockery::getConfiguration()->setConstantsMap([
23 'DBCONFIGAVAILABLE' => 0
27 $mode = \Mockery::mock(Mode::class);
29 ->shouldReceive('has')
33 ->shouldReceive('getMode')
37 function testSetGetKeyValue() {
39 ->shouldReceive('set')
40 ->with('config', 'test', 'now')
44 ->shouldReceive('get')
45 ->with('config', 'test')
49 $console = new Config($this->consoleArgv);
50 $console->setArgument(0, 'config');
51 $console->setArgument(1, 'test');
52 $console->setArgument(2, 'now');
53 $txt = $this->dumpExecute($console);
54 $this->assertEquals("config.test <= now\n", $txt);
57 ->shouldReceive('get')
58 ->with('config', 'test')
62 $console = new Config($this->consoleArgv);
63 $console->setArgument(0, 'config');
64 $console->setArgument(1, 'test');
65 $txt = $this->dumpExecute($console);
66 $this->assertEquals("config.test => now\n", $txt);
69 ->shouldReceive('get')
70 ->with('config', 'test')
74 $console = new Config($this->consoleArgv);
75 $console->setArgument(0, 'config');
76 $console->setArgument(1, 'test');
77 $txt = $this->dumpExecute($console);
78 $this->assertEquals("config.test => \n", $txt);
81 function testSetArrayValue() {
82 $testArray = [1, 2, 3];
84 ->shouldReceive('get')
85 ->with('config', 'test')
86 ->andReturn($testArray)
89 $console = new Config($this->consoleArgv);
90 $console->setArgument(0, 'config');
91 $console->setArgument(1, 'test');
92 $console->setArgument(2, 'now');
93 $txt = $this->dumpExecute($console);
95 $this->assertEquals("[Error] config.test is an array and can't be set using this command.\n", $txt);
98 function testTooManyArguments() {
99 $console = new Config($this->consoleArgv);
100 $console->setArgument(0, 'config');
101 $console->setArgument(1, 'test');
102 $console->setArgument(2, 'it');
103 $console->setArgument(3, 'now');
104 $txt = $this->dumpExecute($console);
105 $assertion = '[Warning] Too many arguments';
106 $firstline = substr($txt, 0, strlen($assertion));
107 $this->assertEquals($assertion, $firstline);
110 function testVerbose() {
112 ->shouldReceive('get')
116 $console = new Config($this->consoleArgv);
117 $console->setArgument(0, 'test');
118 $console->setArgument(1, 'it');
119 $console->setOption('v', 1);
120 $executable = $this->consoleArgv[0];
122 Executable: {$executable}
123 Class: Friendica\Core\Console\Config
134 $txt = $this->dumpExecute($console);
135 $this->assertEquals($assertion, $txt);
138 function testUnableToSet() {
140 ->shouldReceive('set')
141 ->with('test', 'it', 'now')
145 ->shouldReceive('get')
149 $console = new Config();
150 $console->setArgument(0, 'test');
151 $console->setArgument(1, 'it');
152 $console->setArgument(2, 'now');
153 $txt = $this->dumpExecute($console);
154 $this->assertSame("Unable to set test.it\n", $txt);
157 public function testGetHelp()
159 // Usable to purposely fail if new commands are added without taking tests into account
161 console config - Manage site configuration
163 bin/console config [-h|--help|-?] [-v]
164 bin/console config <category> [-h|--help|-?] [-v]
165 bin/console config <category> <key> [-h|--help|-?] [-v]
166 bin/console config <category> <key> <value> [-h|--help|-?] [-v]
170 Lists all config values
172 bin/console config <category>
173 Lists all config values in the provided category
175 bin/console config <category> <key>
176 Shows the value of the provided key in the category
178 bin/console config <category> <key> <value>
179 Sets the value of the provided key in the category
182 Setting config entries which are manually set in config/local.config.php may result in
183 conflict between database settings and the manual startup settings.
186 -h|--help|-? Show help information
187 -v Show more debug information.
190 $console = new Config($this->consoleArgv);
191 $console->setOption('help', true);
193 $txt = $this->dumpExecute($console);
195 $this->assertEquals($txt, $theHelp);