2018-08-17 21:41:46 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Friendica\Test\src\Core\Console;
|
|
|
|
|
2018-10-31 10:16:15 +01:00
|
|
|
use Friendica\Core\Console\Config;
|
2018-08-17 21:41:46 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @runTestsInSeparateProcesses
|
|
|
|
* @preserveGlobalState disabled
|
|
|
|
* @requires PHP 7.0
|
|
|
|
*/
|
|
|
|
class ConfigConsoleTest extends ConsoleTest
|
|
|
|
{
|
2018-10-31 10:16:15 +01:00
|
|
|
protected function setUp()
|
2018-08-17 21:41:46 +02:00
|
|
|
{
|
2018-10-31 10:16:15 +01:00
|
|
|
parent::setUp();
|
2018-08-17 21:41:46 +02:00
|
|
|
|
2018-10-31 10:19:33 +01:00
|
|
|
\Mockery::getConfiguration()->setConstantsMap([
|
2018-10-31 10:16:15 +01:00
|
|
|
'Friendica\App\Mode' => [
|
|
|
|
'DBCONFIGAVAILABLE' => 0
|
|
|
|
]
|
|
|
|
]);
|
2018-08-17 21:41:46 +02:00
|
|
|
|
2018-10-31 10:19:33 +01:00
|
|
|
$mode = \Mockery::mock('alias:Friendica\App\Mode');
|
2018-10-31 10:16:15 +01:00
|
|
|
$mode
|
|
|
|
->shouldReceive('has')
|
|
|
|
->andReturn(true);
|
2018-08-17 21:41:46 +02:00
|
|
|
|
2018-10-31 10:16:15 +01:00
|
|
|
$this->app
|
|
|
|
->shouldReceive('getMode')
|
|
|
|
->andReturn($mode);
|
2018-08-17 21:41:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function testSetGetKeyValue() {
|
2018-10-31 10:16:15 +01:00
|
|
|
$this->mockConfigSet('config', 'test', 'now', 1);
|
2018-10-31 11:57:51 +01:00
|
|
|
$console = new Config($this->consoleArgv);
|
2018-10-31 10:16:15 +01:00
|
|
|
$console->setArgument(0, 'config');
|
|
|
|
$console->setArgument(1, 'test');
|
|
|
|
$console->setArgument(2, 'now');
|
|
|
|
$txt = $this->dumpExecute($console);
|
|
|
|
$this->assertEquals("config.test <= now\n", $txt);
|
|
|
|
|
|
|
|
$this->mockConfigGet('config', 'test', 'now', 1);
|
2018-10-31 11:57:51 +01:00
|
|
|
$console = new Config($this->consoleArgv);
|
2018-10-31 10:16:15 +01:00
|
|
|
$console->setArgument(0, 'config');
|
|
|
|
$console->setArgument(1, 'test');
|
|
|
|
$txt = $this->dumpExecute($console);
|
|
|
|
$this->assertEquals("config.test => now\n", $txt);
|
|
|
|
|
|
|
|
$this->mockConfigGet('config', 'test', null, 1);
|
2018-10-31 11:57:51 +01:00
|
|
|
$console = new Config($this->consoleArgv);
|
2018-10-31 10:16:15 +01:00
|
|
|
$console->setArgument(0, 'config');
|
|
|
|
$console->setArgument(1, 'test');
|
|
|
|
$txt = $this->dumpExecute($console);
|
|
|
|
$this->assertEquals("config.test => \n", $txt);
|
2018-08-17 21:41:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function testSetArrayValue() {
|
|
|
|
$testArray = [1, 2, 3];
|
2018-10-31 10:16:15 +01:00
|
|
|
$this->mockConfigGet('config', 'test', $testArray, 1);
|
2018-08-17 21:41:46 +02:00
|
|
|
|
2018-10-31 11:57:51 +01:00
|
|
|
$console = new Config($this->consoleArgv);
|
2018-10-31 10:16:15 +01:00
|
|
|
$console->setArgument(0, 'config');
|
|
|
|
$console->setArgument(1, 'test');
|
|
|
|
$console->setArgument(2, 'now');
|
|
|
|
$txt = $this->dumpExecute($console);
|
2018-08-17 21:41:46 +02:00
|
|
|
|
|
|
|
$this->assertEquals("[Error] config.test is an array and can't be set using this command.\n", $txt);
|
|
|
|
}
|
|
|
|
|
|
|
|
function testTooManyArguments() {
|
2018-10-31 11:57:51 +01:00
|
|
|
$console = new Config($this->consoleArgv);
|
2018-10-31 10:16:15 +01:00
|
|
|
$console->setArgument(0, 'config');
|
|
|
|
$console->setArgument(1, 'test');
|
|
|
|
$console->setArgument(2, 'it');
|
|
|
|
$console->setArgument(3, 'now');
|
|
|
|
$txt = $this->dumpExecute($console);
|
2018-08-17 21:41:46 +02:00
|
|
|
$assertion = '[Warning] Too many arguments';
|
|
|
|
$firstline = substr($txt, 0, strlen($assertion));
|
|
|
|
$this->assertEquals($assertion, $firstline);
|
|
|
|
}
|
|
|
|
|
|
|
|
function testVerbose() {
|
2018-10-31 10:16:15 +01:00
|
|
|
$this->mockConfigGet('test', 'it', 'now', 1);
|
2018-10-31 11:57:51 +01:00
|
|
|
$console = new Config($this->consoleArgv);
|
2018-10-31 10:16:15 +01:00
|
|
|
$console->setArgument(0, 'test');
|
|
|
|
$console->setArgument(1, 'it');
|
|
|
|
$console->setOption('v', 1);
|
2018-10-31 11:57:51 +01:00
|
|
|
$executable = $this->consoleArgv[0];
|
2018-08-17 21:41:46 +02:00
|
|
|
$assertion = <<<CONF
|
2018-10-31 11:57:51 +01:00
|
|
|
Executable: {$executable}
|
2018-08-17 21:41:46 +02:00
|
|
|
Class: Friendica\Core\Console\Config
|
|
|
|
Arguments: array (
|
|
|
|
0 => 'test',
|
2018-10-31 10:16:15 +01:00
|
|
|
1 => 'it',
|
2018-08-17 21:41:46 +02:00
|
|
|
)
|
|
|
|
Options: array (
|
|
|
|
'v' => 1,
|
|
|
|
)
|
2018-10-31 10:16:15 +01:00
|
|
|
test.it => now
|
2018-08-17 21:41:46 +02:00
|
|
|
|
|
|
|
CONF;
|
2018-10-31 10:16:15 +01:00
|
|
|
$txt = $this->dumpExecute($console);
|
2018-08-17 21:41:46 +02:00
|
|
|
$this->assertEquals($assertion, $txt);
|
|
|
|
}
|
2018-10-31 10:16:15 +01:00
|
|
|
|
|
|
|
function testUnableToSet() {
|
|
|
|
$this->mockConfigSet('test', 'it', 'now', 1, false);
|
|
|
|
$console = new Config();
|
|
|
|
$console->setArgument(0, 'test');
|
|
|
|
$console->setArgument(1, 'it');
|
|
|
|
$console->setArgument(2, 'now');
|
|
|
|
$txt = $this->dumpExecute($console);
|
|
|
|
$this->assertSame("Unable to set test.it\n", $txt);
|
|
|
|
}
|
2018-10-31 11:57:51 +01:00
|
|
|
|
|
|
|
public function testGetHelp()
|
|
|
|
{
|
|
|
|
// Usable to purposely fail if new commands are added without taking tests into account
|
|
|
|
$theHelp = <<<HELP
|
|
|
|
console config - Manage site configuration
|
|
|
|
Synopsis
|
|
|
|
bin/console config [-h|--help|-?] [-v]
|
|
|
|
bin/console config <category> [-h|--help|-?] [-v]
|
|
|
|
bin/console config <category> <key> [-h|--help|-?] [-v]
|
|
|
|
bin/console config <category> <key> <value> [-h|--help|-?] [-v]
|
|
|
|
|
|
|
|
Description
|
|
|
|
bin/console config
|
|
|
|
Lists all config values
|
|
|
|
|
|
|
|
bin/console config <category>
|
|
|
|
Lists all config values in the provided category
|
|
|
|
|
|
|
|
bin/console config <category> <key>
|
|
|
|
Shows the value of the provided key in the category
|
|
|
|
|
|
|
|
bin/console config <category> <key> <value>
|
|
|
|
Sets the value of the provided key in the category
|
|
|
|
|
|
|
|
Notes:
|
2018-11-25 07:44:51 +01:00
|
|
|
Setting config entries which are manually set in config/local.config.php may result in
|
2018-10-31 11:57:51 +01:00
|
|
|
conflict between database settings and the manual startup settings.
|
|
|
|
|
|
|
|
Options
|
|
|
|
-h|--help|-? Show help information
|
|
|
|
-v Show more debug information.
|
|
|
|
|
|
|
|
HELP;
|
|
|
|
$console = new Config($this->consoleArgv);
|
|
|
|
$console->setOption('help', true);
|
|
|
|
|
|
|
|
$txt = $this->dumpExecute($console);
|
|
|
|
|
|
|
|
$this->assertEquals($txt, $theHelp);
|
|
|
|
}
|
2018-08-17 21:41:46 +02:00
|
|
|
}
|