3 namespace Friendica\Test\src\Core\Console;
5 use Friendica\Core\Console\Config;
8 * @runTestsInSeparateProcesses
9 * @preserveGlobalState disabled
12 class ConfigConsoleTest extends ConsoleTest
14 protected function setUp()
18 \Mockery::getConfiguration()->setConstantsMap([
19 'Friendica\App\Mode' => [
20 'DBCONFIGAVAILABLE' => 0
24 $mode = \Mockery::mock('Friendica\App\Mode');
26 ->shouldReceive('has')
30 ->shouldReceive('getMode')
34 function testSetGetKeyValue() {
35 $this->mockConfigSet('config', 'test', 'now', 1);
36 $console = new Config($this->consoleArgv);
37 $console->setArgument(0, 'config');
38 $console->setArgument(1, 'test');
39 $console->setArgument(2, 'now');
40 $txt = $this->dumpExecute($console);
41 $this->assertEquals("config.test <= now\n", $txt);
43 $this->mockConfigGet('config', 'test', 'now', 1);
44 $console = new Config($this->consoleArgv);
45 $console->setArgument(0, 'config');
46 $console->setArgument(1, 'test');
47 $txt = $this->dumpExecute($console);
48 $this->assertEquals("config.test => now\n", $txt);
50 $this->mockConfigGet('config', 'test', null, 1);
51 $console = new Config($this->consoleArgv);
52 $console->setArgument(0, 'config');
53 $console->setArgument(1, 'test');
54 $txt = $this->dumpExecute($console);
55 $this->assertEquals("config.test => \n", $txt);
58 function testSetArrayValue() {
59 $testArray = [1, 2, 3];
60 $this->mockConfigGet('config', 'test', $testArray, 1);
62 $console = new Config($this->consoleArgv);
63 $console->setArgument(0, 'config');
64 $console->setArgument(1, 'test');
65 $console->setArgument(2, 'now');
66 $txt = $this->dumpExecute($console);
68 $this->assertEquals("[Error] config.test is an array and can't be set using this command.\n", $txt);
71 function testTooManyArguments() {
72 $console = new Config($this->consoleArgv);
73 $console->setArgument(0, 'config');
74 $console->setArgument(1, 'test');
75 $console->setArgument(2, 'it');
76 $console->setArgument(3, 'now');
77 $txt = $this->dumpExecute($console);
78 $assertion = '[Warning] Too many arguments';
79 $firstline = substr($txt, 0, strlen($assertion));
80 $this->assertEquals($assertion, $firstline);
83 function testVerbose() {
84 $this->mockConfigGet('test', 'it', 'now', 1);
85 $console = new Config($this->consoleArgv);
86 $console->setArgument(0, 'test');
87 $console->setArgument(1, 'it');
88 $console->setOption('v', 1);
89 $executable = $this->consoleArgv[0];
91 Executable: {$executable}
92 Class: Friendica\Core\Console\Config
103 $txt = $this->dumpExecute($console);
104 $this->assertEquals($assertion, $txt);
107 function testUnableToSet() {
108 $this->mockConfigSet('test', 'it', 'now', 1, false);
109 $console = new Config();
110 $console->setArgument(0, 'test');
111 $console->setArgument(1, 'it');
112 $console->setArgument(2, 'now');
113 $txt = $this->dumpExecute($console);
114 $this->assertSame("Unable to set test.it\n", $txt);
117 public function testGetHelp()
119 // Usable to purposely fail if new commands are added without taking tests into account
121 console config - Manage site configuration
123 bin/console config [-h|--help|-?] [-v]
124 bin/console config <category> [-h|--help|-?] [-v]
125 bin/console config <category> <key> [-h|--help|-?] [-v]
126 bin/console config <category> <key> <value> [-h|--help|-?] [-v]
130 Lists all config values
132 bin/console config <category>
133 Lists all config values in the provided category
135 bin/console config <category> <key>
136 Shows the value of the provided key in the category
138 bin/console config <category> <key> <value>
139 Sets the value of the provided key in the category
142 Setting config entries which are manually set in config/local.config.php may result in
143 conflict between database settings and the manual startup settings.
146 -h|--help|-? Show help information
147 -v Show more debug information.
150 $console = new Config($this->consoleArgv);
151 $console->setOption('help', true);
153 $txt = $this->dumpExecute($console);
155 $this->assertEquals($txt, $theHelp);