]> git.mxchange.org Git - friendica.git/blobdiff - tests/src/Console/ConfigConsoleTest.php
Merge pull request #9680 from annando/issue-9402
[friendica.git] / tests / src / Console / ConfigConsoleTest.php
index e4206af4144302b20bd5dca0d55e0bc2b256343e..51bf04d59a5cf8838f00a82e624b900ea151cd96 100644 (file)
@@ -1,11 +1,32 @@
 <?php
+/**
+ * @copyright Copyright (C) 2020, Friendica
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ *
+ */
 
 namespace Friendica\Test\src\Console;
 
 use Friendica\App;
 use Friendica\App\Mode;
 use Friendica\Console\Config;
-use Friendica\Core\Config\Configuration;
+use Friendica\Core\Config\IConfig;
+use Mockery;
+use Mockery\LegacyMockInterface;
 use Mockery\MockInterface;
 
 class ConfigConsoleTest extends ConsoleTest
@@ -14,25 +35,27 @@ class ConfigConsoleTest extends ConsoleTest
         * @var App\Mode|MockInterface $appMode
         */
        private $appMode;
+       /** @var IConfig|LegacyMockInterface|MockInterface */
+       private $configMock;
 
        protected function setUp()
        {
                parent::setUp();
 
-               \Mockery::getConfiguration()->setConstantsMap([
+               Mockery::getConfiguration()->setConstantsMap([
                        Mode::class => [
-                               'DBCONFIGAVAILABLE' => 0
-                       ]
+                               'DBCONFIGAVAILABLE' => 0,
+                       ],
                ]);
 
-               $this->appMode = \Mockery::mock(App\Mode::class);
+               $this->appMode = Mockery::mock(App\Mode::class);
                $this->appMode->shouldReceive('has')
-                       ->andReturn(true);
+                                         ->andReturn(true);
 
-               $this->configMock = \Mockery::mock(Configuration::class);
+               $this->configMock = Mockery::mock(IConfig::class);
        }
 
-       function testSetGetKeyValue()
+       public function testSetGetKeyValue()
        {
                $this->configMock
                        ->shouldReceive('set')
@@ -50,7 +73,7 @@ class ConfigConsoleTest extends ConsoleTest
                $console->setArgument(1, 'test');
                $console->setArgument(2, 'now');
                $txt = $this->dumpExecute($console);
-               $this->assertEquals("config.test <= now\n", $txt);
+               self::assertEquals("config.test <= now\n", $txt);
 
                $this->configMock
                        ->shouldReceive('get')
@@ -62,7 +85,7 @@ class ConfigConsoleTest extends ConsoleTest
                $console->setArgument(0, 'config');
                $console->setArgument(1, 'test');
                $txt = $this->dumpExecute($console);
-               $this->assertEquals("config.test => now\n", $txt);
+               self::assertEquals("config.test => now\n", $txt);
 
                $this->configMock
                        ->shouldReceive('get')
@@ -74,10 +97,11 @@ class ConfigConsoleTest extends ConsoleTest
                $console->setArgument(0, 'config');
                $console->setArgument(1, 'test');
                $txt = $this->dumpExecute($console);
-               $this->assertEquals("config.test => \n", $txt);
+               self::assertEquals("config.test => \n", $txt);
        }
 
-       function testSetArrayValue() {
+       public function testSetArrayValue()
+       {
                $testArray = [1, 2, 3];
                $this->configMock
                        ->shouldReceive('get')
@@ -91,22 +115,24 @@ class ConfigConsoleTest extends ConsoleTest
                $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);
+               self::assertEquals("[Error] config.test is an array and can't be set using this command.\n", $txt);
        }
 
-       function testTooManyArguments() {
+       public function testTooManyArguments()
+       {
                $console = new Config($this->appMode, $this->configMock, $this->consoleArgv);
                $console->setArgument(0, 'config');
                $console->setArgument(1, 'test');
                $console->setArgument(2, 'it');
                $console->setArgument(3, 'now');
-               $txt = $this->dumpExecute($console);
+               $txt       = $this->dumpExecute($console);
                $assertion = '[Warning] Too many arguments';
                $firstline = substr($txt, 0, strlen($assertion));
-               $this->assertEquals($assertion, $firstline);
+               self::assertEquals($assertion, $firstline);
        }
 
-       function testVerbose() {
+       public function testVerbose()
+       {
                $this->configMock
                        ->shouldReceive('get')
                        ->with('test', 'it')
@@ -117,7 +143,7 @@ class ConfigConsoleTest extends ConsoleTest
                $console->setArgument(1, 'it');
                $console->setOption('v', 1);
                $executable = $this->consoleArgv[0];
-               $assertion = <<<CONF
+               $assertion  = <<<CONF
 Executable: {$executable}
 Class: Friendica\Console\Config
 Arguments: array (
@@ -130,11 +156,12 @@ Options: array (
 test.it => now
 
 CONF;
-               $txt = $this->dumpExecute($console);
-               $this->assertEquals($assertion, $txt);
+               $txt        = $this->dumpExecute($console);
+               self::assertEquals($assertion, $txt);
        }
 
-       function testUnableToSet() {
+       public function testUnableToSet()
+       {
                $this->configMock
                        ->shouldReceive('set')
                        ->with('test', 'it', 'now')
@@ -143,14 +170,14 @@ CONF;
                $this->configMock
                        ->shouldReceive('get')
                        ->with('test', 'it')
-                       ->andReturn(NULL)
+                       ->andReturn(null)
                        ->once();
                $console = new Config($this->appMode, $this->configMock, [$this->consoleArgv]);
                $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);
+               self::assertSame("Unable to set test.it\n", $txt);
        }
 
        public function testGetHelp()
@@ -191,6 +218,6 @@ HELP;
 
                $txt = $this->dumpExecute($console);
 
-               $this->assertEquals($txt, $theHelp);
+               self::assertEquals($txt, $theHelp);
        }
 }