Config FollowUp
- New Configuration (Config is now only holding the instance) - New PConfiguration (PConfig is now only holding the instance) - Config & PConfig-Adapter don't need "ConfigCache" anymore - DB-Connection is now outside App->reload() for better dependency-chaining
This commit is contained in:
parent
c36a0eabdb
commit
eafcf3592d
59 changed files with 1754 additions and 1038 deletions
|
@ -5,7 +5,7 @@
|
|||
|
||||
namespace Friendica\Test;
|
||||
|
||||
use Friendica\Core\Config;
|
||||
use Friendica\Core\Config\Cache;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Factory;
|
||||
use Friendica\Util\BasePath;
|
||||
|
@ -41,7 +41,7 @@ abstract class DatabaseTest extends MockedTest
|
|||
}
|
||||
|
||||
$basedir = BasePath::create(dirname(__DIR__));
|
||||
$configLoader = new Config\ConfigCacheLoader($basedir);
|
||||
$configLoader = new Cache\ConfigCacheLoader($basedir);
|
||||
$config = Factory\ConfigFactory::createCache($configLoader);
|
||||
|
||||
$profiler = \Mockery::mock(Profiler::class);
|
||||
|
|
|
@ -5,7 +5,6 @@ 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;
|
||||
use org\bovigo\vfs\vfsStreamDirectory;
|
||||
|
@ -21,7 +20,7 @@ trait AppMockTrait
|
|||
protected $app;
|
||||
|
||||
/**
|
||||
* @var MockInterface|ConfigCache The mocked Config Cache
|
||||
* @var MockInterface|Config\Configuration The mocked Config Cache
|
||||
*/
|
||||
protected $configCache;
|
||||
|
||||
|
@ -29,9 +28,9 @@ trait AppMockTrait
|
|||
* Mock the App
|
||||
*
|
||||
* @param vfsStreamDirectory $root The root directory
|
||||
* @param MockInterface|ConfigCache $config The config cache
|
||||
* @param MockInterface|Config\Configuration $config The config cache
|
||||
*/
|
||||
public function mockApp($root, $config)
|
||||
public function mockApp($root, Config\Configuration $config)
|
||||
{
|
||||
$this->configCache = $config;
|
||||
// Mocking App and most used functions
|
||||
|
@ -62,11 +61,14 @@ trait AppMockTrait
|
|||
->andReturn('localhost');
|
||||
$config
|
||||
->shouldReceive('get')
|
||||
->with('system', 'theme', NULL)
|
||||
->with('system', 'theme', NULL, false)
|
||||
->andReturn('system_theme');
|
||||
$config
|
||||
->shouldReceive('getConfig')
|
||||
->andReturn($config);
|
||||
|
||||
$this->app
|
||||
->shouldReceive('getConfig')
|
||||
->shouldReceive('getConfigCache')
|
||||
->andReturn($config);
|
||||
|
||||
$this->app
|
||||
|
@ -84,11 +86,6 @@ trait AppMockTrait
|
|||
|
||||
// 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);
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ namespace Friendica\Test;
|
|||
|
||||
use Friendica\App;
|
||||
use Friendica\Core\Config;
|
||||
use Friendica\Core\Config\Cache;
|
||||
use Friendica\Core\PConfig;
|
||||
use Friendica\Core\Protocol;
|
||||
use Friendica\Core\System;
|
||||
|
@ -36,8 +37,11 @@ class ApiTest extends DatabaseTest
|
|||
public function setUp()
|
||||
{
|
||||
$basedir = BasePath::create(dirname(__DIR__) . '/../');
|
||||
$configLoader = new Config\ConfigCacheLoader($basedir);
|
||||
$config = Factory\ConfigFactory::createCache($configLoader);
|
||||
$configLoader = new Cache\ConfigCacheLoader($basedir);
|
||||
$configCache = Factory\ConfigFactory::createCache($configLoader);
|
||||
Factory\DBFactory::init($configCache, $_SERVER);
|
||||
$config = Factory\ConfigFactory::createConfig($configCache);
|
||||
$pconfig = Factory\ConfigFactory::createPConfig($configCache);
|
||||
$logger = Factory\LoggerFactory::create('test', $config);
|
||||
$profiler = Factory\ProfilerFactory::create($logger, $config);
|
||||
$this->app = new App($config, $logger, $profiler, false);
|
||||
|
|
|
@ -90,19 +90,14 @@ class ModeTest extends MockedTest
|
|||
$this->mockConnected(true, 1);
|
||||
$this->mockFetchFirst('SHOW TABLES LIKE \'config\'', true, 1);
|
||||
|
||||
$config = \Mockery::mock('Friendica\Core\Config\ConfigCache');
|
||||
$config = \Mockery::mock('Friendica\Core\Config\Configuration');
|
||||
$config
|
||||
->shouldReceive('get')
|
||||
->with('system', 'maintenance', null)
|
||||
->with('system', 'maintenance', null, false)
|
||||
->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();
|
||||
|
@ -123,19 +118,14 @@ class ModeTest extends MockedTest
|
|||
$this->mockConnected(true, 1);
|
||||
$this->mockFetchFirst('SHOW TABLES LIKE \'config\'', true, 1);
|
||||
|
||||
$config = \Mockery::mock('Friendica\Core\Config\ConfigCache');
|
||||
$config = \Mockery::mock('Friendica\Core\Config\Configuration');
|
||||
$config
|
||||
->shouldReceive('get')
|
||||
->with('system', 'maintenance', null)
|
||||
->with('system', 'maintenance', null, false)
|
||||
->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();
|
||||
|
|
|
@ -31,7 +31,7 @@ class BaseObjectTest extends TestCase
|
|||
{
|
||||
$baseObject = new BaseObject();
|
||||
$this->setUpVfsDir();
|
||||
$configMock = \Mockery::mock('Friendica\Core\Config\ConfigCache');
|
||||
$configMock = \Mockery::mock('Friendica\Core\Config\Configuration');
|
||||
$this->mockApp($this->root, $configMock);
|
||||
|
||||
$this->assertNull($baseObject->setApp($this->app));
|
||||
|
|
|
@ -67,7 +67,7 @@ abstract class CacheTest extends MockedTest
|
|||
protected function setUp()
|
||||
{
|
||||
$this->setUpVfsDir();
|
||||
$configMock = \Mockery::mock('Friendica\Core\Config\ConfigCache');
|
||||
$configMock = \Mockery::mock('Friendica\Core\Config\Configuration');
|
||||
$this->mockApp($this->root, $configMock);
|
||||
$this->app
|
||||
->shouldReceive('getHostname')
|
||||
|
|
|
@ -14,12 +14,12 @@ class MemcacheCacheDriverTest extends MemoryCacheTest
|
|||
{
|
||||
$this->configCache
|
||||
->shouldReceive('get')
|
||||
->with('system', 'memcache_host', NULL)
|
||||
->with('system', 'memcache_host', NULL, false)
|
||||
->andReturn('localhost');
|
||||
|
||||
$this->configCache
|
||||
->shouldReceive('get')
|
||||
->with('system', 'memcache_port', NULL)
|
||||
->with('system', 'memcache_port', NULL, false)
|
||||
->andReturn(11211);
|
||||
|
||||
$this->cache = CacheDriverFactory::create('memcache');
|
||||
|
|
|
@ -14,7 +14,7 @@ class MemcachedCacheDriverTest extends MemoryCacheTest
|
|||
{
|
||||
$this->configCache
|
||||
->shouldReceive('get')
|
||||
->with('system', 'memcached_hosts', NULL)
|
||||
->with('system', 'memcached_hosts', NULL, false)
|
||||
->andReturn([0 => 'localhost, 11211']);
|
||||
|
||||
$this->cache = CacheDriverFactory::create('memcached');
|
||||
|
|
|
@ -14,12 +14,12 @@ class RedisCacheDriverTest extends MemoryCacheTest
|
|||
{
|
||||
$this->configCache
|
||||
->shouldReceive('get')
|
||||
->with('system', 'redis_host', NULL)
|
||||
->with('system', 'redis_host', NULL, false)
|
||||
->andReturn('localhost');
|
||||
|
||||
$this->configCache
|
||||
->shouldReceive('get')
|
||||
->with('system', 'redis_port', NULL)
|
||||
->with('system', 'redis_port', NULL, false)
|
||||
->andReturn(null);
|
||||
|
||||
$this->cache = CacheDriverFactory::create('redis');
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace Friendica\Test\Core\Config;
|
||||
namespace Friendica\Test\Core\Config\Cache;
|
||||
|
||||
use Friendica\Core\Config\ConfigCache;
|
||||
use Friendica\Core\Config\ConfigCacheLoader;
|
||||
use Friendica\Core\Config\Cache\ConfigCache;
|
||||
use Friendica\Core\Config\Cache\ConfigCacheLoader;
|
||||
use Friendica\Test\MockedTest;
|
||||
use Friendica\Test\Util\VFSTrait;
|
||||
use org\bovigo\vfs\vfsStream;
|
||||
|
@ -59,6 +59,7 @@ class ConfigCacheLoaderTest extends MockedTest
|
|||
$this->delConfigFile('local.config.php');
|
||||
|
||||
$file = dirname(__DIR__) . DIRECTORY_SEPARATOR .
|
||||
'..' . DIRECTORY_SEPARATOR .
|
||||
'..' . DIRECTORY_SEPARATOR .
|
||||
'..' . DIRECTORY_SEPARATOR .
|
||||
'datasets' . DIRECTORY_SEPARATOR .
|
||||
|
@ -91,6 +92,7 @@ class ConfigCacheLoaderTest extends MockedTest
|
|||
$this->delConfigFile('local.config.php');
|
||||
|
||||
$file = dirname(__DIR__) . DIRECTORY_SEPARATOR .
|
||||
'..' . DIRECTORY_SEPARATOR .
|
||||
'..' . DIRECTORY_SEPARATOR .
|
||||
'..' . DIRECTORY_SEPARATOR .
|
||||
'datasets' . DIRECTORY_SEPARATOR .
|
||||
|
@ -122,6 +124,7 @@ class ConfigCacheLoaderTest extends MockedTest
|
|||
$this->delConfigFile('local.config.php');
|
||||
|
||||
$file = dirname(__DIR__) . DIRECTORY_SEPARATOR .
|
||||
'..' . DIRECTORY_SEPARATOR .
|
||||
'..' . DIRECTORY_SEPARATOR .
|
||||
'..' . DIRECTORY_SEPARATOR .
|
||||
'datasets' . DIRECTORY_SEPARATOR .
|
||||
|
@ -160,6 +163,7 @@ class ConfigCacheLoaderTest extends MockedTest
|
|||
vfsStream::create($structure, $this->root);
|
||||
|
||||
$file = dirname(__DIR__) . DIRECTORY_SEPARATOR .
|
||||
'..' . DIRECTORY_SEPARATOR .
|
||||
'..' . DIRECTORY_SEPARATOR .
|
||||
'..' . DIRECTORY_SEPARATOR .
|
||||
'datasets' . DIRECTORY_SEPARATOR .
|
|
@ -1,8 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace Friendica\Test\Core\Config;
|
||||
namespace Friendica\Test\Core\Config\Cache;
|
||||
|
||||
use Friendica\Core\Config\ConfigCache;
|
||||
use Friendica\Core\Config\Cache\ConfigCache;
|
||||
use Friendica\Test\MockedTest;
|
||||
|
||||
class ConfigCacheTest extends MockedTest
|
||||
|
@ -48,7 +48,7 @@ class ConfigCacheTest extends MockedTest
|
|||
public function testLoadConfigArray($data)
|
||||
{
|
||||
$configCache = new ConfigCache();
|
||||
$configCache->loadConfigArray($data);
|
||||
$configCache->load($data);
|
||||
|
||||
$this->assertConfigValues($data, $configCache);
|
||||
}
|
||||
|
@ -67,18 +67,38 @@ class ConfigCacheTest extends MockedTest
|
|||
];
|
||||
|
||||
$configCache = new ConfigCache();
|
||||
$configCache->loadConfigArray($data);
|
||||
$configCache->loadConfigArray($override);
|
||||
$configCache->load($data);
|
||||
$configCache->load($override);
|
||||
|
||||
$this->assertConfigValues($data, $configCache);
|
||||
|
||||
// override the value
|
||||
$configCache->loadConfigArray($override, true);
|
||||
$configCache->load($override, true);
|
||||
|
||||
$this->assertEquals($override['system']['test'], $configCache->get('system', 'test'));
|
||||
$this->assertEquals($override['system']['boolTrue'], $configCache->get('system', 'boolTrue'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the loadConfigArray() method with wrong/empty datasets
|
||||
*/
|
||||
public function testLoadConfigArrayWrong()
|
||||
{
|
||||
$configCache = new ConfigCache();
|
||||
|
||||
// empty dataset
|
||||
$configCache->load([]);
|
||||
$this->assertEmpty($configCache->getAll());
|
||||
|
||||
// wrong dataset
|
||||
$configCache->load(['system' => 'not_array']);
|
||||
$this->assertEmpty($configCache->getAll());
|
||||
|
||||
// incomplete dataset (key is integer ID of the array)
|
||||
$configCache->load(['system' => ['value']]);
|
||||
$this->assertEquals('value', $configCache->get('system', 0));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the getAll() method
|
||||
* @dataProvider dataTests
|
||||
|
@ -86,14 +106,12 @@ class ConfigCacheTest extends MockedTest
|
|||
public function testGetAll($data)
|
||||
{
|
||||
$configCache = new ConfigCache();
|
||||
$configCache->loadConfigArray($data);
|
||||
$configCache->load($data);
|
||||
|
||||
$all = $configCache->getAll();
|
||||
|
||||
$this->assertContains($data['system'], $all);
|
||||
|
||||
// config values are stored directly in the array base
|
||||
$this->assertEquals($data['config']['a'], $all['a']);
|
||||
$this->assertContains($data['config'], $all);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -113,6 +131,33 @@ class ConfigCacheTest extends MockedTest
|
|||
$this->assertConfigValues($data, $configCache);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the get() method without a value
|
||||
*/
|
||||
public function testGetEmpty()
|
||||
{
|
||||
$configCache = new ConfigCache();
|
||||
|
||||
$this->assertEquals('!<unset>!', $configCache->get('something', 'value'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the has() method
|
||||
*/
|
||||
public function testHas()
|
||||
{
|
||||
$configCache = new ConfigCache();
|
||||
|
||||
$this->assertFalse($configCache->has('system', 'test'));
|
||||
|
||||
$configCache->set('system', 'test', 'it');
|
||||
$this->assertTrue($configCache->has('system', 'test'));
|
||||
|
||||
$this->assertFalse($configCache->has('system', null));
|
||||
$configCache->set('system', null, 'it');
|
||||
$this->assertTrue($configCache->has('system', null));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the delete() method
|
||||
* @dataProvider dataTests
|
||||
|
@ -172,4 +217,22 @@ class ConfigCacheTest extends MockedTest
|
|||
|
||||
$this->assertEmpty($configCache->getAll());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the hasP() method
|
||||
*/
|
||||
public function testHasP()
|
||||
{
|
||||
$configCache = new ConfigCache();
|
||||
$uid = 345;
|
||||
|
||||
$this->assertFalse($configCache->hasP($uid, 'system', 'test'));
|
||||
|
||||
$configCache->setP($uid, 'system', 'test', 'it');
|
||||
$this->assertTrue($configCache->hasP($uid, 'system', 'test'));
|
||||
|
||||
$this->assertFalse($configCache->hasP($uid, 'system', null));
|
||||
$configCache->setP($uid, 'system', null, 'it');
|
||||
$this->assertTrue($configCache->hasP($uid, 'system', null));
|
||||
}
|
||||
}
|
215
tests/src/Core/Config/ConfigurationTest.php
Normal file
215
tests/src/Core/Config/ConfigurationTest.php
Normal file
|
@ -0,0 +1,215 @@
|
|||
<?php
|
||||
|
||||
namespace Friendica\Test\Core\Config;
|
||||
|
||||
use Friendica\Core\Config\Cache\ConfigCache;
|
||||
use Friendica\Core\Config\Cache\IConfigCache;
|
||||
use Friendica\Core\Config\Configuration;
|
||||
use Friendica\Test\MockedTest;
|
||||
|
||||
class ConfigurationTest extends MockedTest
|
||||
{
|
||||
/**
|
||||
* Test the configuration initialization
|
||||
*/
|
||||
public function testSetUp()
|
||||
{
|
||||
$configCache = new ConfigCache();
|
||||
$configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IConfigAdapter');
|
||||
$configAdapter->shouldReceive('isConnected')->andReturn(false)->once();
|
||||
|
||||
$configuration = new Configuration($configCache, $configAdapter);
|
||||
|
||||
$this->assertInstanceOf(IConfigCache::class, $configuration->getCache());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the configuration load() method
|
||||
*/
|
||||
public function testCacheLoad()
|
||||
{
|
||||
$configCache = new ConfigCache();
|
||||
$configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IConfigAdapter');
|
||||
$configAdapter->shouldReceive('isConnected')->andReturn(true)->twice();
|
||||
// constructor loading
|
||||
$configAdapter->shouldReceive('load')->andReturn([])->once();
|
||||
// expected loading
|
||||
$configAdapter->shouldReceive('load')->andReturn(['testing' => ['test' => 'it']])->once();
|
||||
|
||||
$configuration = new Configuration($configCache, $configAdapter);
|
||||
$configuration->load('testing');
|
||||
|
||||
$this->assertEquals('it', $configuration->get('testing', 'test'));
|
||||
$this->assertEquals('it', $configuration->getCache()->get('testing', 'test'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the configuration load() method with overwrite
|
||||
*/
|
||||
public function testCacheLoadDouble()
|
||||
{
|
||||
$configCache = new ConfigCache();
|
||||
$configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IConfigAdapter');
|
||||
$configAdapter->shouldReceive('isConnected')->andReturn(true)->times(3);
|
||||
// constructor loading
|
||||
$configAdapter->shouldReceive('load')->andReturn([])->once();
|
||||
// expected loading
|
||||
$configAdapter->shouldReceive('load')->andReturn(['testing' => ['test' => 'it']])->once();
|
||||
// expected next loading
|
||||
$configAdapter->shouldReceive('load')->andReturn(['testing' => ['test' => 'again']])->once();
|
||||
|
||||
$configuration = new Configuration($configCache, $configAdapter);
|
||||
$configuration->load('testing');
|
||||
|
||||
$this->assertEquals('it', $configuration->get('testing', 'test'));
|
||||
$this->assertEquals('it', $configuration->getCache()->get('testing', 'test'));
|
||||
|
||||
$configuration->load('testing');
|
||||
|
||||
$this->assertEquals('again', $configuration->get('testing', 'test'));
|
||||
$this->assertEquals('again', $configuration->getCache()->get('testing', 'test'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the configuration get() and set() methods without adapter
|
||||
*/
|
||||
public function testSetGetWithoutDB()
|
||||
{
|
||||
$configCache = new ConfigCache();
|
||||
$configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IConfigAdapter');
|
||||
$configAdapter->shouldReceive('isConnected')->andReturn(false)->twice();
|
||||
|
||||
$configuration = new Configuration($configCache, $configAdapter);
|
||||
|
||||
$this->assertTrue($configuration->set('test', 'it', 'now'));
|
||||
|
||||
$this->assertEquals('now', $configuration->get('test', 'it'));
|
||||
$this->assertEquals('now', $configuration->getCache()->get('test', 'it'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the configuration get() and set() methods with adapter
|
||||
*/
|
||||
public function testSetGetWithDB()
|
||||
{
|
||||
$configCache = new ConfigCache();
|
||||
$configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IConfigAdapter');
|
||||
$configAdapter->shouldReceive('isConnected')->andReturn(true)->twice();
|
||||
// constructor loading
|
||||
$configAdapter->shouldReceive('load')->andReturn([])->once();
|
||||
$configAdapter->shouldReceive('set')->with('test', 'it', 'now')->andReturn(true)->once();
|
||||
|
||||
$configuration = new Configuration($configCache, $configAdapter);
|
||||
|
||||
$this->assertTrue($configuration->set('test', 'it', 'now'));
|
||||
|
||||
$this->assertEquals('now', $configuration->get('test', 'it'));
|
||||
$this->assertEquals('now', $configuration->getCache()->get('test', 'it'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the configuration get() method with wrong value and no db
|
||||
*/
|
||||
public function testGetWrongWithoutDB()
|
||||
{
|
||||
$configCache = new ConfigCache();
|
||||
$configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IConfigAdapter');
|
||||
$configAdapter->shouldReceive('isConnected')->andReturn(false)->times(4);
|
||||
|
||||
$configuration = new Configuration($configCache, $configAdapter);
|
||||
|
||||
// without refresh
|
||||
$this->assertNull($configuration->get('test', 'it'));
|
||||
|
||||
/// beware that the cache returns '!<unset>!' and not null for a non existing value
|
||||
$this->assertEquals('!<unset>!', $configuration->getCache()->get('test', 'it'));
|
||||
|
||||
// with default value
|
||||
$this->assertEquals('default', $configuration->get('test', 'it', 'default'));
|
||||
|
||||
// with default value and refresh
|
||||
$this->assertEquals('default', $configuration->get('test', 'it', 'default', true));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the configuration get() method with refresh
|
||||
*/
|
||||
public function testGetWithRefresh()
|
||||
{
|
||||
$configCache = new ConfigCache(['test' => ['it' => 'now']]);
|
||||
$configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IConfigAdapter');
|
||||
$configAdapter->shouldReceive('isConnected')->andReturn(true)->times(3);
|
||||
// constructor loading
|
||||
$configAdapter->shouldReceive('load')->andReturn([])->once();
|
||||
$configAdapter->shouldReceive('get')->with('test', 'it')->andReturn('again')->once();
|
||||
$configAdapter->shouldReceive('get')->with('test', 'not')->andReturn('!<unset>!')->once();
|
||||
|
||||
$configuration = new Configuration($configCache, $configAdapter);
|
||||
|
||||
// without refresh
|
||||
$this->assertEquals('now', $configuration->get('test', 'it'));
|
||||
$this->assertEquals('now', $configuration->getCache()->get('test', 'it'));
|
||||
|
||||
// with refresh
|
||||
$this->assertEquals('again', $configuration->get('test', 'it', null, true));
|
||||
$this->assertEquals('again', $configuration->getCache()->get('test', 'it'));
|
||||
|
||||
// without refresh and wrong value and default
|
||||
$this->assertEquals('default', $configuration->get('test', 'not', 'default'));
|
||||
$this->assertEquals('!<unset>!', $configuration->getCache()->get('test', 'not'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the configuration delete() method without adapter
|
||||
*/
|
||||
public function testDeleteWithoutDB()
|
||||
{
|
||||
$configCache = new ConfigCache(['test' => ['it' => 'now']]);
|
||||
$configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IConfigAdapter');
|
||||
$configAdapter->shouldReceive('isConnected')->andReturn(false)->times(3);
|
||||
|
||||
$configuration = new Configuration($configCache, $configAdapter);
|
||||
|
||||
$this->assertEquals('now', $configuration->get('test', 'it'));
|
||||
$this->assertEquals('now', $configuration->getCache()->get('test', 'it'));
|
||||
|
||||
$this->assertTrue($configuration->delete('test', 'it'));
|
||||
$this->assertNull($configuration->get('test', 'it'));
|
||||
$this->assertEquals('!<unset>!', $configuration->getCache()->get('test', 'it'));
|
||||
|
||||
$this->assertEmpty($configuration->getCache()->getAll());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the configuration delete() method with adapter
|
||||
*/
|
||||
public function testDeleteWithDB()
|
||||
{
|
||||
$configCache = new ConfigCache(['test' => ['it' => 'now', 'quarter' => 'true']]);
|
||||
$configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IConfigAdapter');
|
||||
$configAdapter->shouldReceive('isConnected')->andReturn(true)->times(5);
|
||||
// constructor loading
|
||||
$configAdapter->shouldReceive('load')->andReturn([])->once();
|
||||
$configAdapter->shouldReceive('delete')->with('test', 'it')->andReturn(false)->once();
|
||||
|
||||
$configAdapter->shouldReceive('delete')->with('test', 'second')->andReturn(true)->once();
|
||||
$configAdapter->shouldReceive('delete')->with('test', 'third')->andReturn(false)->once();
|
||||
$configAdapter->shouldReceive('delete')->with('test', 'quarter')->andReturn(true)->once();
|
||||
|
||||
$configuration = new Configuration($configCache, $configAdapter);
|
||||
|
||||
$this->assertEquals('now', $configuration->get('test', 'it'));
|
||||
$this->assertEquals('now', $configuration->getCache()->get('test', 'it'));
|
||||
|
||||
// delete from cache only
|
||||
$this->assertTrue($configuration->delete('test', 'it'));
|
||||
// delete from db only
|
||||
$this->assertTrue($configuration->delete('test', 'second'));
|
||||
// no delete
|
||||
$this->assertFalse($configuration->delete('test', 'third'));
|
||||
// delete both
|
||||
$this->assertTrue($configuration->delete('test', 'quarter'));
|
||||
|
||||
$this->assertEmpty($configuration->getCache()->getAll());
|
||||
}
|
||||
}
|
186
tests/src/Core/Config/PConfigurationTest.php
Normal file
186
tests/src/Core/Config/PConfigurationTest.php
Normal file
|
@ -0,0 +1,186 @@
|
|||
<?php
|
||||
|
||||
namespace Friendica\Test\Core\Config;
|
||||
|
||||
use Friendica\Core\Config\Cache\ConfigCache;
|
||||
use Friendica\Core\Config\PConfiguration;
|
||||
use Friendica\Test\MockedTest;
|
||||
|
||||
class PConfigurationTest extends MockedTest
|
||||
{
|
||||
/**
|
||||
* Test if the configuration load() method
|
||||
*/
|
||||
public function testCacheLoad()
|
||||
{
|
||||
$uid = 234;
|
||||
$configCache = new ConfigCache();
|
||||
$configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IPConfigAdapter');
|
||||
$configAdapter->shouldReceive('isConnected')->andReturn(true)->once();
|
||||
// expected loading
|
||||
$configAdapter->shouldReceive('load')->andReturn(['testing' => ['test' => 'it']])->once();
|
||||
|
||||
$configuration = new PConfiguration($configCache, $configAdapter);
|
||||
$configuration->load($uid, 'testing');
|
||||
|
||||
$this->assertEquals('it', $configuration->get($uid, 'testing', 'test'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the configuration load() method with overwrite
|
||||
*/
|
||||
public function testCacheLoadDouble()
|
||||
{
|
||||
$uid = 234;
|
||||
$configCache = new ConfigCache();
|
||||
$configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IPConfigAdapter');
|
||||
$configAdapter->shouldReceive('isConnected')->andReturn(true)->twice();
|
||||
// expected loading
|
||||
$configAdapter->shouldReceive('load')->andReturn(['testing' => ['test' => 'it']])->once();
|
||||
// expected next loading
|
||||
$configAdapter->shouldReceive('load')->andReturn(['testing' => ['test' => 'again']])->once();
|
||||
|
||||
$configuration = new PConfiguration($configCache, $configAdapter);
|
||||
$configuration->load($uid, 'testing');
|
||||
|
||||
$this->assertEquals('it', $configuration->get($uid, 'testing', 'test'));
|
||||
|
||||
$configuration->load($uid, 'testing');
|
||||
|
||||
$this->assertEquals('again', $configuration->get($uid, 'testing', 'test'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the configuration get() and set() methods without adapter
|
||||
*/
|
||||
public function testSetGetWithoutDB()
|
||||
{
|
||||
$uid = 234;
|
||||
$configCache = new ConfigCache();
|
||||
$configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IPConfigAdapter');
|
||||
$configAdapter->shouldReceive('isConnected')->andReturn(false)->once();
|
||||
|
||||
$configuration = new PConfiguration($configCache, $configAdapter);
|
||||
|
||||
$this->assertTrue($configuration->set($uid, 'test', 'it', 'now'));
|
||||
|
||||
$this->assertEquals('now', $configuration->get($uid, 'test', 'it'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the configuration get() and set() methods with adapter
|
||||
*/
|
||||
public function testSetGetWithDB()
|
||||
{
|
||||
$uid = 234;
|
||||
$configCache = new ConfigCache();
|
||||
$configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IPConfigAdapter');
|
||||
$configAdapter->shouldReceive('isConnected')->andReturn(true)->once();
|
||||
$configAdapter->shouldReceive('set')->with($uid, 'test', 'it', 'now')->andReturn(true)->once();
|
||||
|
||||
$configuration = new PConfiguration($configCache, $configAdapter);
|
||||
|
||||
$this->assertTrue($configuration->set($uid, 'test', 'it', 'now'));
|
||||
|
||||
$this->assertEquals('now', $configuration->get($uid, 'test', 'it'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the configuration get() method with wrong value and no db
|
||||
*/
|
||||
public function testGetWrongWithoutDB()
|
||||
{
|
||||
$uid = 234;
|
||||
$configCache = new ConfigCache();
|
||||
$configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IPConfigAdapter');
|
||||
$configAdapter->shouldReceive('isConnected')->andReturn(false)->times(3);
|
||||
|
||||
$configuration = new PConfiguration($configCache, $configAdapter);
|
||||
|
||||
// without refresh
|
||||
$this->assertNull($configuration->get($uid, 'test', 'it'));
|
||||
|
||||
// with default value
|
||||
$this->assertEquals('default', $configuration->get($uid, 'test', 'it', 'default'));
|
||||
|
||||
// with default value and refresh
|
||||
$this->assertEquals('default', $configuration->get($uid, 'test', 'it', 'default', true));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the configuration get() method with refresh
|
||||
*/
|
||||
public function testGetWithRefresh()
|
||||
{
|
||||
$uid = 234;
|
||||
$configCache = new ConfigCache();
|
||||
$configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IPConfigAdapter');
|
||||
$configAdapter->shouldReceive('isConnected')->andReturn(true)->times(3);
|
||||
$configAdapter->shouldReceive('get')->with($uid, 'test', 'it')->andReturn('now')->once();
|
||||
$configAdapter->shouldReceive('get')->with($uid, 'test', 'it')->andReturn('again')->once();
|
||||
$configAdapter->shouldReceive('get')->with($uid, 'test', 'not')->andReturn('!<unset>!')->once();
|
||||
|
||||
$configuration = new PConfiguration($configCache, $configAdapter);
|
||||
|
||||
// without refresh
|
||||
$this->assertEquals('now', $configuration->get($uid, 'test', 'it'));
|
||||
// use the cache again
|
||||
$this->assertEquals('now', $configuration->get($uid, 'test', 'it'));
|
||||
|
||||
// with refresh (and load the second value out of the db)
|
||||
$this->assertEquals('again', $configuration->get($uid, 'test', 'it', null, true));
|
||||
|
||||
// without refresh and wrong value and default
|
||||
$this->assertEquals('default', $configuration->get($uid, 'test', 'not', 'default'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the configuration delete() method without adapter
|
||||
*/
|
||||
public function testDeleteWithoutDB()
|
||||
{
|
||||
$uid = 234;
|
||||
$configCache = new ConfigCache();
|
||||
$configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IPConfigAdapter');
|
||||
$configAdapter->shouldReceive('isConnected')->andReturn(false)->times(3);
|
||||
|
||||
$configuration = new PConfiguration($configCache, $configAdapter);
|
||||
|
||||
$this->assertTrue($configuration->set($uid, 'test', 'it', 'now'));
|
||||
$this->assertEquals('now', $configuration->get($uid, 'test', 'it'));
|
||||
|
||||
$this->assertTrue($configuration->delete($uid, 'test', 'it'));
|
||||
$this->assertNull($configuration->get($uid, 'test', 'it'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the configuration delete() method with adapter
|
||||
*/
|
||||
public function testDeleteWithDB()
|
||||
{
|
||||
$uid = 234;
|
||||
$configCache = new ConfigCache();
|
||||
$configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IPConfigAdapter');
|
||||
$configAdapter->shouldReceive('isConnected')->andReturn(true)->times(5);
|
||||
$configAdapter->shouldReceive('set')->with($uid, 'test', 'it', 'now')->andReturn(false)->once();
|
||||
$configAdapter->shouldReceive('delete')->with($uid, 'test', 'it')->andReturn(false)->once();
|
||||
|
||||
$configAdapter->shouldReceive('delete')->with($uid, 'test', 'second')->andReturn(true)->once();
|
||||
$configAdapter->shouldReceive('delete')->with($uid, 'test', 'third')->andReturn(false)->once();
|
||||
$configAdapter->shouldReceive('delete')->with($uid, 'test', 'quarter')->andReturn(true)->once();
|
||||
|
||||
$configuration = new PConfiguration($configCache, $configAdapter);
|
||||
|
||||
$this->assertFalse($configuration->set($uid, 'test', 'it', 'now'));
|
||||
$this->assertEquals('now', $configuration->get($uid, 'test', 'it'));
|
||||
|
||||
// delete from set
|
||||
$this->assertTrue($configuration->delete($uid, 'test', 'it'));
|
||||
// delete from db only
|
||||
$this->assertTrue($configuration->delete($uid, 'test', 'second'));
|
||||
// no delete
|
||||
$this->assertFalse($configuration->delete($uid, 'test', 'third'));
|
||||
// delete both
|
||||
$this->assertTrue($configuration->delete($uid, 'test', 'quarter'));
|
||||
}
|
||||
}
|
|
@ -54,7 +54,7 @@ class AutomaticInstallationConsoleTest extends ConsoleTest
|
|||
|
||||
$this->configCache
|
||||
->shouldReceive('get')
|
||||
->with('config', 'php_path', NULL)
|
||||
->with('config', 'php_path', NULL, false)
|
||||
->andReturn(false);
|
||||
|
||||
$this->mockL10nT();
|
||||
|
|
|
@ -39,7 +39,7 @@ class ConfigConsoleTest extends ConsoleTest
|
|||
->once();
|
||||
$this->configCache
|
||||
->shouldReceive('get')
|
||||
->with('config', 'test', NULL)
|
||||
->with('config', 'test', NULL, false)
|
||||
->andReturn('now')
|
||||
->twice();
|
||||
|
||||
|
@ -52,7 +52,7 @@ class ConfigConsoleTest extends ConsoleTest
|
|||
|
||||
$this->configCache
|
||||
->shouldReceive('get')
|
||||
->with('config', 'test', null)
|
||||
->with('config', 'test', null, false)
|
||||
->andReturn('now')
|
||||
->once();
|
||||
|
||||
|
@ -64,7 +64,7 @@ class ConfigConsoleTest extends ConsoleTest
|
|||
|
||||
$this->configCache
|
||||
->shouldReceive('get')
|
||||
->with('config', 'test', null)
|
||||
->with('config', 'test', null, false)
|
||||
->andReturn(null)
|
||||
->once();
|
||||
|
||||
|
@ -79,7 +79,7 @@ class ConfigConsoleTest extends ConsoleTest
|
|||
$testArray = [1, 2, 3];
|
||||
$this->configCache
|
||||
->shouldReceive('get')
|
||||
->with('config', 'test', null)
|
||||
->with('config', 'test', null, false)
|
||||
->andReturn($testArray)
|
||||
->once();
|
||||
|
||||
|
@ -107,7 +107,7 @@ class ConfigConsoleTest extends ConsoleTest
|
|||
function testVerbose() {
|
||||
$this->configCache
|
||||
->shouldReceive('get')
|
||||
->with('test', 'it', null)
|
||||
->with('test', 'it', null, false)
|
||||
->andReturn('now')
|
||||
->once();
|
||||
$console = new Config($this->consoleArgv);
|
||||
|
@ -140,7 +140,7 @@ CONF;
|
|||
->once();
|
||||
$this->configCache
|
||||
->shouldReceive('get')
|
||||
->with('test', 'it', NULL)
|
||||
->with('test', 'it', NULL, false)
|
||||
->andReturn(NULL)
|
||||
->once();
|
||||
$console = new Config();
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
namespace Friendica\Test\src\Core\Console;
|
||||
|
||||
use Asika\SimpleConsole\Console;
|
||||
use Friendica\Core\Config\ConfigCache;
|
||||
use Friendica\Core\Config\Configuration;
|
||||
use Friendica\Test\MockedTest;
|
||||
use Friendica\Test\Util\AppMockTrait;
|
||||
use Friendica\Test\Util\Intercept;
|
||||
|
@ -31,7 +31,7 @@ abstract class ConsoleTest extends MockedTest
|
|||
Intercept::setUp();
|
||||
|
||||
$this->setUpVfsDir();
|
||||
$configMock = \Mockery::mock(ConfigCache::class);
|
||||
$configMock = \Mockery::mock(Configuration::class);
|
||||
$this->mockApp($this->root, $configMock);
|
||||
$profileMock = \Mockery::mock(Profiler::class);
|
||||
$this->app->shouldReceive('getProfiler')->andReturn($profileMock);
|
||||
|
|
|
@ -27,7 +27,7 @@ abstract class LockTest extends MockedTest
|
|||
{
|
||||
// Reusable App object
|
||||
$this->setUpVfsDir();
|
||||
$configMock = \Mockery::mock('Friendica\Core\Config\ConfigCache');
|
||||
$configMock = \Mockery::mock('Friendica\Core\Config\Configuration');
|
||||
$this->mockApp($this->root, $configMock);
|
||||
$this->app
|
||||
->shouldReceive('getHostname')
|
||||
|
|
|
@ -15,12 +15,12 @@ class MemcacheCacheLockDriverTest extends LockTest
|
|||
{
|
||||
$this->configCache
|
||||
->shouldReceive('get')
|
||||
->with('system', 'memcache_host', NULL)
|
||||
->with('system', 'memcache_host', NULL, false)
|
||||
->andReturn('localhost');
|
||||
|
||||
$this->configCache
|
||||
->shouldReceive('get')
|
||||
->with('system', 'memcache_port', NULL)
|
||||
->with('system', 'memcache_port', NULL, false)
|
||||
->andReturn(11211);
|
||||
|
||||
return new CacheLockDriver(CacheDriverFactory::create('memcache'));
|
||||
|
|
|
@ -15,7 +15,7 @@ class MemcachedCacheLockDriverTest extends LockTest
|
|||
{
|
||||
$this->configCache
|
||||
->shouldReceive('get')
|
||||
->with('system', 'memcached_hosts', NULL)
|
||||
->with('system', 'memcached_hosts', NULL, false)
|
||||
->andReturn([0 => 'localhost, 11211']);
|
||||
|
||||
return new CacheLockDriver(CacheDriverFactory::create('memcached'));
|
||||
|
|
|
@ -15,12 +15,12 @@ class RedisCacheLockDriverTest extends LockTest
|
|||
{
|
||||
$this->configCache
|
||||
->shouldReceive('get')
|
||||
->with('system', 'redis_host', NULL)
|
||||
->with('system', 'redis_host', NULL, false)
|
||||
->andReturn('localhost');
|
||||
|
||||
$this->configCache
|
||||
->shouldReceive('get')
|
||||
->with('system', 'redis_port', NULL)
|
||||
->with('system', 'redis_port', NULL, false)
|
||||
->andReturn(null);
|
||||
|
||||
return new CacheLockDriver(CacheDriverFactory::create('redis'));
|
||||
|
|
|
@ -14,7 +14,7 @@ class SemaphoreLockDriverTest extends LockTest
|
|||
|
||||
$this->configCache
|
||||
->shouldReceive('get')
|
||||
->with('system', 'temppath', NULL)
|
||||
->with('system', 'temppath', NULL, false)
|
||||
->andReturn('/tmp/');
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ namespace Friendica\Test\Database;
|
|||
|
||||
use Friendica\App;
|
||||
use Friendica\Core\Config;
|
||||
use Friendica\Core\Config\Cache;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\Factory;
|
||||
use Friendica\Test\DatabaseTest;
|
||||
|
@ -13,8 +14,11 @@ class DBATest extends DatabaseTest
|
|||
public function setUp()
|
||||
{
|
||||
$basedir = BasePath::create(dirname(__DIR__) . '/../../');
|
||||
$configLoader = new Config\ConfigCacheLoader($basedir);
|
||||
$config = Factory\ConfigFactory::createCache($configLoader);
|
||||
$configLoader = new Cache\ConfigCacheLoader($basedir);
|
||||
$configCache = Factory\ConfigFactory::createCache($configLoader);
|
||||
Factory\DBFactory::init($configCache, $_SERVER);
|
||||
$config = Factory\ConfigFactory::createConfig($configCache);
|
||||
$pconfig = Factory\ConfigFactory::createPConfig($configCache);
|
||||
$logger = Factory\LoggerFactory::create('test', $config);
|
||||
$profiler = Factory\ProfilerFactory::create($logger, $config);
|
||||
$this->app = new App($config, $logger, $profiler, false);
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
namespace Friendica\Test\Database;
|
||||
|
||||
use Friendica\App;
|
||||
use Friendica\Core\Config;
|
||||
use Friendica\Core\Config\Cache;
|
||||
use Friendica\Database\DBStructure;
|
||||
use Friendica\Factory;
|
||||
use Friendica\Test\DatabaseTest;
|
||||
|
@ -14,8 +14,11 @@ class DBStructureTest extends DatabaseTest
|
|||
public function setUp()
|
||||
{
|
||||
$basedir = BasePath::create(dirname(__DIR__) . '/../../');
|
||||
$configLoader = new Config\ConfigCacheLoader($basedir);
|
||||
$config = Factory\ConfigFactory::createCache($configLoader);
|
||||
$configLoader = new Cache\ConfigCacheLoader($basedir);
|
||||
$configCache = Factory\ConfigFactory::createCache($configLoader);
|
||||
Factory\DBFactory::init($configCache, $_SERVER);
|
||||
$config = Factory\ConfigFactory::createConfig($configCache);
|
||||
$pconfig = Factory\ConfigFactory::createPConfig($configCache);
|
||||
$logger = Factory\LoggerFactory::create('test', $config);
|
||||
$profiler = Factory\ProfilerFactory::create($logger, $config);
|
||||
$this->app = new App($config, $logger, $profiler, false);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue