Refactor ConfigMockTrait to mocked ConfigCache
This commit is contained in:
parent
38ac615ba0
commit
cb791024e4
27 changed files with 244 additions and 193 deletions
|
|
@ -3,24 +3,19 @@
|
|||
namespace Friendica\Test\src\App;
|
||||
|
||||
use Friendica\App\Mode;
|
||||
use Friendica\Core\Config;
|
||||
use Friendica\Test\MockedTest;
|
||||
use Friendica\Test\Util\ConfigMockTrait;
|
||||
use Friendica\Test\Util\DBAMockTrait;
|
||||
use Friendica\Test\Util\VFSTrait;
|
||||
|
||||
/**
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
class ModeTest extends MockedTest
|
||||
{
|
||||
use VFSTrait;
|
||||
use DBAMockTrait;
|
||||
use ConfigMockTrait;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp(); // TODO: Change the autogenerated stub
|
||||
parent::setUp();
|
||||
|
||||
$this->setUpVfsDir();
|
||||
}
|
||||
|
|
@ -50,6 +45,10 @@ class ModeTest extends MockedTest
|
|||
$this->assertFalse($mode->has(Mode::LOCALCONFIGPRESENT));
|
||||
}
|
||||
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
public function testWithoutDatabase()
|
||||
{
|
||||
$this->mockConnected(false, 1);
|
||||
|
|
@ -64,6 +63,10 @@ class ModeTest extends MockedTest
|
|||
$this->assertFalse($mode->has(Mode::DBAVAILABLE));
|
||||
}
|
||||
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
public function testWithoutDatabaseSetup()
|
||||
{
|
||||
$this->mockConnected(true, 1);
|
||||
|
|
@ -78,11 +81,28 @@ class ModeTest extends MockedTest
|
|||
$this->assertTrue($mode->has(Mode::LOCALCONFIGPRESENT));
|
||||
}
|
||||
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
public function testWithMaintenanceMode()
|
||||
{
|
||||
$this->mockConnected(true, 1);
|
||||
$this->mockFetchFirst('SHOW TABLES LIKE \'config\'', true, 1);
|
||||
$this->mockConfigGet('system', 'maintenance', true, 1);
|
||||
|
||||
$config = \Mockery::mock('Friendica\Core\Config\ConfigCache');
|
||||
$config
|
||||
->shouldReceive('get')
|
||||
->with('system', 'maintenance', null)
|
||||
->andReturn(true)
|
||||
->once();
|
||||
// Initialize empty Config
|
||||
Config::init($config);
|
||||
$configAdapter = \Mockery::mock('Friendica\Core\Config\IConfigAdapter');
|
||||
$configAdapter
|
||||
->shouldReceive('isConnected')
|
||||
->andReturn(false);
|
||||
Config::setAdapter($configAdapter);
|
||||
|
||||
$mode = new Mode($this->root->url());
|
||||
$mode->determine();
|
||||
|
|
@ -94,11 +114,28 @@ class ModeTest extends MockedTest
|
|||
$this->assertFalse($mode->has(Mode::MAINTENANCEDISABLED));
|
||||
}
|
||||
|
||||
/**
|
||||
* @runInSeparateProcess
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
public function testNormalMode()
|
||||
{
|
||||
$this->mockConnected(true, 1);
|
||||
$this->mockFetchFirst('SHOW TABLES LIKE \'config\'', true, 1);
|
||||
$this->mockConfigGet('system', 'maintenance', false, 1);
|
||||
|
||||
$config = \Mockery::mock('Friendica\Core\Config\ConfigCache');
|
||||
$config
|
||||
->shouldReceive('get')
|
||||
->with('system', 'maintenance', null)
|
||||
->andReturn(false)
|
||||
->once();
|
||||
// Initialize empty Config
|
||||
Config::init($config);
|
||||
$configAdapter = \Mockery::mock('Friendica\Core\Config\IConfigAdapter');
|
||||
$configAdapter
|
||||
->shouldReceive('isConnected')
|
||||
->andReturn(false);
|
||||
Config::setAdapter($configAdapter);
|
||||
|
||||
$mode = new Mode($this->root->url());
|
||||
$mode->determine();
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@
|
|||
|
||||
namespace Friendica\Test;
|
||||
|
||||
use Friendica\App;
|
||||
use Friendica\BaseObject;
|
||||
use Friendica\Test\Util\AppMockTrait;
|
||||
use Friendica\Test\Util\VFSTrait;
|
||||
|
|
@ -13,8 +12,6 @@ use PHPUnit\Framework\TestCase;
|
|||
|
||||
/**
|
||||
* Tests for the BaseObject class.
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
class BaseObjectTest extends TestCase
|
||||
{
|
||||
|
|
@ -27,46 +24,29 @@ class BaseObjectTest extends TestCase
|
|||
private $baseObject;
|
||||
|
||||
/**
|
||||
* Create variables used in tests.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->baseObject = new BaseObject();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the getApp() function.
|
||||
* Test the setApp() and getApp() function.
|
||||
* @return void
|
||||
*/
|
||||
public function testGetApp()
|
||||
public function testGetSetApp()
|
||||
{
|
||||
$baseObject = new BaseObject();
|
||||
$this->setUpVfsDir();
|
||||
$configMock = \Mockery::mock('Friendica\Core\Config\ConfigCache');
|
||||
$this->mockApp($this->root, $configMock);
|
||||
|
||||
$this->assertInstanceOf(App::class, $this->baseObject->getApp());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the setApp() function.
|
||||
* @return void
|
||||
*/
|
||||
public function testSetApp()
|
||||
{
|
||||
$this->setUpVfsDir();
|
||||
$configMock = \Mockery::mock('Friendica\Core\Config\ConfigCache');
|
||||
$this->mockApp($this->root, $configMock);
|
||||
|
||||
$this->assertNull($this->baseObject->setApp($this->app));
|
||||
$this->assertEquals($this->app, $this->baseObject->getApp());
|
||||
$this->assertNull($baseObject->setApp($this->app));
|
||||
$this->assertEquals($this->app, $baseObject->getApp());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the getApp() function without App
|
||||
* @expectedException Friendica\Network\HTTPException\InternalServerErrorException
|
||||
* @runInSeparateProcess
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
public function testGetAppFailed()
|
||||
{
|
||||
BaseObject::getApp();
|
||||
$baseObject = new BaseObject();
|
||||
$baseObject->getApp();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,13 +2,8 @@
|
|||
|
||||
namespace Friendica\Test\src\Core\Cache;
|
||||
|
||||
|
||||
use Friendica\Core\Cache\ArrayCache;
|
||||
|
||||
/**
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
class ArrayCacheDriverTest extends MemoryCacheTest
|
||||
{
|
||||
protected function getInstance()
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ namespace Friendica\Test\src\Core\Cache;
|
|||
use Friendica\Core\Cache\MemcachedCacheDriver;
|
||||
use Friendica\Test\MockedTest;
|
||||
use Friendica\Test\Util\AppMockTrait;
|
||||
use Friendica\Test\Util\DateTimeFormatMockTrait;
|
||||
use Friendica\Test\Util\VFSTrait;
|
||||
use Friendica\Util\PidFile;
|
||||
|
||||
|
|
@ -13,7 +12,6 @@ abstract class CacheTest extends MockedTest
|
|||
{
|
||||
use VFSTrait;
|
||||
use AppMockTrait;
|
||||
use DateTimeFormatMockTrait;
|
||||
|
||||
/**
|
||||
* @var int Start time of the mock (used for time operations)
|
||||
|
|
@ -75,19 +73,10 @@ abstract class CacheTest extends MockedTest
|
|||
->shouldReceive('getHostname')
|
||||
->andReturn('friendica.local');
|
||||
|
||||
$this->mockUtcNow($this->startTime);
|
||||
|
||||
parent::setUp();
|
||||
|
||||
$this->instance = $this->getInstance();
|
||||
|
||||
// Default config
|
||||
$this->mockConfigGet('config', 'hostname', 'localhost');
|
||||
$this->mockConfigGet('system', 'throttle_limit_day', 100);
|
||||
$this->mockConfigGet('system', 'throttle_limit_week', 100);
|
||||
$this->mockConfigGet('system', 'throttle_limit_month', 100);
|
||||
$this->mockConfigGet('system', 'theme', 'system_theme');
|
||||
|
||||
$this->instance->clear(false);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@ class DatabaseCacheDriverTest extends CacheTest
|
|||
|
||||
public function setUp()
|
||||
{
|
||||
$this->mockUtcNow($this->startTime);
|
||||
|
||||
$this->mockConnected();
|
||||
$this->mockConnect();
|
||||
|
||||
|
|
|
|||
|
|
@ -6,16 +6,21 @@ namespace Friendica\Test\src\Core\Cache;
|
|||
use Friendica\Core\Cache\CacheDriverFactory;
|
||||
|
||||
/**
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @requires extension memcache
|
||||
*/
|
||||
class MemcacheCacheDriverTest extends MemoryCacheTest
|
||||
{
|
||||
protected function getInstance()
|
||||
{
|
||||
$this->mockConfigGet('system', 'memcache_host', 'localhost', 1);
|
||||
$this->mockConfigGet('system', 'memcache_port', 11211, 1);
|
||||
$this->configCache
|
||||
->shouldReceive('get')
|
||||
->with('system', 'memcache_host', NULL)
|
||||
->andReturn('localhost');
|
||||
|
||||
$this->configCache
|
||||
->shouldReceive('get')
|
||||
->with('system', 'memcache_port', NULL)
|
||||
->andReturn(11211);
|
||||
|
||||
$this->cache = CacheDriverFactory::create('memcache');
|
||||
return $this->cache;
|
||||
|
|
|
|||
|
|
@ -6,15 +6,16 @@ namespace Friendica\Test\src\Core\Cache;
|
|||
use Friendica\Core\Cache\CacheDriverFactory;
|
||||
|
||||
/**
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @requires extension memcached
|
||||
*/
|
||||
class MemcachedCacheDriverTest extends MemoryCacheTest
|
||||
{
|
||||
protected function getInstance()
|
||||
{
|
||||
$this->mockConfigGet('system', 'memcached_hosts', [0 => 'localhost, 11211']);
|
||||
$this->configCache
|
||||
->shouldReceive('get')
|
||||
->with('system', 'memcached_hosts', NULL)
|
||||
->andReturn([0 => 'localhost, 11211']);
|
||||
|
||||
$this->cache = CacheDriverFactory::create('memcached');
|
||||
return $this->cache;
|
||||
|
|
|
|||
|
|
@ -6,16 +6,21 @@ namespace Friendica\Test\src\Core\Cache;
|
|||
use Friendica\Core\Cache\CacheDriverFactory;
|
||||
|
||||
/**
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
* @requires extension redis
|
||||
*/
|
||||
class RedisCacheDriverTest extends MemoryCacheTest
|
||||
{
|
||||
protected function getInstance()
|
||||
{
|
||||
$this->mockConfigGet('system', 'redis_host', 'localhost', 1);
|
||||
$this->mockConfigGet('system', 'redis_port', null, 1);
|
||||
$this->configCache
|
||||
->shouldReceive('get')
|
||||
->with('system', 'redis_host', NULL)
|
||||
->andReturn('localhost');
|
||||
|
||||
$this->configCache
|
||||
->shouldReceive('get')
|
||||
->with('system', 'redis_port', NULL)
|
||||
->andReturn(null);
|
||||
|
||||
$this->cache = CacheDriverFactory::create('redis');
|
||||
return $this->cache;
|
||||
|
|
|
|||
|
|
@ -52,7 +52,10 @@ class AutomaticInstallationConsoleTest extends ConsoleTest
|
|||
$this->db_user = getenv('MYSQL_USERNAME') . getenv('MYSQL_USER');
|
||||
$this->db_pass = getenv('MYSQL_PASSWORD');
|
||||
|
||||
$this->mockConfigGet('config', 'php_path', false);
|
||||
$this->configCache
|
||||
->shouldReceive('get')
|
||||
->with('config', 'php_path', NULL)
|
||||
->andReturn(false);
|
||||
|
||||
$this->mockL10nT();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,7 +32,17 @@ class ConfigConsoleTest extends ConsoleTest
|
|||
}
|
||||
|
||||
function testSetGetKeyValue() {
|
||||
$this->mockConfigSet('config', 'test', 'now', 1);
|
||||
$this->configCache
|
||||
->shouldReceive('set')
|
||||
->with('config', 'test', 'now')
|
||||
->andReturn(true)
|
||||
->once();
|
||||
$this->configCache
|
||||
->shouldReceive('get')
|
||||
->with('config', 'test', NULL)
|
||||
->andReturn('now')
|
||||
->twice();
|
||||
|
||||
$console = new Config($this->consoleArgv);
|
||||
$console->setArgument(0, 'config');
|
||||
$console->setArgument(1, 'test');
|
||||
|
|
@ -40,14 +50,24 @@ class ConfigConsoleTest extends ConsoleTest
|
|||
$txt = $this->dumpExecute($console);
|
||||
$this->assertEquals("config.test <= now\n", $txt);
|
||||
|
||||
$this->mockConfigGet('config', 'test', 'now', 1);
|
||||
$this->configCache
|
||||
->shouldReceive('get')
|
||||
->with('config', 'test', null)
|
||||
->andReturn('now')
|
||||
->once();
|
||||
|
||||
$console = new Config($this->consoleArgv);
|
||||
$console->setArgument(0, 'config');
|
||||
$console->setArgument(1, 'test');
|
||||
$txt = $this->dumpExecute($console);
|
||||
$this->assertEquals("config.test => now\n", $txt);
|
||||
|
||||
$this->mockConfigGet('config', 'test', null, 1);
|
||||
$this->configCache
|
||||
->shouldReceive('get')
|
||||
->with('config', 'test', null)
|
||||
->andReturn(null)
|
||||
->once();
|
||||
|
||||
$console = new Config($this->consoleArgv);
|
||||
$console->setArgument(0, 'config');
|
||||
$console->setArgument(1, 'test');
|
||||
|
|
@ -57,7 +77,11 @@ class ConfigConsoleTest extends ConsoleTest
|
|||
|
||||
function testSetArrayValue() {
|
||||
$testArray = [1, 2, 3];
|
||||
$this->mockConfigGet('config', 'test', $testArray, 1);
|
||||
$this->configCache
|
||||
->shouldReceive('get')
|
||||
->with('config', 'test', null)
|
||||
->andReturn($testArray)
|
||||
->once();
|
||||
|
||||
$console = new Config($this->consoleArgv);
|
||||
$console->setArgument(0, 'config');
|
||||
|
|
@ -81,7 +105,11 @@ class ConfigConsoleTest extends ConsoleTest
|
|||
}
|
||||
|
||||
function testVerbose() {
|
||||
$this->mockConfigGet('test', 'it', 'now', 1);
|
||||
$this->configCache
|
||||
->shouldReceive('get')
|
||||
->with('test', 'it', null)
|
||||
->andReturn('now')
|
||||
->once();
|
||||
$console = new Config($this->consoleArgv);
|
||||
$console->setArgument(0, 'test');
|
||||
$console->setArgument(1, 'it');
|
||||
|
|
@ -105,7 +133,16 @@ CONF;
|
|||
}
|
||||
|
||||
function testUnableToSet() {
|
||||
$this->mockConfigSet('test', 'it', 'now', 1, false);
|
||||
$this->configCache
|
||||
->shouldReceive('set')
|
||||
->with('test', 'it', 'now')
|
||||
->andReturn(false)
|
||||
->once();
|
||||
$this->configCache
|
||||
->shouldReceive('get')
|
||||
->with('test', 'it', NULL)
|
||||
->andReturn(NULL)
|
||||
->once();
|
||||
$console = new Config();
|
||||
$console->setArgument(0, 'test');
|
||||
$console->setArgument(1, 'it');
|
||||
|
|
|
|||
|
|
@ -6,10 +6,6 @@ namespace Friendica\Test\src\Core\Lock;
|
|||
use Friendica\Core\Cache\ArrayCache;
|
||||
use Friendica\Core\Lock\CacheLockDriver;
|
||||
|
||||
/**
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
class ArrayCacheLockDriverTest extends LockTest
|
||||
{
|
||||
protected function getInstance()
|
||||
|
|
|
|||
|
|
@ -25,10 +25,6 @@ abstract class LockTest extends MockedTest
|
|||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->instance = $this->getInstance();
|
||||
$this->instance->releaseAll();
|
||||
|
||||
// Reusable App object
|
||||
$this->setUpVfsDir();
|
||||
$configMock = \Mockery::mock('Friendica\Core\Config\ConfigCache');
|
||||
|
|
@ -37,12 +33,9 @@ abstract class LockTest extends MockedTest
|
|||
->shouldReceive('getHostname')
|
||||
->andReturn('friendica.local');
|
||||
|
||||
// Default config
|
||||
$this->mockConfigGet('config', 'hostname', 'localhost');
|
||||
$this->mockConfigGet('system', 'throttle_limit_day', 100);
|
||||
$this->mockConfigGet('system', 'throttle_limit_week', 100);
|
||||
$this->mockConfigGet('system', 'throttle_limit_month', 100);
|
||||
$this->mockConfigGet('system', 'theme', 'system_theme');
|
||||
parent::setUp();
|
||||
$this->instance = $this->getInstance();
|
||||
$this->instance->releaseAll();
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
|
|
|
|||
|
|
@ -8,15 +8,20 @@ use Friendica\Core\Lock\CacheLockDriver;
|
|||
|
||||
/**
|
||||
* @requires extension Memcache
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
class MemcacheCacheLockDriverTest extends LockTest
|
||||
{
|
||||
protected function getInstance()
|
||||
{
|
||||
$this->mockConfigGet('system', 'memcache_host', 'localhost', 1);
|
||||
$this->mockConfigGet('system', 'memcache_port', 11211, 1);
|
||||
$this->configCache
|
||||
->shouldReceive('get')
|
||||
->with('system', 'memcache_host', NULL)
|
||||
->andReturn('localhost');
|
||||
|
||||
$this->configCache
|
||||
->shouldReceive('get')
|
||||
->with('system', 'memcache_port', NULL)
|
||||
->andReturn(11211);
|
||||
|
||||
return new CacheLockDriver(CacheDriverFactory::create('memcache'));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,14 +8,15 @@ use Friendica\Core\Lock\CacheLockDriver;
|
|||
|
||||
/**
|
||||
* @requires extension memcached
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
class MemcachedCacheLockDriverTest extends LockTest
|
||||
{
|
||||
protected function getInstance()
|
||||
{
|
||||
$this->mockConfigGet('system', 'memcached_hosts', [0 => 'localhost, 11211']);
|
||||
$this->configCache
|
||||
->shouldReceive('get')
|
||||
->with('system', 'memcached_hosts', NULL)
|
||||
->andReturn([0 => 'localhost, 11211']);
|
||||
|
||||
return new CacheLockDriver(CacheDriverFactory::create('memcached'));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,15 +8,20 @@ use Friendica\Core\Lock\CacheLockDriver;
|
|||
|
||||
/**
|
||||
* @requires extension redis
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
class RedisCacheLockDriverTest extends LockTest
|
||||
{
|
||||
protected function getInstance()
|
||||
{
|
||||
$this->mockConfigGet('system', 'redis_host', 'localhost', 1);
|
||||
$this->mockConfigGet('system', 'redis_port', null, 1);
|
||||
$this->configCache
|
||||
->shouldReceive('get')
|
||||
->with('system', 'redis_host', NULL)
|
||||
->andReturn('localhost');
|
||||
|
||||
$this->configCache
|
||||
->shouldReceive('get')
|
||||
->with('system', 'redis_port', NULL)
|
||||
->andReturn(null);
|
||||
|
||||
return new CacheLockDriver(CacheDriverFactory::create('redis'));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,10 +4,6 @@ namespace Friendica\Test\src\Core\Lock;
|
|||
|
||||
use Friendica\Core\Lock\SemaphoreLockDriver;
|
||||
|
||||
/**
|
||||
* @runTestsInSeparateProcesses
|
||||
* @preserveGlobalState disabled
|
||||
*/
|
||||
class SemaphoreLockDriverTest extends LockTest
|
||||
{
|
||||
public function setUp()
|
||||
|
|
@ -15,7 +11,11 @@ class SemaphoreLockDriverTest extends LockTest
|
|||
parent::setUp();
|
||||
|
||||
$this->app->shouldReceive('getHostname')->andReturn('friendica.local');
|
||||
$this->mockConfigGet('system', 'temppath', '/tmp/');
|
||||
|
||||
$this->configCache
|
||||
->shouldReceive('get')
|
||||
->with('system', 'temppath', NULL)
|
||||
->andReturn('/tmp/');
|
||||
}
|
||||
|
||||
protected function getInstance()
|
||||
|
|
|
|||
|
|
@ -21,13 +21,6 @@ class DBStructureTest extends DatabaseTest
|
|||
$this->logOutput = FActory\LoggerFactory::enableTest($this->app->getLogger());
|
||||
|
||||
parent::setUp();
|
||||
|
||||
// Default config
|
||||
Config::set('config', 'hostname', 'localhost');
|
||||
Config::set('system', 'throttle_limit_day', 100);
|
||||
Config::set('system', 'throttle_limit_week', 100);
|
||||
Config::set('system', 'throttle_limit_month', 100);
|
||||
Config::set('system', 'theme', 'system_theme');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue