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 \Mockery::getConfiguration()->setConstantsMap([
21 'DBCONFIGAVAILABLE' => 0
25 $mode = \Mockery::mock(Mode::class);
27 ->shouldReceive('has')
31 ->shouldReceive('getMode')
35 function testSetGetKeyValue() {
37 ->shouldReceive('set')
38 ->with('config', 'test', 'now')
42 ->shouldReceive('get')
43 ->with('config', 'test')
47 $console = new Config($this->consoleArgv);
48 $console->setArgument(0, 'config');
49 $console->setArgument(1, 'test');
50 $console->setArgument(2, 'now');
51 $txt = $this->dumpExecute($console);
52 $this->assertEquals("config.test <= now\n", $txt);
55 ->shouldReceive('get')
56 ->with('config', 'test')
60 $console = new Config($this->consoleArgv);
61 $console->setArgument(0, 'config');
62 $console->setArgument(1, 'test');
63 $txt = $this->dumpExecute($console);
64 $this->assertEquals("config.test => now\n", $txt);
67 ->shouldReceive('get')
68 ->with('config', 'test')
72 $console = new Config($this->consoleArgv);
73 $console->setArgument(0, 'config');
74 $console->setArgument(1, 'test');
75 $txt = $this->dumpExecute($console);
76 $this->assertEquals("config.test => \n", $txt);
79 function testSetArrayValue() {
80 $testArray = [1, 2, 3];
82 ->shouldReceive('get')
83 ->with('config', 'test')
84 ->andReturn($testArray)
87 $console = new Config($this->consoleArgv);
88 $console->setArgument(0, 'config');
89 $console->setArgument(1, 'test');
90 $console->setArgument(2, 'now');
91 $txt = $this->dumpExecute($console);
93 $this->assertEquals("[Error] config.test is an array and can't be set using this command.\n", $txt);
96 function testTooManyArguments() {
97 $console = new Config($this->consoleArgv);
98 $console->setArgument(0, 'config');
99 $console->setArgument(1, 'test');
100 $console->setArgument(2, 'it');
101 $console->setArgument(3, 'now');
102 $txt = $this->dumpExecute($console);
103 $assertion = '[Warning] Too many arguments';
104 $firstline = substr($txt, 0, strlen($assertion));
105 $this->assertEquals($assertion, $firstline);
108 function testVerbose() {
110 ->shouldReceive('get')
114 $console = new Config($this->consoleArgv);
115 $console->setArgument(0, 'test');
116 $console->setArgument(1, 'it');
117 $console->setOption('v', 1);
118 $executable = $this->consoleArgv[0];
120 Executable: {$executable}
121 Class: Friendica\Core\Console\Config
132 $txt = $this->dumpExecute($console);
133 $this->assertEquals($assertion, $txt);
136 function testUnableToSet() {
138 ->shouldReceive('set')
139 ->with('test', 'it', 'now')
143 ->shouldReceive('get')
147 $console = new Config();
148 $console->setArgument(0, 'test');
149 $console->setArgument(1, 'it');
150 $console->setArgument(2, 'now');
151 $txt = $this->dumpExecute($console);
152 $this->assertSame("Unable to set test.it\n", $txt);
155 public function testGetHelp()
157 // Usable to purposely fail if new commands are added without taking tests into account
159 console config - Manage site configuration
161 bin/console config [-h|--help|-?] [-v]
162 bin/console config <category> [-h|--help|-?] [-v]
163 bin/console config <category> <key> [-h|--help|-?] [-v]
164 bin/console config <category> <key> <value> [-h|--help|-?] [-v]
168 Lists all config values
170 bin/console config <category>
171 Lists all config values in the provided category
173 bin/console config <category> <key>
174 Shows the value of the provided key in the category
176 bin/console config <category> <key> <value>
177 Sets the value of the provided key in the category
180 Setting config entries which are manually set in config/local.config.php may result in
181 conflict between database settings and the manual startup settings.
184 -h|--help|-? Show help information
185 -v Show more debug information.
188 $console = new Config($this->consoleArgv);
189 $console->setOption('help', true);
191 $txt = $this->dumpExecute($console);
193 $this->assertEquals($txt, $theHelp);