Moved Mocking usage

Adding more documentation
This commit is contained in:
Philipp Holzer 2018-10-31 10:24:07 +01:00
parent 551efde226
commit 70e240691e
No known key found for this signature in database
GPG Key ID: 517BE60E2CE5C8A5
6 changed files with 65 additions and 9 deletions

View File

@ -5,6 +5,7 @@ namespace Friendica\Test\Util;
use Friendica\App; use Friendica\App;
use Friendica\BaseObject; use Friendica\BaseObject;
use Friendica\Render\FriendicaSmartyEngine; use Friendica\Render\FriendicaSmartyEngine;
use Mockery\MockInterface;
use org\bovigo\vfs\vfsStreamDirectory; use org\bovigo\vfs\vfsStreamDirectory;
/** /**
@ -13,10 +14,9 @@ use org\bovigo\vfs\vfsStreamDirectory;
trait AppMockTrait trait AppMockTrait
{ {
use ConfigMockTrait; use ConfigMockTrait;
use DBAMockTrait;
/** /**
* @var App The Friendica global App Mock * @var MockInterface|App The mocked Friendica\App
*/ */
protected $app; protected $app;
@ -35,7 +35,7 @@ trait AppMockTrait
$this->mockConfigGet('system', 'theme', 'testtheme'); $this->mockConfigGet('system', 'theme', 'testtheme');
// Mocking App and most used functions // Mocking App and most used functions
$this->app = \Mockery::mock('Friendica\App'); $this->app = \Mockery::mock(App::class);
$this->app $this->app
->shouldReceive('getBasePath') ->shouldReceive('getBasePath')
->andReturn($root->url()); ->andReturn($root->url());

View File

@ -2,11 +2,16 @@
namespace Friendica\Test\Util; namespace Friendica\Test\Util;
use Mockery\MockInterface;
/** /**
* Trait to Mock Config settings * Trait to Mock Config settings
*/ */
trait ConfigMockTrait trait ConfigMockTrait
{ {
/**
* @var MockInterface The mocking interface of Friendica\Core\Config
*/
private $configMock; private $configMock;
/** /**

View File

@ -2,13 +2,24 @@
namespace Friendica\Test\Util; namespace Friendica\Test\Util;
use Mockery\MockInterface;
/** /**
* Trait to mock the DBA connection status * Trait to mock the DBA connection status
*/ */
trait DBAMockTrait trait DBAMockTrait
{ {
/**
* @var MockInterface The mocking interface of Friendica\Database\DBA
*/
private $dbaMock; 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) public function mockConnect($return = true, $times = null)
{ {
if (!isset($this->dbaMock)) { if (!isset($this->dbaMock)) {
@ -21,6 +32,12 @@ trait DBAMockTrait
->andReturn($return); ->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) public function mockConnected($return = true, $times = null)
{ {
if (!isset($this->dbaMock)) { if (!isset($this->dbaMock)) {

View File

@ -2,13 +2,25 @@
namespace Friendica\Test\Util; namespace Friendica\Test\Util;
use Mockery\MockInterface;
/** /**
* Trait to mock the DBStructure connection status * Trait to mock the DBStructure connection status
*/ */
trait DBStructureMockTrait trait DBStructureMockTrait
{ {
/**
* @var MockInterface The mocking interface of Friendica\Database\DBStructure
*/
private $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) public function mockUpdate($args = [], $return = true, $times = null)
{ {
if (!isset($this->dbStructure)) { if (!isset($this->dbStructure)) {
@ -22,6 +34,13 @@ trait DBStructureMockTrait
->andReturn($return); ->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) public function mockExistsTable($tableName, $return = true, $times = null)
{ {
if (!isset($this->dbStructure)) { if (!isset($this->dbStructure)) {

View File

@ -13,6 +13,9 @@ trait VFSTrait
*/ */
protected $root; protected $root;
/**
* Sets up the Virtual File System for Friendica with common files (config, dbstructure)
*/
protected function setUpVfsDir() { protected function setUpVfsDir() {
// the used directories inside the App class // the used directories inside the App class
$structure = [ $structure = [
@ -29,6 +32,11 @@ trait VFSTrait
$this->setConfigFile('dbstructure.php'); $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) protected function setConfigFile($filename)
{ {
$file = dirname(__DIR__) . DIRECTORY_SEPARATOR . $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) protected function delConfigFile($filename)
{ {
if ($this->root->hasChild('config/' . $filename)) { if ($this->root->hasChild('config/' . $filename)) {

View File

@ -3,6 +3,7 @@
namespace Friendica\Test\src\Core\Console; namespace Friendica\Test\src\Core\Console;
use Friendica\Core\Console\AutomaticInstallation; use Friendica\Core\Console\AutomaticInstallation;
use Friendica\Test\Util\DBAMockTrait;
use Friendica\Test\Util\DBStructureMockTrait; use Friendica\Test\Util\DBStructureMockTrait;
use org\bovigo\vfs\vfsStream; use org\bovigo\vfs\vfsStream;
@ -13,6 +14,7 @@ use org\bovigo\vfs\vfsStream;
*/ */
class AutomaticInstallationConsoleTest extends ConsoleTest class AutomaticInstallationConsoleTest extends ConsoleTest
{ {
use DBAMockTrait;
use DBStructureMockTrait; use DBStructureMockTrait;
private $db_host; private $db_host;
@ -251,9 +253,9 @@ CONF;
$console = new AutomaticInstallation(); $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')); $this->assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.ini.php'));
@ -290,9 +292,9 @@ CONF;
$console->setOption('urlpath', '/friendica'); $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')); $this->assertTrue($this->root->hasChild('config' . DIRECTORY_SEPARATOR . 'local.ini.php'));
@ -311,9 +313,9 @@ CONF;
$console = new AutomaticInstallation(); $console = new AutomaticInstallation();
$returnStr = $this->dumpExecute($console); $txt = $this->dumpExecute($console);
$this->assertStuckDB($returnStr); $this->assertStuckDB($txt);
} }
public function testGetHelp() public function testGetHelp()