Bugfixing & Enhancement
- Added Mocking Engine for App, DBA, Config - Using Mocking Engine for AutomaticInstallationConsoleTest - Using Mocking Engine for ConfigConsoleTest - Removing MultiUserConsole - Workaround
This commit is contained in:
parent
f7147fae96
commit
0e22c18a9d
10 changed files with 515 additions and 175 deletions
90
tests/Util/AppMockTrait.php
Normal file
90
tests/Util/AppMockTrait.php
Normal file
|
@ -0,0 +1,90 @@
|
|||
<?php
|
||||
|
||||
namespace Friendica\Test\Util;
|
||||
|
||||
use Friendica\App;
|
||||
use Friendica\BaseObject;
|
||||
use Friendica\Render\FriendicaSmartyEngine;
|
||||
use org\bovigo\vfs\vfsStreamDirectory;
|
||||
|
||||
/**
|
||||
* Trait to Mock the global App instance
|
||||
*/
|
||||
trait AppMockTrait
|
||||
{
|
||||
use ConfigMockTrait;
|
||||
use DBAMockTrait;
|
||||
|
||||
/**
|
||||
* @var App The Friendica global App Mock
|
||||
*/
|
||||
protected $app;
|
||||
|
||||
/**
|
||||
* Mock the App
|
||||
*
|
||||
* @param vfsStreamDirectory $root The root directory
|
||||
*/
|
||||
public function mockApp($root)
|
||||
{
|
||||
/// @todo This mock is ugly. We return an empty string for each translation - no workaround yet
|
||||
$l10nMock = \Mockery::mock('alias:Friendica\Core\L10n');
|
||||
$l10nMock->shouldReceive('t')
|
||||
->andReturn('');
|
||||
|
||||
$this->mockConfigGet('system', 'theme', 'testtheme');
|
||||
|
||||
// Mocking App and most used functions
|
||||
$this->app = \Mockery::mock('Friendica\App');
|
||||
$this->app
|
||||
->shouldReceive('getBasePath')
|
||||
->andReturn($root->url());
|
||||
|
||||
$this->app
|
||||
->shouldReceive('getConfigValue')
|
||||
->with('database', 'hostname')
|
||||
->andReturn(getenv('MYSQL_HOST'));
|
||||
$this->app
|
||||
->shouldReceive('getConfigValue')
|
||||
->with('database', 'username')
|
||||
->andReturn(getenv('MYSQL_USERNAME'));
|
||||
$this->app
|
||||
->shouldReceive('getConfigValue')
|
||||
->with('database', 'password')
|
||||
->andReturn(getenv('MYSQL_PASSWORD'));
|
||||
$this->app
|
||||
->shouldReceive('getConfigValue')
|
||||
->with('database', 'database')
|
||||
->andReturn(getenv('MYSQL_DATABASE'));
|
||||
$this->app
|
||||
->shouldReceive('getTemplateEngine')
|
||||
->andReturn(new FriendicaSmartyEngine());
|
||||
$this->app
|
||||
->shouldReceive('getCurrentTheme')
|
||||
->andReturn('Smarty3');
|
||||
$this->app
|
||||
->shouldReceive('getTemplateLeftDelimiter')
|
||||
->with('smarty3')
|
||||
->andReturn('{{');
|
||||
$this->app
|
||||
->shouldReceive('getTemplateRightDelimiter')
|
||||
->with('smarty3')
|
||||
->andReturn('}}');
|
||||
$this->app
|
||||
->shouldReceive('saveTimestamp')
|
||||
->andReturn(true);
|
||||
$this->app
|
||||
->shouldReceive('getBaseUrl')
|
||||
->andReturn('http://friendica.local');
|
||||
|
||||
// Mocking the Theme
|
||||
// Necessary for macro engine with template files
|
||||
$themeMock = \Mockery::mock('alias:Friendica\Core\Theme');
|
||||
$themeMock
|
||||
->shouldReceive('install')
|
||||
->with('testtheme')
|
||||
->andReturn(true);
|
||||
|
||||
BaseObject::setApp($this->app);
|
||||
}
|
||||
}
|
59
tests/Util/ConfigMockTrait.php
Normal file
59
tests/Util/ConfigMockTrait.php
Normal file
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
|
||||
namespace Friendica\Test\Util;
|
||||
|
||||
/**
|
||||
* Trait to Mock Config settings
|
||||
*/
|
||||
trait ConfigMockTrait
|
||||
{
|
||||
private $configMock;
|
||||
|
||||
/**
|
||||
* Mocking a config setting
|
||||
*
|
||||
* @param string $family The family of the config double
|
||||
* @param string $key The key of the config double
|
||||
* @param mixed $value The value of the config double
|
||||
* @param null|int $times How often the Config will get used
|
||||
*/
|
||||
public function mockConfigGet($family, $key, $value, $times = null)
|
||||
{
|
||||
if (!isset($this->configMock)) {
|
||||
$this->configMock = \Mockery::mock('alias:Friendica\Core\Config');
|
||||
}
|
||||
|
||||
$this->configMock
|
||||
->shouldReceive('get')
|
||||
->times($times)
|
||||
->with($family, $key)
|
||||
->andReturn($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Mocking setting a new config entry
|
||||
*
|
||||
* @param string $family The family of the config double
|
||||
* @param string $key The key of the config double
|
||||
* @param mixed $value The value of the config double
|
||||
* @param null|int $times How often the Config will get used
|
||||
* @param bool $return Return value of the set (default is true)
|
||||
*/
|
||||
public function mockConfigSet($family, $key, $value, $times = null, $return = true)
|
||||
{
|
||||
if (!isset($this->configMock)) {
|
||||
$this->configMock = \Mockery::mock('alias:Friendica\Core\Config');
|
||||
}
|
||||
|
||||
$this->mockConfigGet($family, $key, false, 1);
|
||||
if ($return) {
|
||||
$this->mockConfigGet($family, $key, $value, 1);
|
||||
}
|
||||
|
||||
$this->configMock
|
||||
->shouldReceive('set')
|
||||
->times($times)
|
||||
->with($family, $key, $value)
|
||||
->andReturn($return);
|
||||
}
|
||||
}
|
35
tests/Util/DBAMockTrait.php
Normal file
35
tests/Util/DBAMockTrait.php
Normal file
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace Friendica\Test\Util;
|
||||
|
||||
/**
|
||||
* Trait to mock the DBA connection status
|
||||
*/
|
||||
trait DBAMockTrait
|
||||
{
|
||||
private $dbaMock;
|
||||
|
||||
public function mockConnect($return = true, $times = null)
|
||||
{
|
||||
if (!isset($this->dbaMock)) {
|
||||
$this->dbaMock = \Mockery::mock('alias:Friendica\Database\DBA');
|
||||
}
|
||||
|
||||
$this->dbaMock
|
||||
->shouldReceive('connect')
|
||||
->times($times)
|
||||
->andReturn($return);
|
||||
}
|
||||
|
||||
public function mockConnected($return = true, $times = null)
|
||||
{
|
||||
if (!isset($this->dbaMock)) {
|
||||
$this->dbaMock = \Mockery::mock('alias:Friendica\Database\DBA');
|
||||
}
|
||||
|
||||
$this->dbaMock
|
||||
->shouldReceive('connected')
|
||||
->times($times)
|
||||
->andReturn($return);
|
||||
}
|
||||
}
|
37
tests/Util/DBStructureMockTrait.php
Normal file
37
tests/Util/DBStructureMockTrait.php
Normal file
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
namespace Friendica\Test\Util;
|
||||
|
||||
/**
|
||||
* Trait to mock the DBStructure connection status
|
||||
*/
|
||||
trait DBStructureMockTrait
|
||||
{
|
||||
private $dbStructure;
|
||||
|
||||
public function mockUpdate($args = [], $return = true, $times = null)
|
||||
{
|
||||
if (!isset($this->dbStructure)) {
|
||||
$this->dbStructure = \Mockery::mock('alias:Friendica\Database\DBStructure');
|
||||
}
|
||||
|
||||
$this->dbStructure
|
||||
->shouldReceive('update')
|
||||
->withArgs($args)
|
||||
->times($times)
|
||||
->andReturn($return);
|
||||
}
|
||||
|
||||
public function mockExistsTable($tableName, $return = true, $times = null)
|
||||
{
|
||||
if (!isset($this->dbStructure)) {
|
||||
$this->dbStructure = \Mockery::mock('alias:Friendica\Database\DBStructure');
|
||||
}
|
||||
|
||||
$this->dbStructure
|
||||
->shouldReceive('existsTable')
|
||||
->with($tableName)
|
||||
->times($times)
|
||||
->andReturn($return);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue