Splitting ConfigCache & PConfigCache
- Remove IConfigCache & IPConfigCache - Add new PConfigCache - Add missing Logger::init() (bugfixing tests)
This commit is contained in:
parent
b56709d802
commit
c82127ffb7
27 changed files with 527 additions and 334 deletions
|
@ -3,6 +3,8 @@
|
|||
namespace Friendica\Test\src\Core\Cache;
|
||||
|
||||
use Friendica\Core\Cache\IMemoryCacheDriver;
|
||||
use Friendica\Core\Logger;
|
||||
use Psr\Log\NullLogger;
|
||||
|
||||
abstract class MemoryCacheTest extends CacheTest
|
||||
{
|
||||
|
@ -13,6 +15,8 @@ abstract class MemoryCacheTest extends CacheTest
|
|||
|
||||
protected function setUp()
|
||||
{
|
||||
Logger::init(new NullLogger());
|
||||
|
||||
parent::setUp();
|
||||
if (!($this->instance instanceof IMemoryCacheDriver)) {
|
||||
throw new \Exception('MemoryCacheTest unsupported');
|
||||
|
|
|
@ -29,15 +29,11 @@ class ConfigCacheTest extends MockedTest
|
|||
];
|
||||
}
|
||||
|
||||
private function assertConfigValues($data, ConfigCache $configCache, $uid = null)
|
||||
private function assertConfigValues($data, ConfigCache $configCache)
|
||||
{
|
||||
foreach ($data as $cat => $values) {
|
||||
foreach ($values as $key => $value) {
|
||||
if (isset($uid)) {
|
||||
$this->assertEquals($data[$cat][$key], $configCache->getP($uid, $cat, $key));
|
||||
} else {
|
||||
$this->assertEquals($data[$cat][$key], $configCache->get($cat, $key));
|
||||
}
|
||||
$this->assertEquals($data[$cat][$key], $configCache->get($cat, $key));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -180,73 +176,6 @@ class ConfigCacheTest extends MockedTest
|
|||
$this->assertEmpty($configCache->getAll());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the setP() and getP() methods
|
||||
* @dataProvider dataTests
|
||||
*/
|
||||
public function testSetGetP($data)
|
||||
{
|
||||
$configCache = new ConfigCache();
|
||||
$uid = 345;
|
||||
|
||||
foreach ($data as $cat => $values) {
|
||||
foreach ($values as $key => $value) {
|
||||
$configCache->setP($uid, $cat, $key, $value);
|
||||
}
|
||||
}
|
||||
|
||||
$this->assertConfigValues($data, $configCache, $uid);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test the getP() method with a category
|
||||
*/
|
||||
public function testGetPCat()
|
||||
{
|
||||
$configCache = new ConfigCache();
|
||||
$uid = 345;
|
||||
|
||||
$configCache->loadP($uid, [
|
||||
'system' => [
|
||||
'key1' => 'value1',
|
||||
'key2' => 'value2',
|
||||
],
|
||||
'config' => [
|
||||
'key3' => 'value3',
|
||||
],
|
||||
]);
|
||||
|
||||
$this->assertEquals([
|
||||
'key1' => 'value1',
|
||||
'key2' => 'value2',
|
||||
], $configCache->get($uid, 'system'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the deleteP() method
|
||||
* @dataProvider dataTests
|
||||
*/
|
||||
public function testDeleteP($data)
|
||||
{
|
||||
$configCache = new ConfigCache();
|
||||
$uid = 345;
|
||||
|
||||
foreach ($data as $cat => $values) {
|
||||
foreach ($values as $key => $value) {
|
||||
$configCache->setP($uid, $cat, $key, $value);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($data as $cat => $values) {
|
||||
foreach ($values as $key => $value) {
|
||||
$configCache->deleteP($uid, $cat, $key);
|
||||
}
|
||||
}
|
||||
|
||||
$this->assertEmpty($configCache->getAll());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the keyDiff() method with result
|
||||
* @dataProvider dataTests
|
||||
|
|
252
tests/src/Core/Config/Cache/PConfigCacheTest.php
Normal file
252
tests/src/Core/Config/Cache/PConfigCacheTest.php
Normal file
|
@ -0,0 +1,252 @@
|
|||
<?php
|
||||
|
||||
namespace Friendica\Test\src\Core\Config\Cache;
|
||||
|
||||
use Friendica\Core\Config\Cache\PConfigCache;
|
||||
use Friendica\Test\MockedTest;
|
||||
|
||||
class PConfigCacheTest extends MockedTest
|
||||
{
|
||||
public function dataTests()
|
||||
{
|
||||
return [
|
||||
'normal' => [
|
||||
'data' => [
|
||||
'system' => [
|
||||
'test' => 'it',
|
||||
'boolTrue' => true,
|
||||
'boolFalse' => false,
|
||||
'int' => 235,
|
||||
'dec' => 2.456,
|
||||
'array' => ['1', 2, '3', true, false],
|
||||
],
|
||||
'config' => [
|
||||
'a' => 'value',
|
||||
],
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
private function assertConfigValues($data, PConfigCache $configCache, $uid)
|
||||
{
|
||||
foreach ($data as $cat => $values) {
|
||||
foreach ($values as $key => $value) {
|
||||
$this->assertEquals($data[$cat][$key], $configCache->get($uid, $cat, $key));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the setP() and getP() methods
|
||||
*
|
||||
* @dataProvider dataTests
|
||||
*/
|
||||
public function testSetGet($data)
|
||||
{
|
||||
$configCache = new PConfigCache();
|
||||
$uid = 345;
|
||||
|
||||
foreach ($data as $cat => $values) {
|
||||
foreach ($values as $key => $value) {
|
||||
$configCache->set($uid, $cat, $key, $value);
|
||||
}
|
||||
}
|
||||
|
||||
$this->assertConfigValues($data, $configCache, $uid);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Test the getP() method with a category
|
||||
*/
|
||||
public function testGetCat()
|
||||
{
|
||||
$configCache = new PConfigCache();
|
||||
$uid = 345;
|
||||
|
||||
$configCache->load($uid, [
|
||||
'system' => [
|
||||
'key1' => 'value1',
|
||||
'key2' => 'value2',
|
||||
],
|
||||
'config' => [
|
||||
'key3' => 'value3',
|
||||
],
|
||||
]);
|
||||
|
||||
$this->assertEquals([
|
||||
'key1' => 'value1',
|
||||
'key2' => 'value2',
|
||||
], $configCache->get($uid, 'system'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the deleteP() method
|
||||
*
|
||||
* @dataProvider dataTests
|
||||
*/
|
||||
public function testDelete($data)
|
||||
{
|
||||
$configCache = new PConfigCache();
|
||||
$uid = 345;
|
||||
|
||||
foreach ($data as $cat => $values) {
|
||||
foreach ($values as $key => $value) {
|
||||
$configCache->set($uid, $cat, $key, $value);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($data as $cat => $values) {
|
||||
foreach ($values as $key => $value) {
|
||||
$configCache->delete($uid, $cat, $key);
|
||||
}
|
||||
}
|
||||
|
||||
$this->assertEmpty($configCache->getAll());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the keyDiff() method with result
|
||||
*
|
||||
* @dataProvider dataTests
|
||||
*/
|
||||
public function testKeyDiffWithResult($data)
|
||||
{
|
||||
$configCache = new PConfigCache($data);
|
||||
|
||||
$diffConfig = [
|
||||
'fakeCat' => [
|
||||
'fakeKey' => 'value',
|
||||
]
|
||||
];
|
||||
|
||||
$this->assertEquals($diffConfig, $configCache->keyDiff($diffConfig));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the keyDiff() method without result
|
||||
*
|
||||
* @dataProvider dataTests
|
||||
*/
|
||||
public function testKeyDiffWithoutResult($data)
|
||||
{
|
||||
$configCache = new PConfigCache();
|
||||
|
||||
$configCache->load(1, $data);
|
||||
|
||||
$diffConfig = $configCache->getAll();
|
||||
|
||||
$this->assertEmpty($configCache->keyDiff($diffConfig));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the default hiding of passwords inside the cache
|
||||
*/
|
||||
public function testPasswordHide()
|
||||
{
|
||||
$configCache = new PConfigCache();
|
||||
|
||||
$configCache->load(1, [
|
||||
'database' => [
|
||||
'password' => 'supersecure',
|
||||
'username' => 'notsecured',
|
||||
]
|
||||
]);
|
||||
|
||||
$this->assertEquals('supersecure', $configCache->get(1, 'database', 'password'));
|
||||
$this->assertNotEquals('supersecure', print_r($configCache->get(1, 'database', 'password'), true));
|
||||
$this->assertEquals('notsecured', print_r($configCache->get(1, 'database', 'username'), true));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test disabling the hiding of passwords inside the cache
|
||||
*/
|
||||
public function testPasswordShow()
|
||||
{
|
||||
$configCache = new PConfigCache(false);
|
||||
|
||||
$configCache->load(1, [
|
||||
'database' => [
|
||||
'password' => 'supersecure',
|
||||
'username' => 'notsecured',
|
||||
]
|
||||
]);
|
||||
|
||||
$this->assertEquals('supersecure', $configCache->get(1, 'database', 'password'));
|
||||
$this->assertEquals('supersecure', print_r($configCache->get(1, 'database', 'password'), true));
|
||||
$this->assertEquals('notsecured', print_r($configCache->get(1, 'database', 'username'), true));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test a empty password
|
||||
*/
|
||||
public function testEmptyPassword()
|
||||
{
|
||||
$configCache = new PConfigCache();
|
||||
|
||||
$configCache->load(1, [
|
||||
'database' => [
|
||||
'password' => '',
|
||||
'username' => '',
|
||||
]
|
||||
]);
|
||||
|
||||
$this->assertEmpty($configCache->get(1, 'database', 'password'));
|
||||
$this->assertEmpty($configCache->get(1, 'database', 'username'));
|
||||
}
|
||||
|
||||
public function testWrongTypePassword()
|
||||
{
|
||||
$configCache = new PConfigCache();
|
||||
|
||||
$configCache->load(1, [
|
||||
'database' => [
|
||||
'password' => new \stdClass(),
|
||||
'username' => '',
|
||||
]
|
||||
]);
|
||||
|
||||
$this->assertNotEmpty($configCache->get(1, 'database', 'password'));
|
||||
$this->assertEmpty($configCache->get(1, 'database', 'username'));
|
||||
|
||||
$configCache = new PConfigCache();
|
||||
|
||||
$configCache->load(1, [
|
||||
'database' => [
|
||||
'password' => 23,
|
||||
'username' => '',
|
||||
],
|
||||
]);
|
||||
|
||||
$this->assertEquals(23, $configCache->get(1, 'database', 'password'));
|
||||
$this->assertEmpty($configCache->get(1, 'database', 'username'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test two different UID configs and make sure that there is no overlapping possible
|
||||
*/
|
||||
public function testTwoUid()
|
||||
{
|
||||
$configCache = new PConfigCache();
|
||||
|
||||
$configCache->load(1, [
|
||||
'cat1' => [
|
||||
'key1' => 'value1',
|
||||
],
|
||||
]);
|
||||
|
||||
|
||||
$configCache->load(2, [
|
||||
'cat2' => [
|
||||
'key2' => 'value2',
|
||||
],
|
||||
]);
|
||||
|
||||
$this->assertEquals('value1', $configCache->get(1, 'cat1', 'key1'));
|
||||
$this->assertEquals('value2', $configCache->get(2, 'cat2', 'key2'));
|
||||
|
||||
$this->assertNull($configCache->get(1, 'cat2', 'key2'));
|
||||
$this->assertNull($configCache->get(2, 'cat1', 'key1'));
|
||||
}
|
||||
}
|
|
@ -4,7 +4,6 @@ namespace Friendica\Test\src\Core\Config;
|
|||
|
||||
use Friendica\Core\Config\Adapter\IConfigAdapter;
|
||||
use Friendica\Core\Config\Cache\ConfigCache;
|
||||
use Friendica\Core\Config\Cache\IConfigCache;
|
||||
use Friendica\Core\Config\Configuration;
|
||||
use Friendica\Test\MockedTest;
|
||||
|
||||
|
@ -35,7 +34,7 @@ class ConfigurationTest extends MockedTest
|
|||
|
||||
$configuration = new Configuration($configCache, $configAdapter);
|
||||
|
||||
$this->assertInstanceOf(IConfigCache::class, $configuration->getCache());
|
||||
$this->assertInstanceOf(ConfigCache::class, $configuration->getCache());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
namespace Friendica\Test\src\Core\Config;
|
||||
|
||||
use Friendica\Core\Config\Adapter\IPConfigAdapter;
|
||||
use Friendica\Core\Config\Cache\ConfigCache;
|
||||
use Friendica\Core\Config\Cache\PConfigCache;
|
||||
use Friendica\Core\Config\PConfiguration;
|
||||
use Friendica\Test\MockedTest;
|
||||
|
||||
|
@ -29,7 +29,7 @@ class PConfigurationTest extends MockedTest
|
|||
public function testCacheLoad()
|
||||
{
|
||||
$uid = 234;
|
||||
$configCache = new ConfigCache();
|
||||
$configCache = new PConfigCache();
|
||||
$configAdapter = \Mockery::mock(IPConfigAdapter::class);
|
||||
$configAdapter->shouldReceive('isConnected')->andReturn(true)->twice();
|
||||
// expected loading
|
||||
|
@ -51,7 +51,7 @@ class PConfigurationTest extends MockedTest
|
|||
public function testCacheLoadDouble()
|
||||
{
|
||||
$uid = 234;
|
||||
$configCache = new ConfigCache();
|
||||
$configCache = new PConfigCache();
|
||||
$configAdapter = \Mockery::mock(IPConfigAdapter::class);
|
||||
$configAdapter->shouldReceive('isConnected')->andReturn(true)->times(4);
|
||||
// expected loading
|
||||
|
@ -77,7 +77,7 @@ class PConfigurationTest extends MockedTest
|
|||
public function testSetGetWithoutDB($data)
|
||||
{
|
||||
$uid = 234;
|
||||
$configCache = new ConfigCache();
|
||||
$configCache = new PConfigCache();
|
||||
$configAdapter = \Mockery::mock(IPConfigAdapter::class);
|
||||
$configAdapter->shouldReceive('isConnected')->andReturn(false)->times(2);
|
||||
|
||||
|
@ -95,7 +95,7 @@ class PConfigurationTest extends MockedTest
|
|||
public function testSetGetWithDB($data)
|
||||
{
|
||||
$uid = 234;
|
||||
$configCache = new ConfigCache();
|
||||
$configCache = new PConfigCache();
|
||||
$configAdapter = \Mockery::mock(IPConfigAdapter::class);
|
||||
$configAdapter->shouldReceive('isConnected')->andReturn(true)->times(2);
|
||||
$configAdapter->shouldReceive('isLoaded')->with($uid, 'test', 'it')->andReturn(true)->once();
|
||||
|
@ -114,7 +114,7 @@ class PConfigurationTest extends MockedTest
|
|||
public function testGetWrongWithoutDB()
|
||||
{
|
||||
$uid = 234;
|
||||
$configCache = new ConfigCache();
|
||||
$configCache = new PConfigCache();
|
||||
$configAdapter = \Mockery::mock(IPConfigAdapter::class);
|
||||
$configAdapter->shouldReceive('isConnected')->andReturn(false)->times(3);
|
||||
|
||||
|
@ -137,7 +137,7 @@ class PConfigurationTest extends MockedTest
|
|||
public function testGetWithRefresh($data)
|
||||
{
|
||||
$uid = 234;
|
||||
$configCache = new ConfigCache();
|
||||
$configCache = new PConfigCache();
|
||||
$configAdapter = \Mockery::mock(IPConfigAdapter::class);
|
||||
$configAdapter->shouldReceive('isConnected')->andReturn(true)->times(4);
|
||||
$configAdapter->shouldReceive('isLoaded')->with($uid, 'test', 'it')->andReturn(false)->once();
|
||||
|
@ -168,7 +168,7 @@ class PConfigurationTest extends MockedTest
|
|||
public function testGetWithoutLoaded($data)
|
||||
{
|
||||
$uid = 234;
|
||||
$configCache = new ConfigCache();
|
||||
$configCache = new PConfigCache();
|
||||
$configAdapter = \Mockery::mock(IPConfigAdapter::class);
|
||||
$configAdapter->shouldReceive('isConnected')->andReturn(true)->times(3);
|
||||
|
||||
|
@ -199,7 +199,7 @@ class PConfigurationTest extends MockedTest
|
|||
public function testDeleteWithoutDB($data)
|
||||
{
|
||||
$uid = 234;
|
||||
$configCache = new ConfigCache();
|
||||
$configCache = new PConfigCache();
|
||||
$configAdapter = \Mockery::mock(IPConfigAdapter::class);
|
||||
$configAdapter->shouldReceive('isConnected')->andReturn(false)->times(4);
|
||||
|
||||
|
@ -218,7 +218,7 @@ class PConfigurationTest extends MockedTest
|
|||
public function testDeleteWithDB()
|
||||
{
|
||||
$uid = 234;
|
||||
$configCache = new ConfigCache();
|
||||
$configCache = new PConfigCache();
|
||||
$configAdapter = \Mockery::mock(IPConfigAdapter::class);
|
||||
$configAdapter->shouldReceive('isConnected')->andReturn(true)->times(6);
|
||||
$configAdapter->shouldReceive('set')->with($uid, 'test', 'it', 'now')->andReturn(false)->once();
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
// this is in the same namespace as Install for mocking 'function_exists'
|
||||
namespace Friendica\Core;
|
||||
|
||||
use Friendica\Core\Config\Cache\IConfigCache;
|
||||
use Friendica\Core\Config\Cache\ConfigCache;
|
||||
use Friendica\Network\CurlResult;
|
||||
use Friendica\Object\Image;
|
||||
use Friendica\Test\MockedTest;
|
||||
|
@ -402,7 +402,7 @@ class InstallerTest extends MockedTest
|
|||
$this->mockL10nT();
|
||||
|
||||
$install = new Installer();
|
||||
$configCache = \Mockery::mock(IConfigCache::class);
|
||||
$configCache = \Mockery::mock(ConfigCache::class);
|
||||
$configCache->shouldReceive('set')->with('config', 'php_path', \Mockery::any())->once();
|
||||
$configCache->shouldReceive('set')->with('system', 'basepath', '/test/')->once();
|
||||
|
||||
|
|
|
@ -2,9 +2,11 @@
|
|||
|
||||
namespace Friendica\Test\src\Core\Lock;
|
||||
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Test\MockedTest;
|
||||
use Friendica\Test\Util\AppMockTrait;
|
||||
use Friendica\Test\Util\VFSTrait;
|
||||
use Psr\Log\NullLogger;
|
||||
|
||||
abstract class LockTest extends MockedTest
|
||||
{
|
||||
|
@ -32,6 +34,8 @@ abstract class LockTest extends MockedTest
|
|||
->shouldReceive('getHostname')
|
||||
->andReturn('friendica.local');
|
||||
|
||||
Logger::init(new NullLogger());
|
||||
|
||||
parent::setUp();
|
||||
$this->instance = $this->getInstance();
|
||||
$this->instance->releaseAll();
|
||||
|
|
|
@ -22,7 +22,7 @@ class DBATest extends DatabaseTest
|
|||
$profiler = Factory\ProfilerFactory::create($configCache);
|
||||
$database = Factory\DBFactory::init($configCache, $profiler, $_SERVER);
|
||||
$config = Factory\ConfigFactory::createConfig($configCache);
|
||||
Factory\ConfigFactory::createPConfig($configCache);
|
||||
Factory\ConfigFactory::createPConfig(new Config\Cache\PConfigCache());
|
||||
$logger = Factory\LoggerFactory::create('test', $database, $config, $profiler);
|
||||
$baseUrl = new BaseURL($config, $_SERVER);
|
||||
$this->app = new App($database, $config, $mode, $router, $baseUrl, $logger, $profiler, false);
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace Friendica\Test\src\Database;
|
||||
|
||||
use Friendica\App;
|
||||
use Friendica\Core\Config\Cache\PConfigCache;
|
||||
use Friendica\Database\DBStructure;
|
||||
use Friendica\Factory;
|
||||
use Friendica\Test\DatabaseTest;
|
||||
|
@ -22,7 +23,7 @@ class DBStructureTest extends DatabaseTest
|
|||
$profiler = Factory\ProfilerFactory::create($configCache);
|
||||
$database = Factory\DBFactory::init($configCache, $profiler, $_SERVER);
|
||||
$config = Factory\ConfigFactory::createConfig($configCache);
|
||||
Factory\ConfigFactory::createPConfig($configCache);
|
||||
Factory\ConfigFactory::createPConfig(new PConfigCache());
|
||||
$logger = Factory\LoggerFactory::create('test', $database, $config, $profiler);
|
||||
$baseUrl = new BaseURL($config, $_SERVER);
|
||||
$this->app = new App($database, $config, $mode, $router, $baseUrl, $logger, $profiler, false);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue