friendica/tests/Util/ConfigMockTrait.php
Philipp Holzer 0e22c18a9d
Bugfixing & Enhancement
- Added Mocking Engine for App, DBA, Config
- Using Mocking Engine for AutomaticInstallationConsoleTest
- Using Mocking Engine for ConfigConsoleTest

- Removing MultiUserConsole - Workaround
2018-10-31 10:16:15 +01:00

60 lines
1.5 KiB
PHP

<?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);
}
}