X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=tests%2Fsrc%2FCore%2FConsole%2FConfigConsoleTest.php;h=ef50c19b7271a895acf592486522fb990810facf;hb=b06fc578804fdc0073631e7c97eccd25543e769e;hp=c4fd217770f1e7e804d8a8bb532abc2a7819f4f4;hpb=df3b1be3b7437f3a36d6c1b6cf33cd2f0ad07388;p=friendica.git diff --git a/tests/src/Core/Console/ConfigConsoleTest.php b/tests/src/Core/Console/ConfigConsoleTest.php index c4fd217770..ef50c19b72 100644 --- a/tests/src/Core/Console/ConfigConsoleTest.php +++ b/tests/src/Core/Console/ConfigConsoleTest.php @@ -2,7 +2,8 @@ namespace Friendica\Test\src\Core\Console; -use Friendica\Database\DBA; +use Friendica\App\Mode; +use Friendica\Core\Console\Config; /** * @runTestsInSeparateProcesses @@ -11,76 +12,184 @@ use Friendica\Database\DBA; */ class ConfigConsoleTest extends ConsoleTest { - public function tearDown() + protected function setUp() { - DBA::delete('config', ['k' => 'test']); + parent::setUp(); - parent::tearDown(); - } + \Mockery::getConfiguration()->setConstantsMap([ + Mode::class => [ + 'DBCONFIGAVAILABLE' => 0 + ] + ]); - private function assertGet($family, $key, $value) { - $config = $this->execute(['config', $family, $key]); - $this->assertEquals($family . "." . $key . " => " . $value . "\n", $config); - } + $mode = \Mockery::mock(Mode::class); + $mode + ->shouldReceive('has') + ->andReturn(true); - private function assertSet($family, $key, $value) { - $config = $this->execute(['config', $family, $key, $value]); - $this->assertEquals($family . "." . $key . " <= " . $value . "\n", $config); + $this->app + ->shouldReceive('getMode') + ->andReturn($mode); } function testSetGetKeyValue() { - $this->assertSet( 'config', 'test', 'now'); - $this->assertGet('config', 'test', 'now'); - $this->assertSet('config', 'test', ''); - $this->assertGet('config', 'test', ''); - DBA::delete('config', ['k' => 'test']); - $this->assertGet('config', 'test', null); + $this->configMock + ->shouldReceive('set') + ->with('config', 'test', 'now') + ->andReturn(true) + ->once(); + $this->configMock + ->shouldReceive('get') + ->with('config', 'test') + ->andReturn('now') + ->twice(); + + $console = new Config($this->consoleArgv); + $console->setArgument(0, 'config'); + $console->setArgument(1, 'test'); + $console->setArgument(2, 'now'); + $txt = $this->dumpExecute($console); + $this->assertEquals("config.test <= now\n", $txt); + + $this->configMock + ->shouldReceive('get') + ->with('config', 'test') + ->andReturn('now') + ->once(); + + $console = new Config($this->consoleArgv); + $console->setArgument(0, 'config'); + $console->setArgument(1, 'test'); + $txt = $this->dumpExecute($console); + $this->assertEquals("config.test => now\n", $txt); + + $this->configMock + ->shouldReceive('get') + ->with('config', 'test') + ->andReturn(null) + ->once(); + + $console = new Config($this->consoleArgv); + $console->setArgument(0, 'config'); + $console->setArgument(1, 'test'); + $txt = $this->dumpExecute($console); + $this->assertEquals("config.test => \n", $txt); } function testSetArrayValue() { $testArray = [1, 2, 3]; - DBA::insert('config', ['cat' => 'config', 'k' => 'test', 'v' => serialize($testArray)]); + $this->configMock + ->shouldReceive('get') + ->with('config', 'test') + ->andReturn($testArray) + ->once(); - $txt = $this->execute(['config', 'config', 'test', 'now']); + $console = new Config($this->consoleArgv); + $console->setArgument(0, 'config'); + $console->setArgument(1, 'test'); + $console->setArgument(2, 'now'); + $txt = $this->dumpExecute($console); $this->assertEquals("[Error] config.test is an array and can't be set using this command.\n", $txt); } function testTooManyArguments() { - $txt = $this->execute(['config', 'config', 'test', 'it', 'now']); + $console = new Config($this->consoleArgv); + $console->setArgument(0, 'config'); + $console->setArgument(1, 'test'); + $console->setArgument(2, 'it'); + $console->setArgument(3, 'now'); + $txt = $this->dumpExecute($console); $assertion = '[Warning] Too many arguments'; $firstline = substr($txt, 0, strlen($assertion)); - $this->assertEquals($assertion, $firstline); } function testVerbose() { - $this->assertSet('test', 'it', 'now'); - $executable = $this->getExecutablePath(); + $this->configMock + ->shouldReceive('get') + ->with('test', 'it') + ->andReturn('now') + ->once(); + $console = new Config($this->consoleArgv); + $console->setArgument(0, 'test'); + $console->setArgument(1, 'it'); + $console->setOption('v', 1); + $executable = $this->consoleArgv[0]; $assertion = << 'config', - 1 => 'test', -) -Options: array ( - 'v' => 1, -) -Command: config -Executable: {$executable} Class: Friendica\Core\Console\Config Arguments: array ( 0 => 'test', + 1 => 'it', ) Options: array ( 'v' => 1, ) -[test] -it => now +test.it => now CONF; - $txt = $this->execute(['config', 'test', '-v']); - + $txt = $this->dumpExecute($console); $this->assertEquals($assertion, $txt); } + + function testUnableToSet() { + $this->configMock + ->shouldReceive('set') + ->with('test', 'it', 'now') + ->andReturn(false) + ->once(); + $this->configMock + ->shouldReceive('get') + ->with('test', 'it') + ->andReturn(NULL) + ->once(); + $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); + } + + public function testGetHelp() + { + // Usable to purposely fail if new commands are added without taking tests into account + $theHelp = << [-h|--help|-?] [-v] + bin/console config [-h|--help|-?] [-v] + bin/console config [-h|--help|-?] [-v] + +Description + bin/console config + Lists all config values + + bin/console config + Lists all config values in the provided category + + bin/console config + Shows the value of the provided key in the category + + bin/console config + Sets the value of the provided key in the category + +Notes: + Setting config entries which are manually set in config/local.config.php may result in + 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); + } }