From: Philipp Holzer Date: Wed, 31 Oct 2018 09:24:07 +0000 (+0100) Subject: Moved Mocking usage X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=70e240691e56a0b84e069658378b4d6593064632;p=friendica.git Moved Mocking usage Adding more documentation --- diff --git a/tests/Util/AppMockTrait.php b/tests/Util/AppMockTrait.php index c04b5d7dc5..cdd5aedd5d 100644 --- a/tests/Util/AppMockTrait.php +++ b/tests/Util/AppMockTrait.php @@ -5,6 +5,7 @@ namespace Friendica\Test\Util; use Friendica\App; use Friendica\BaseObject; use Friendica\Render\FriendicaSmartyEngine; +use Mockery\MockInterface; use org\bovigo\vfs\vfsStreamDirectory; /** @@ -13,10 +14,9 @@ use org\bovigo\vfs\vfsStreamDirectory; trait AppMockTrait { use ConfigMockTrait; - use DBAMockTrait; /** - * @var App The Friendica global App Mock + * @var MockInterface|App The mocked Friendica\App */ protected $app; @@ -35,7 +35,7 @@ trait AppMockTrait $this->mockConfigGet('system', 'theme', 'testtheme'); // Mocking App and most used functions - $this->app = \Mockery::mock('Friendica\App'); + $this->app = \Mockery::mock(App::class); $this->app ->shouldReceive('getBasePath') ->andReturn($root->url()); diff --git a/tests/Util/ConfigMockTrait.php b/tests/Util/ConfigMockTrait.php index 8e285f3922..d2867a589e 100644 --- a/tests/Util/ConfigMockTrait.php +++ b/tests/Util/ConfigMockTrait.php @@ -2,11 +2,16 @@ namespace Friendica\Test\Util; +use Mockery\MockInterface; + /** * Trait to Mock Config settings */ trait ConfigMockTrait { + /** + * @var MockInterface The mocking interface of Friendica\Core\Config + */ private $configMock; /** diff --git a/tests/Util/DBAMockTrait.php b/tests/Util/DBAMockTrait.php index 77746f7d9e..a076ac23d0 100644 --- a/tests/Util/DBAMockTrait.php +++ b/tests/Util/DBAMockTrait.php @@ -2,13 +2,24 @@ namespace Friendica\Test\Util; +use Mockery\MockInterface; + /** * Trait to mock the DBA connection status */ trait DBAMockTrait { + /** + * @var MockInterface The mocking interface of Friendica\Database\DBA + */ private $dbaMock; + /** + * Mocking DBA::connect() + * + * @param bool $return True, if the connect was successful, otherwise false + * @param null|int $times How often the method will get used + */ public function mockConnect($return = true, $times = null) { if (!isset($this->dbaMock)) { @@ -21,6 +32,12 @@ trait DBAMockTrait ->andReturn($return); } + /** + * Mocking DBA::connected() + * + * @param bool $return True, if the DB is connected, otherwise false + * @param null|int $times How often the method will get used + */ public function mockConnected($return = true, $times = null) { if (!isset($this->dbaMock)) { diff --git a/tests/Util/DBStructureMockTrait.php b/tests/Util/DBStructureMockTrait.php index 3298107eb3..87c120d3f2 100644 --- a/tests/Util/DBStructureMockTrait.php +++ b/tests/Util/DBStructureMockTrait.php @@ -2,13 +2,25 @@ namespace Friendica\Test\Util; +use Mockery\MockInterface; + /** * Trait to mock the DBStructure connection status */ trait DBStructureMockTrait { + /** + * @var MockInterface The mocking interface of Friendica\Database\DBStructure + */ private $dbStructure; + /** + * Mocking DBStructure::update() + * + * @param array $args The arguments for the update call + * @param bool $return True, if the connect was successful, otherwise false + * @param null|int $times How often the method will get used + */ public function mockUpdate($args = [], $return = true, $times = null) { if (!isset($this->dbStructure)) { @@ -22,6 +34,13 @@ trait DBStructureMockTrait ->andReturn($return); } + /** + * Mocking DBStructure::existsTable() + * + * @param string $tableName The name of the table to check + * @param bool $return True, if the connect was successful, otherwise false + * @param null|int $times How often the method will get used + */ public function mockExistsTable($tableName, $return = true, $times = null) { if (!isset($this->dbStructure)) { diff --git a/tests/Util/VFSTrait.php b/tests/Util/VFSTrait.php index d51ba5b6a5..34763b1385 100644 --- a/tests/Util/VFSTrait.php +++ b/tests/Util/VFSTrait.php @@ -13,6 +13,9 @@ trait VFSTrait */ protected $root; + /** + * Sets up the Virtual File System for Friendica with common files (config, dbstructure) + */ protected function setUpVfsDir() { // the used directories inside the App class $structure = [ @@ -29,6 +32,11 @@ trait VFSTrait $this->setConfigFile('dbstructure.php'); } + /** + * Copying a config file from the file system to the Virtual File System + * + * @param string $filename The filename of the config file + */ protected function setConfigFile($filename) { $file = dirname(__DIR__) . DIRECTORY_SEPARATOR . @@ -43,6 +51,11 @@ trait VFSTrait } } + /** + * Delets a config file from the Virtual File System + * + * @param string $filename The filename of the config file + */ protected function delConfigFile($filename) { if ($this->root->hasChild('config/' . $filename)) { diff --git a/tests/src/Core/Console/AutomaticInstallationConsoleTest.php b/tests/src/Core/Console/AutomaticInstallationConsoleTest.php index 78f4e14e91..1c371f9ba0 100644 --- a/tests/src/Core/Console/AutomaticInstallationConsoleTest.php +++ b/tests/src/Core/Console/AutomaticInstallationConsoleTest.php @@ -3,6 +3,7 @@ namespace Friendica\Test\src\Core\Console; use Friendica\Core\Console\AutomaticInstallation; +use Friendica\Test\Util\DBAMockTrait; use Friendica\Test\Util\DBStructureMockTrait; use org\bovigo\vfs\vfsStream; @@ -13,6 +14,7 @@ use org\bovigo\vfs\vfsStream; */ class AutomaticInstallationConsoleTest extends ConsoleTest { + use DBAMockTrait; use DBStructureMockTrait; private $db_host; @@ -251,9 +253,9 @@ CONF; $console = new AutomaticInstallation(); - $returnStr = $this->dumpExecute($console); + $txt = $this->dumpExecute($console); - $this->assertFinished($returnStr, true); + $this->assertFinished($txt, true); $this->assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.ini.php')); @@ -290,9 +292,9 @@ CONF; $console->setOption('urlpath', '/friendica'); - $returnStr = $this->dumpExecute($console); + $txt = $this->dumpExecute($console); - $this->assertFinished($returnStr, true); + $this->assertFinished($txt, true); $this->assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.ini.php')); @@ -311,9 +313,9 @@ CONF; $console = new AutomaticInstallation(); - $returnStr = $this->dumpExecute($console); + $txt = $this->dumpExecute($console); - $this->assertStuckDB($returnStr); + $this->assertStuckDB($txt); } public function testGetHelp()