Restructure (P)Config to follow new paradigm

This commit is contained in:
Philipp 2021-10-23 11:29:16 +02:00
parent 68046573a4
commit ab83d0dd27
No known key found for this signature in database
GPG key ID: 24A7501396EB5432
49 changed files with 368 additions and 331 deletions

View file

@ -22,11 +22,10 @@
namespace Friendica\Test\src\Core\Cache;
use Friendica\Core\Cache;
use Friendica\Factory\ConfigFactory;
use Friendica\Core\Config\Factory\ConfigFactory;
use Friendica\Test\DatabaseTestTrait;
use Friendica\Test\Util\Database\StaticDatabase;
use Friendica\Test\Util\VFSTrait;
use Friendica\Util\ConfigFileLoader;
use Friendica\Util\Profiler;
use Mockery;
use Psr\Log\NullLogger;

View file

@ -19,7 +19,7 @@
*
*/
namespace Friendica\Test\src\Core\Config;
namespace Friendica\Test\src\Core\Config\Cache;
use Friendica\Core\Config\Cache;
use Friendica\Test\MockedTest;
@ -49,7 +49,7 @@ class CacheTest extends MockedTest
];
}
private function assertConfigValues($data, Cache $configCache)
private function assertConfigValues($data, Cache\Cache $configCache)
{
foreach ($data as $cat => $values) {
foreach ($values as $key => $value) {
@ -64,7 +64,7 @@ class CacheTest extends MockedTest
*/
public function testLoadConfigArray($data)
{
$configCache = new Cache();
$configCache = new Cache\Cache();
$configCache->load($data);
self::assertConfigValues($data, $configCache);
@ -83,27 +83,27 @@ class CacheTest extends MockedTest
]
];
$configCache = new Cache();
$configCache->load($data, Cache::SOURCE_DB);
$configCache = new Cache\Cache();
$configCache->load($data, Cache\Cache::SOURCE_DB);
// doesn't override - Low Priority due Config file
$configCache->load($override, Cache::SOURCE_FILE);
$configCache->load($override, Cache\Cache::SOURCE_FILE);
self::assertConfigValues($data, $configCache);
// override the value - High Prio due Server Env
$configCache->load($override, Cache::SOURCE_ENV);
$configCache->load($override, Cache\Cache::SOURCE_ENV);
self::assertEquals($override['system']['test'], $configCache->get('system', 'test'));
self::assertEquals($override['system']['boolTrue'], $configCache->get('system', 'boolTrue'));
// Don't overwrite server ENV variables - even in load mode
$configCache->load($data, Cache::SOURCE_DB);
$configCache->load($data, Cache\Cache::SOURCE_DB);
self::assertEquals($override['system']['test'], $configCache->get('system', 'test'));
self::assertEquals($override['system']['boolTrue'], $configCache->get('system', 'boolTrue'));
// Overwrite ENV variables with ENV variables
$configCache->load($data, Cache::SOURCE_ENV);
$configCache->load($data, Cache\Cache::SOURCE_ENV);
self::assertConfigValues($data, $configCache);
self::assertNotEquals($override['system']['test'], $configCache->get('system', 'test'));
@ -115,7 +115,7 @@ class CacheTest extends MockedTest
*/
public function testLoadConfigArrayWrong()
{
$configCache = new Cache();
$configCache = new Cache\Cache();
// empty dataset
$configCache->load([]);
@ -136,7 +136,7 @@ class CacheTest extends MockedTest
*/
public function testGetAll($data)
{
$configCache = new Cache();
$configCache = new Cache\Cache();
$configCache->load($data);
$all = $configCache->getAll();
@ -151,7 +151,7 @@ class CacheTest extends MockedTest
*/
public function testSetGet($data)
{
$configCache = new Cache();
$configCache = new Cache\Cache();
foreach ($data as $cat => $values) {
foreach ($values as $key => $value) {
@ -167,7 +167,7 @@ class CacheTest extends MockedTest
*/
public function testGetEmpty()
{
$configCache = new Cache();
$configCache = new Cache\Cache();
self::assertNull($configCache->get('something', 'value'));
}
@ -177,7 +177,7 @@ class CacheTest extends MockedTest
*/
public function testGetCat()
{
$configCache = new Cache([
$configCache = new Cache\Cache([
'system' => [
'key1' => 'value1',
'key2' => 'value2',
@ -205,7 +205,7 @@ class CacheTest extends MockedTest
*/
public function testDelete($data)
{
$configCache = new Cache($data);
$configCache = new Cache\Cache($data);
foreach ($data as $cat => $values) {
foreach ($values as $key => $value) {
@ -222,7 +222,7 @@ class CacheTest extends MockedTest
*/
public function testKeyDiffWithResult($data)
{
$configCache = new Cache($data);
$configCache = new Cache\Cache($data);
$diffConfig = [
'fakeCat' => [
@ -239,7 +239,7 @@ class CacheTest extends MockedTest
*/
public function testKeyDiffWithoutResult($data)
{
$configCache = new Cache($data);
$configCache = new Cache\Cache($data);
$diffConfig = $configCache->getAll();
@ -251,7 +251,7 @@ class CacheTest extends MockedTest
*/
public function testPasswordHide()
{
$configCache = new Cache([
$configCache = new Cache\Cache([
'database' => [
'password' => 'supersecure',
'username' => 'notsecured',
@ -268,7 +268,7 @@ class CacheTest extends MockedTest
*/
public function testPasswordShow()
{
$configCache = new Cache([
$configCache = new Cache\Cache([
'database' => [
'password' => 'supersecure',
'username' => 'notsecured',
@ -285,7 +285,7 @@ class CacheTest extends MockedTest
*/
public function testEmptyPassword()
{
$configCache = new Cache([
$configCache = new Cache\Cache([
'database' => [
'password' => '',
'username' => '',
@ -299,7 +299,7 @@ class CacheTest extends MockedTest
public function testWrongTypePassword()
{
$configCache = new Cache([
$configCache = new Cache\Cache([
'database' => [
'password' => new stdClass(),
'username' => '',
@ -309,7 +309,7 @@ class CacheTest extends MockedTest
self::assertNotEmpty($configCache->get('database', 'password'));
self::assertEmpty($configCache->get('database', 'username'));
$configCache = new Cache([
$configCache = new Cache\Cache([
'database' => [
'password' => 23,
'username' => '',
@ -327,19 +327,19 @@ class CacheTest extends MockedTest
public function testSetOverrides($data)
{
$configCache = new Cache();
$configCache->load($data, Cache::SOURCE_DB);
$configCache = new Cache\Cache();
$configCache->load($data, Cache\Cache::SOURCE_DB);
// test with wrong override
self::assertFalse($configCache->set('system', 'test', '1234567', Cache::SOURCE_FILE));
self::assertFalse($configCache->set('system', 'test', '1234567', Cache\Cache::SOURCE_FILE));
self::assertEquals($data['system']['test'], $configCache->get('system', 'test'));
// test with override (equal)
self::assertTrue($configCache->set('system', 'test', '8910', Cache::SOURCE_DB));
self::assertTrue($configCache->set('system', 'test', '8910', Cache\Cache::SOURCE_DB));
self::assertEquals('8910', $configCache->get('system', 'test'));
// test with override (over)
self::assertTrue($configCache->set('system', 'test', '111213', Cache::SOURCE_ENV));
self::assertTrue($configCache->set('system', 'test', '111213', Cache\Cache::SOURCE_ENV));
self::assertEquals('111213', $configCache->get('system', 'test'));
}
}

View file

@ -0,0 +1,389 @@
<?php
/**
* @copyright Copyright (C) 2010-2021, the Friendica project
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
namespace Friendica\Test\src\Core\Config\Cache;
use Friendica\Core\Config\Cache;
use Friendica\Core\Config\Factory\ConfigFactory;
use Friendica\Test\MockedTest;
use Friendica\Test\Util\VFSTrait;
use Friendica\Core\Config\Cache\ConfigFileLoader;
use org\bovigo\vfs\vfsStream;
class ConfigFileLoaderTest extends MockedTest
{
use VFSTrait;
protected function setUp(): void
{
parent::setUp();
$this->setUpVfsDir();
}
/**
* Test the loadConfigFiles() method with default values
*/
public function testLoadConfigFiles()
{
$this->delConfigFile('local.config.php');
$configFileLoader = new ConfigFileLoader(
$this->root->url(),
$this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::CONFIG_DIR,
$this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::STATIC_DIR
);
$configCache = new Cache\Cache();
$configFileLoader->setupCache($configCache);
self::assertEquals($this->root->url(), $configCache->get('system', 'basepath'));
}
/**
* Test the loadConfigFiles() method with a wrong local.config.php
*
*/
public function testLoadConfigWrong()
{
$this->expectExceptionMessageMatches("/Error loading config file \w+/");
$this->expectException(\Exception::class);
$this->delConfigFile('local.config.php');
vfsStream::newFile('local.config.php')
->at($this->root->getChild('config'))
->setContent('<?php return true;');
$configFileLoader = new ConfigFileLoader(
$this->root->url(),
$this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::CONFIG_DIR,
$this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::STATIC_DIR
);
$configCache = new Cache\Cache();
$configFileLoader->setupCache($configCache);
}
/**
* Test the loadConfigFiles() method with a local.config.php file
*/
public function testLoadConfigFilesLocal()
{
$this->delConfigFile('local.config.php');
$file = dirname(__DIR__) . DIRECTORY_SEPARATOR .
'..' . DIRECTORY_SEPARATOR .
'..' . DIRECTORY_SEPARATOR .
'..' . DIRECTORY_SEPARATOR .
'datasets' . DIRECTORY_SEPARATOR .
'config' . DIRECTORY_SEPARATOR .
'A.config.php';
vfsStream::newFile('local.config.php')
->at($this->root->getChild('config'))
->setContent(file_get_contents($file));
$configFileLoader = new ConfigFileLoader(
$this->root->url(),
$this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::CONFIG_DIR,
$this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::STATIC_DIR
);
$configCache = new Cache\Cache();
$configFileLoader->setupCache($configCache);
self::assertEquals('testhost', $configCache->get('database', 'hostname'));
self::assertEquals('testuser', $configCache->get('database', 'username'));
self::assertEquals('testpw', $configCache->get('database', 'password'));
self::assertEquals('testdb', $configCache->get('database', 'database'));
self::assertEquals('admin@test.it', $configCache->get('config', 'admin_email'));
self::assertEquals('Friendica Social Network', $configCache->get('config', 'sitename'));
}
/**
* Test the loadConfigFile() method with a local.ini.php file
*/
public function testLoadConfigFilesINI()
{
$this->delConfigFile('local.config.php');
$file = dirname(__DIR__) . DIRECTORY_SEPARATOR .
'..' . DIRECTORY_SEPARATOR .
'..' . DIRECTORY_SEPARATOR .
'..' . DIRECTORY_SEPARATOR .
'datasets' . DIRECTORY_SEPARATOR .
'config' . DIRECTORY_SEPARATOR .
'A.ini.php';
vfsStream::newFile('local.ini.php')
->at($this->root->getChild('config'))
->setContent(file_get_contents($file));
$configFileLoader = new ConfigFileLoader(
$this->root->url(),
$this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::CONFIG_DIR,
$this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::STATIC_DIR
);
$configCache = new Cache\Cache();
$configFileLoader->setupCache($configCache);
self::assertEquals('testhost', $configCache->get('database', 'hostname'));
self::assertEquals('testuser', $configCache->get('database', 'username'));
self::assertEquals('testpw', $configCache->get('database', 'password'));
self::assertEquals('testdb', $configCache->get('database', 'database'));
self::assertEquals('admin@test.it', $configCache->get('config', 'admin_email'));
}
/**
* Test the loadConfigFile() method with a .htconfig.php file
*/
public function testLoadConfigFilesHtconfig()
{
$this->delConfigFile('local.config.php');
$file = dirname(__DIR__) . DIRECTORY_SEPARATOR .
'..' . DIRECTORY_SEPARATOR .
'..' . DIRECTORY_SEPARATOR .
'..' . DIRECTORY_SEPARATOR .
'datasets' . DIRECTORY_SEPARATOR .
'config' . DIRECTORY_SEPARATOR .
'.htconfig.php';
vfsStream::newFile('.htconfig.php')
->at($this->root)
->setContent(file_get_contents($file));
$configFileLoader = new ConfigFileLoader(
$this->root->url(),
$this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::CONFIG_DIR,
$this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::STATIC_DIR
);
$configCache = new Cache\Cache();
$configFileLoader->setupCache($configCache);
self::assertEquals('testhost', $configCache->get('database', 'hostname'));
self::assertEquals('testuser', $configCache->get('database', 'username'));
self::assertEquals('testpw', $configCache->get('database', 'password'));
self::assertEquals('testdb', $configCache->get('database', 'database'));
self::assertEquals('anotherCharset', $configCache->get('database', 'charset'));
self::assertEquals('/var/run/friendica.pid', $configCache->get('system', 'pidfile'));
self::assertEquals('Europe/Berlin', $configCache->get('system', 'default_timezone'));
self::assertEquals('fr', $configCache->get('system', 'language'));
self::assertEquals('admin@test.it', $configCache->get('config', 'admin_email'));
self::assertEquals('Friendly admin', $configCache->get('config', 'admin_nickname'));
self::assertEquals('/another/php', $configCache->get('config', 'php_path'));
self::assertEquals('999', $configCache->get('config', 'max_import_size'));
self::assertEquals('666', $configCache->get('system', 'maximagesize'));
self::assertEquals('frio,quattro,vier,duepuntozero', $configCache->get('system', 'allowed_themes'));
self::assertEquals('1', $configCache->get('system', 'no_regfullname'));
}
public function testLoadAddonConfig()
{
$structure = [
'addon' => [
'test' => [
'config' => [],
],
],
];
vfsStream::create($structure, $this->root);
$file = dirname(__DIR__) . DIRECTORY_SEPARATOR .
'..' . DIRECTORY_SEPARATOR .
'..' . DIRECTORY_SEPARATOR .
'..' . DIRECTORY_SEPARATOR .
'datasets' . DIRECTORY_SEPARATOR .
'config' . DIRECTORY_SEPARATOR .
'A.config.php';
vfsStream::newFile('test.config.php')
->at($this->root->getChild('addon')->getChild('test')->getChild('config'))
->setContent(file_get_contents($file));
$configFileLoader = new ConfigFileLoader(
$this->root->url(),
$this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::CONFIG_DIR,
$this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::STATIC_DIR
);
$conf = $configFileLoader->loadAddonConfig('test');
self::assertEquals('testhost', $conf['database']['hostname']);
self::assertEquals('testuser', $conf['database']['username']);
self::assertEquals('testpw', $conf['database']['password']);
self::assertEquals('testdb', $conf['database']['database']);
self::assertEquals('admin@test.it', $conf['config']['admin_email']);
}
/**
* test loading multiple config files - the last config should work
*/
public function testLoadMultipleConfigs()
{
$this->delConfigFile('local.config.php');
$fileDir = dirname(__DIR__) . DIRECTORY_SEPARATOR .
'..' . DIRECTORY_SEPARATOR .
'..' . DIRECTORY_SEPARATOR .
'..' . DIRECTORY_SEPARATOR .
'datasets' . DIRECTORY_SEPARATOR .
'config' . DIRECTORY_SEPARATOR;
vfsStream::newFile('A.config.php')
->at($this->root->getChild('config'))
->setContent(file_get_contents($fileDir . 'A.config.php'));
vfsStream::newFile('B.config.php')
->at($this->root->getChild('config'))
->setContent(file_get_contents($fileDir . 'B.config.php'));
$configFileLoader = new ConfigFileLoader(
$this->root->url(),
$this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::CONFIG_DIR,
$this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::STATIC_DIR
);
$configCache = new Cache\Cache();
$configFileLoader->setupCache($configCache);
self::assertEquals('admin@overwritten.local', $configCache->get('config', 'admin_email'));
self::assertEquals('newValue', $configCache->get('system', 'newKey'));
}
/**
* test loading multiple config files - the last config should work (INI-version)
*/
public function testLoadMultipleInis()
{
$this->delConfigFile('local.config.php');
$fileDir = dirname(__DIR__) . DIRECTORY_SEPARATOR .
'..' . DIRECTORY_SEPARATOR .
'..' . DIRECTORY_SEPARATOR .
'..' . DIRECTORY_SEPARATOR .
'datasets' . DIRECTORY_SEPARATOR .
'config' . DIRECTORY_SEPARATOR;
vfsStream::newFile('A.ini.php')
->at($this->root->getChild('config'))
->setContent(file_get_contents($fileDir . 'A.ini.php'));
vfsStream::newFile('B.ini.php')
->at($this->root->getChild('config'))
->setContent(file_get_contents($fileDir . 'B.ini.php'));
$configFileLoader = new ConfigFileLoader(
$this->root->url(),
$this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::CONFIG_DIR,
$this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::STATIC_DIR
);
$configCache = new Cache\Cache();
$configFileLoader->setupCache($configCache);
self::assertEquals('admin@overwritten.local', $configCache->get('config', 'admin_email'));
self::assertEquals('newValue', $configCache->get('system', 'newKey'));
}
/**
* Test that sample-files (e.g. local-sample.config.php) is never loaded
*/
public function testNotLoadingSamples()
{
$this->delConfigFile('local.config.php');
$fileDir = dirname(__DIR__) . DIRECTORY_SEPARATOR .
'..' . DIRECTORY_SEPARATOR .
'..' . DIRECTORY_SEPARATOR .
'..' . DIRECTORY_SEPARATOR .
'datasets' . DIRECTORY_SEPARATOR .
'config' . DIRECTORY_SEPARATOR;
vfsStream::newFile('A.ini.php')
->at($this->root->getChild('config'))
->setContent(file_get_contents($fileDir . 'A.ini.php'));
vfsStream::newFile('B-sample.ini.php')
->at($this->root->getChild('config'))
->setContent(file_get_contents($fileDir . 'B.ini.php'));
$configFileLoader = new ConfigFileLoader(
$this->root->url(),
$this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::CONFIG_DIR,
$this->root->url() . DIRECTORY_SEPARATOR . ConfigFactory::STATIC_DIR
);
$configCache = new Cache\Cache();
$configFileLoader->setupCache($configCache);
self::assertEquals('admin@test.it', $configCache->get('config', 'admin_email'));
self::assertEmpty($configCache->get('system', 'NewKey'));
}
/**
* Test that using a wrong configuration directory leads to the "normal" config path
*/
public function testWrongEnvDir()
{
$this->delConfigFile('local.config.php');
$configFileLoader = (new ConfigFactory())->createConfigFileLoader($this->root->url(), ['FRIENDICA_CONFIG_DIR' => '/a/wrong/dir/']);
$configCache = new Cache\Cache();
$configFileLoader->setupCache($configCache);
self::assertEquals($this->root->url(), $configCache->get('system', 'basepath'));
}
/**
* Test that a different location of the configuration directory produces the expected output
*/
public function testRightEnvDir()
{
$this->delConfigFile('local.config.php');
$fileDir = dirname(__DIR__) . DIRECTORY_SEPARATOR .
'..' . DIRECTORY_SEPARATOR .
'..' . DIRECTORY_SEPARATOR .
'..' . DIRECTORY_SEPARATOR .
'datasets' . DIRECTORY_SEPARATOR .
'config' . DIRECTORY_SEPARATOR;
vfsStream::newFile('B.config.php')
->at($this->root->getChild('config2'))
->setContent(file_get_contents($fileDir . 'B.config.php'));
$configFileLoader = (new ConfigFactory())->createConfigFileLoader($this->root->url(), ['FRIENDICA_CONFIG_DIR' => $this->root->getChild('config2')->url()]);
$configCache = new Cache\Cache();
$configFileLoader->setupCache($configCache);
self::assertEquals('newValue', $configCache->get('system', 'newKey'));
}
}

View file

@ -23,7 +23,7 @@ namespace Friendica\Test\src\Core\Config;
use Friendica\Core\Config\Cache;
use Friendica\Core\Config\IConfig;
use Friendica\Model\Config\Config as ConfigModel;
use Friendica\Core\Config\Model\Config as ConfigModel;
use Friendica\Test\MockedTest;
use Mockery\MockInterface;
use Mockery;
@ -33,7 +33,7 @@ abstract class ConfigTest extends MockedTest
/** @var ConfigModel|MockInterface */
protected $configModel;
/** @var Cache */
/** @var Cache\Cache */
protected $configCache;
/** @var IConfig */
@ -61,7 +61,7 @@ abstract class ConfigTest extends MockedTest
// Create the config model
$this->configModel = Mockery::mock(ConfigModel::class);
$this->configCache = new Cache();
$this->configCache = new Cache\Cache();
}
/**
@ -161,7 +161,7 @@ abstract class ConfigTest extends MockedTest
->once();
$this->testedConfig = $this->getInstance();
self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
self::assertInstanceOf(Cache\Cache::class, $this->testedConfig->getCache());
// assert config is loaded everytime
self::assertConfig('config', $data['config']);
@ -176,7 +176,7 @@ abstract class ConfigTest extends MockedTest
public function testLoad(array $data, array $load)
{
$this->testedConfig = $this->getInstance();
self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
self::assertInstanceOf(Cache\Cache::class, $this->testedConfig->getCache());
foreach ($load as $loadedCats) {
$this->testedConfig->load($loadedCats);
@ -257,7 +257,7 @@ abstract class ConfigTest extends MockedTest
public function testCacheLoadDouble(array $data1, array $data2, array $expect = [])
{
$this->testedConfig = $this->getInstance();
self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
self::assertInstanceOf(Cache\Cache::class, $this->testedConfig->getCache());
foreach ($data1 as $cat => $data) {
$this->testedConfig->load($cat);
@ -282,7 +282,7 @@ abstract class ConfigTest extends MockedTest
$this->configModel->shouldReceive('load')->withAnyArgs()->andReturn([])->once();
$this->testedConfig = $this->getInstance();
self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
self::assertInstanceOf(Cache\Cache::class, $this->testedConfig->getCache());
self::assertEmpty($this->testedConfig->getCache()->getAll());
}
@ -299,7 +299,7 @@ abstract class ConfigTest extends MockedTest
->times(3);
$this->testedConfig = $this->getInstance();
self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
self::assertInstanceOf(Cache\Cache::class, $this->testedConfig->getCache());
self::assertTrue($this->testedConfig->set('test', 'it', $data));
@ -317,7 +317,7 @@ abstract class ConfigTest extends MockedTest
$this->configModel->shouldReceive('set')->with('test', 'it', $data)->andReturn(true)->once();
$this->testedConfig = $this->getInstance();
self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
self::assertInstanceOf(Cache\Cache::class, $this->testedConfig->getCache());
self::assertTrue($this->testedConfig->set('test', 'it', $data));
@ -331,7 +331,7 @@ abstract class ConfigTest extends MockedTest
public function testGetWrongWithoutDB()
{
$this->testedConfig = $this->getInstance();
self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
self::assertInstanceOf(Cache\Cache::class, $this->testedConfig->getCache());
// without refresh
self::assertNull($this->testedConfig->get('test', 'it'));
@ -353,10 +353,10 @@ abstract class ConfigTest extends MockedTest
*/
public function testGetWithRefresh($data)
{
$this->configCache->load(['test' => ['it' => 'now']], Cache::SOURCE_FILE);
$this->configCache->load(['test' => ['it' => 'now']], Cache\Cache::SOURCE_FILE);
$this->testedConfig = $this->getInstance();
self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
self::assertInstanceOf(Cache\Cache::class, $this->testedConfig->getCache());
// without refresh
self::assertEquals('now', $this->testedConfig->get('test', 'it'));
@ -378,10 +378,10 @@ abstract class ConfigTest extends MockedTest
*/
public function testDeleteWithoutDB($data)
{
$this->configCache->load(['test' => ['it' => $data]], Cache::SOURCE_FILE);
$this->configCache->load(['test' => ['it' => $data]], Cache\Cache::SOURCE_FILE);
$this->testedConfig = $this->getInstance();
self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
self::assertInstanceOf(Cache\Cache::class, $this->testedConfig->getCache());
self::assertEquals($data, $this->testedConfig->get('test', 'it'));
self::assertEquals($data, $this->testedConfig->getCache()->get('test', 'it'));
@ -398,7 +398,7 @@ abstract class ConfigTest extends MockedTest
*/
public function testDeleteWithDB()
{
$this->configCache->load(['test' => ['it' => 'now', 'quarter' => 'true']], Cache::SOURCE_FILE);
$this->configCache->load(['test' => ['it' => 'now', 'quarter' => 'true']], Cache\Cache::SOURCE_FILE);
$this->configModel->shouldReceive('delete')
->with('test', 'it')
@ -418,7 +418,7 @@ abstract class ConfigTest extends MockedTest
->once();
$this->testedConfig = $this->getInstance();
self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
self::assertInstanceOf(Cache\Cache::class, $this->testedConfig->getCache());
// directly set the value to the cache
$this->testedConfig->getCache()->set('test', 'it', 'now');
@ -444,9 +444,9 @@ abstract class ConfigTest extends MockedTest
public function testSetGetHighPrio()
{
$this->testedConfig = $this->getInstance();
self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
self::assertInstanceOf(Cache\Cache::class, $this->testedConfig->getCache());
$this->testedConfig->getCache()->set('config', 'test', 'prio', Cache::SOURCE_FILE);
$this->testedConfig->getCache()->set('config', 'test', 'prio', Cache\Cache::SOURCE_FILE);
self::assertEquals('prio', $this->testedConfig->get('config', 'test'));
// now you have to get the new variable entry because of the new set the get refresh succeed as well
@ -460,10 +460,10 @@ abstract class ConfigTest extends MockedTest
public function testSetGetLowPrio()
{
$this->testedConfig = $this->getInstance();
self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
self::assertInstanceOf(Cache\Cache::class, $this->testedConfig->getCache());
self::assertEquals('it', $this->testedConfig->get('config', 'test'));
$this->testedConfig->getCache()->set('config', 'test', 'prio', Cache::SOURCE_ENV);
$this->testedConfig->getCache()->set('config', 'test', 'prio', Cache\Cache::SOURCE_ENV);
// now you have to get the env variable entry as output, even with a new set (which failed) and a get refresh
self::assertFalse($this->testedConfig->set('config', 'test', '123'));
self::assertEquals('prio', $this->testedConfig->get('config', 'test', '', true));

View file

@ -21,7 +21,7 @@
namespace Friendica\Test\src\Core\Config;
use Friendica\Core\Config\JitConfig;
use Friendica\Core\Config\Type\JitConfig;
class JitConfigTest extends ConfigTest
{

View file

@ -21,7 +21,7 @@
namespace Friendica\Test\src\Core\Config;
use Friendica\Core\Config\PreloadConfig;
use Friendica\Core\Config\Type\PreloadConfig;
class PreloadConfigTest extends ConfigTest
{

View file

@ -23,7 +23,7 @@
namespace Friendica\Core;
use Dice\Dice;
use Friendica\Core\Config\Cache;
use Friendica\Core\Config\Cache\Cache;
use Friendica\DI;
use Friendica\Network\IHTTPResult;
use Friendica\Network\IHTTPClient;

View file

@ -22,11 +22,10 @@
namespace Friendica\Test\src\Core\Lock;
use Friendica\Core\Lock\DatabaseLock;
use Friendica\Factory\ConfigFactory;
use Friendica\Core\Config\Factory\ConfigFactory;
use Friendica\Test\DatabaseTestTrait;
use Friendica\Test\Util\Database\StaticDatabase;
use Friendica\Test\Util\VFSTrait;
use Friendica\Util\ConfigFileLoader;
use Friendica\Util\Profiler;
use Mockery;
use Psr\Log\NullLogger;

View file

@ -24,7 +24,7 @@ namespace Friendica\Test\src\Core\Lock;
use Dice\Dice;
use Friendica\App;
use Friendica\Core\Config\IConfig;
use Friendica\Core\Config\JitConfig;
use Friendica\Core\Config\Type\JitConfig;
use Friendica\Core\Lock\SemaphoreLock;
use Friendica\DI;
use Mockery;

View file

@ -19,7 +19,7 @@
*
*/
namespace Friendica\Test\src\Core\PConfig;
namespace Friendica\Test\src\Core\PConfig\Cache;
use Friendica\Core\PConfig\Cache;
use Friendica\Test\MockedTest;
@ -47,7 +47,7 @@ class CacheTest extends MockedTest
];
}
private function assertConfigValues($data, Cache $configCache, $uid)
private function assertConfigValues($data, Cache\Cache $configCache, $uid)
{
foreach ($data as $cat => $values) {
foreach ($values as $key => $value) {
@ -63,7 +63,7 @@ class CacheTest extends MockedTest
*/
public function testSetGet($data)
{
$configCache = new Cache();
$configCache = new Cache\Cache();
$uid = 345;
foreach ($data as $cat => $values) {
@ -81,7 +81,7 @@ class CacheTest extends MockedTest
*/
public function testGetCat()
{
$configCache = new Cache();
$configCache = new Cache\Cache();
$uid = 345;
$configCache->load($uid, [
@ -113,7 +113,7 @@ class CacheTest extends MockedTest
*/
public function testDelete($data)
{
$configCache = new Cache();
$configCache = new Cache\Cache();
$uid = 345;
foreach ($data as $cat => $values) {
@ -136,7 +136,7 @@ class CacheTest extends MockedTest
*/
public function testKeyDiffWithResult()
{
$configCache = new Cache();
$configCache = new Cache\Cache();
$diffConfig = [
'fakeCat' => [
@ -154,7 +154,7 @@ class CacheTest extends MockedTest
*/
public function testKeyDiffWithoutResult($data)
{
$configCache = new Cache();
$configCache = new Cache\Cache();
$configCache->load(1, $data);
@ -168,7 +168,7 @@ class CacheTest extends MockedTest
*/
public function testPasswordHide()
{
$configCache = new Cache();
$configCache = new Cache\Cache();
$configCache->load(1, [
'database' => [
@ -187,7 +187,7 @@ class CacheTest extends MockedTest
*/
public function testPasswordShow()
{
$configCache = new Cache(false);
$configCache = new Cache\Cache(false);
$configCache->load(1, [
'database' => [
@ -206,7 +206,7 @@ class CacheTest extends MockedTest
*/
public function testEmptyPassword()
{
$configCache = new Cache();
$configCache = new Cache\Cache();
$configCache->load(1, [
'database' => [
@ -221,7 +221,7 @@ class CacheTest extends MockedTest
public function testWrongTypePassword()
{
$configCache = new Cache();
$configCache = new Cache\Cache();
$configCache->load(1, [
'database' => [
@ -233,7 +233,7 @@ class CacheTest extends MockedTest
self::assertNotEmpty($configCache->get(1, 'database', 'password'));
self::assertEmpty($configCache->get(1, 'database', 'username'));
$configCache = new Cache();
$configCache = new Cache\Cache();
$configCache->load(1, [
'database' => [
@ -251,7 +251,7 @@ class CacheTest extends MockedTest
*/
public function testTwoUid()
{
$configCache = new Cache();
$configCache = new Cache\Cache();
$configCache->load(1, [
'cat1' => [
@ -282,7 +282,7 @@ class CacheTest extends MockedTest
// bad UID!
$uid = null;
$configCache = new Cache();
$configCache = new Cache\Cache();
self::assertNull($configCache->get($uid, 'cat1', 'cat2'));

View file

@ -21,7 +21,7 @@
namespace Friendica\Test\src\Core\PConfig;
use Friendica\Core\PConfig\JitPConfig;
use Friendica\Core\PConfig\Type\JitPConfig;
class JitPConfigTest extends PConfigTest
{

View file

@ -22,8 +22,8 @@
namespace Friendica\Test\src\Core\PConfig;
use Friendica\Core\PConfig\Cache;
use Friendica\Core\BasePConfig;
use Friendica\Model\Config\PConfig as PConfigModel;
use Friendica\Core\PConfig\Type\BasePConfig;
use Friendica\Core\PConfig\Model\PConfig as PConfigModel;
use Friendica\Test\MockedTest;
use Mockery;
use Mockery\MockInterface;
@ -33,7 +33,7 @@ abstract class PConfigTest extends MockedTest
/** @var PConfigModel|MockInterface */
protected $configModel;
/** @var Cache */
/** @var Cache\Cache */
protected $configCache;
/** @var BasePConfig */
@ -63,11 +63,11 @@ abstract class PConfigTest extends MockedTest
// Create the config model
$this->configModel = Mockery::mock(PConfigModel::class);
$this->configCache = new Cache();
$this->configCache = new Cache\Cache();
}
/**
* @return BasePConfig
* @return \Friendica\Core\PConfig\Type\BasePConfig
*/
abstract public function getInstance();
@ -163,7 +163,7 @@ abstract class PConfigTest extends MockedTest
public function testSetUp()
{
$this->testedConfig = $this->getInstance();
self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
self::assertInstanceOf(Cache\Cache::class, $this->testedConfig->getCache());
self::assertEmpty($this->testedConfig->getCache()->getAll());
}
@ -174,7 +174,7 @@ abstract class PConfigTest extends MockedTest
public function testLoad(int $uid, array $data, array $possibleCats, array $load)
{
$this->testedConfig = $this->getInstance();
self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
self::assertInstanceOf(Cache\Cache::class, $this->testedConfig->getCache());
foreach ($load as $loadedCats) {
$this->testedConfig->load($uid, $loadedCats);
@ -257,7 +257,7 @@ abstract class PConfigTest extends MockedTest
public function testCacheLoadDouble(int $uid, array $data1, array $data2, array $expect)
{
$this->testedConfig = $this->getInstance();
self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
self::assertInstanceOf(Cache\Cache::class, $this->testedConfig->getCache());
foreach ($data1 as $cat => $data) {
$this->testedConfig->load($uid, $cat);
@ -281,7 +281,7 @@ abstract class PConfigTest extends MockedTest
public function testSetGetWithoutDB(int $uid, $data)
{
$this->testedConfig = $this->getInstance();
self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
self::assertInstanceOf(Cache\Cache::class, $this->testedConfig->getCache());
self::assertTrue($this->testedConfig->set($uid, 'test', 'it', $data));
@ -302,7 +302,7 @@ abstract class PConfigTest extends MockedTest
->once();
$this->testedConfig = $this->getInstance();
self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
self::assertInstanceOf(Cache\Cache::class, $this->testedConfig->getCache());
self::assertTrue($this->testedConfig->set($uid, 'test', 'it', $data));
@ -316,7 +316,7 @@ abstract class PConfigTest extends MockedTest
public function testGetWrongWithoutDB()
{
$this->testedConfig = $this->getInstance();
self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
self::assertInstanceOf(Cache\Cache::class, $this->testedConfig->getCache());
// without refresh
self::assertNull($this->testedConfig->get(0, 'test', 'it'));
@ -341,7 +341,7 @@ abstract class PConfigTest extends MockedTest
$this->configCache->load($uid, ['test' => ['it' => 'now']]);
$this->testedConfig = $this->getInstance();
self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
self::assertInstanceOf(Cache\Cache::class, $this->testedConfig->getCache());
// without refresh
self::assertEquals('now', $this->testedConfig->get($uid, 'test', 'it'));
@ -366,7 +366,7 @@ abstract class PConfigTest extends MockedTest
$this->configCache->load($uid, ['test' => ['it' => $data]]);
$this->testedConfig = $this->getInstance();
self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
self::assertInstanceOf(Cache\Cache::class, $this->testedConfig->getCache());
self::assertEquals($data, $this->testedConfig->get($uid, 'test', 'it'));
self::assertEquals($data, $this->testedConfig->getCache()->get($uid, 'test', 'it'));
@ -405,7 +405,7 @@ abstract class PConfigTest extends MockedTest
->once();
$this->testedConfig = $this->getInstance();
self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
self::assertInstanceOf(Cache\Cache::class, $this->testedConfig->getCache());
// directly set the value to the cache
$this->testedConfig->getCache()->set($uid, 'test', 'it', 'now');
@ -465,7 +465,7 @@ abstract class PConfigTest extends MockedTest
$this->configCache->load($data2['uid'], $data2['data']);
$this->testedConfig = $this->getInstance();
self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
self::assertInstanceOf(Cache\Cache::class, $this->testedConfig->getCache());
self::assertConfig($data1['uid'], 'cat1', $data1['data']['cat1']);
self::assertConfig($data1['uid'], 'cat2', $data1['data']['cat2']);

View file

@ -21,13 +21,13 @@
namespace Friendica\Test\src\Core\PConfig;
use Friendica\Core\PConfig\PreloadPConfig;
use Friendica\Core\PConfig\Type\PreloadPConfig;
class PreloadPConfigTest extends PConfigTest
{
public function getInstance()
{
return new PreloadPConfig($this->configCache, $this->configModel);
return new \Friendica\Core\PConfig\Type\PreloadPConfig($this->configCache, $this->configModel);
}
/**

View file

@ -23,22 +23,22 @@ namespace Friendica\Test\src\Core;
use Dice\Dice;
use Friendica\Core\Config\IConfig;
use Friendica\Core\Config\PreloadConfig;
use Friendica\Core\Config\Type\PreloadConfig;
use Friendica\Core\Hook;
use Friendica\Core\L10n;
use Friendica\Core\Session\ISession;
use Friendica\Core\StorageManager;
use Friendica\Database\Database;
use Friendica\DI;
use Friendica\Factory\ConfigFactory;
use Friendica\Model\Config\Config;
use Friendica\Core\Config\Factory\ConfigFactory;
use Friendica\Core\Config\Model\Config;
use Friendica\Model\Storage;
use Friendica\Core\Session;
use Friendica\Network\HTTPClient;
use Friendica\Test\DatabaseTest;
use Friendica\Test\Util\Database\StaticDatabase;
use Friendica\Test\Util\VFSTrait;
use Friendica\Util\ConfigFileLoader;
use Friendica\Core\Config\Cache\ConfigFileLoader;
use Friendica\Util\Profiler;
use org\bovigo\vfs\vfsStream;
use Psr\Log\LoggerInterface;