1
1
Fork 0

Refactor ConfigMockTrait to mocked ConfigCache

This commit is contained in:
Philipp Holzer 2019-02-07 20:44:03 +01:00
commit cb791024e4
No known key found for this signature in database
GPG key ID: 517BE60E2CE5C8A5
27 changed files with 244 additions and 193 deletions

View file

@ -4,6 +4,7 @@ namespace Friendica\Test\Util;
use Friendica\App;
use Friendica\BaseObject;
use Friendica\Core\Config;
use Friendica\Core\Config\ConfigCache;
use Friendica\Render\FriendicaSmartyEngine;
use Mockery\MockInterface;
@ -14,13 +15,16 @@ use org\bovigo\vfs\vfsStreamDirectory;
*/
trait AppMockTrait
{
use ConfigMockTrait;
/**
* @var MockInterface|App The mocked Friendica\App
*/
protected $app;
/**
* @var MockInterface|ConfigCache The mocked Config Cache
*/
protected $configCache;
/**
* Mock the App
*
@ -29,8 +33,7 @@ trait AppMockTrait
*/
public function mockApp($root, $config)
{
$this->mockConfigGet('system', 'theme', 'testtheme');
$this->configCache = $config;
// Mocking App and most used functions
$this->app = \Mockery::mock(App::class);
$this->app
@ -53,6 +56,15 @@ trait AppMockTrait
->shouldReceive('get')
->with('database', 'database')
->andReturn(getenv('MYSQL_DATABASE'));
$config
->shouldReceive('get')
->with('config', 'hostname')
->andReturn('localhost');
$config
->shouldReceive('get')
->with('system', 'theme', NULL)
->andReturn('system_theme');
$this->app
->shouldReceive('getConfig')
->andReturn($config);
@ -70,6 +82,14 @@ trait AppMockTrait
->shouldReceive('getBaseUrl')
->andReturn('http://friendica.local');
// Initialize empty Config
Config::init($config);
$configAdapter = \Mockery::mock('Friendica\Core\Config\IConfigAdapter');
$configAdapter
->shouldReceive('isConnected')
->andReturn(false);
Config::setAdapter($configAdapter);
BaseObject::setApp($this->app);
}
}

View file

@ -1,64 +0,0 @@
<?php
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;
/**
* 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);
}
}

View file

@ -1,14 +1,7 @@
<?php
/**
* Created by PhpStorm.
* User: philipp
* Date: 01.11.18
* Time: 10:08
*/
namespace Friendica\Test\Util;
use Mockery\MockInterface;
trait RendererMockTrait