Browse Source

Moved Mocking usage

Adding more documentation
pull/6051/head
Philipp Holzer 4 years ago
parent
commit
70e240691e
No known key found for this signature in database
GPG Key ID: 517BE60E2CE5C8A5
  1. 6
      tests/Util/AppMockTrait.php
  2. 5
      tests/Util/ConfigMockTrait.php
  3. 17
      tests/Util/DBAMockTrait.php
  4. 19
      tests/Util/DBStructureMockTrait.php
  5. 13
      tests/Util/VFSTrait.php
  6. 14
      tests/src/Core/Console/AutomaticInstallationConsoleTest.php

6
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());

5
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;
/**

17
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)) {

19
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)) {

13
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)) {

14
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()

Loading…
Cancel
Save