Some improvements
- Move $_SERVER into ConfigFileManager constructor - Rename "creatConfigFileLoader" to "createConfigFileManager" - Rename variable "loader" to "manager" in all tests
This commit is contained in:
parent
b4096251ba
commit
cdd57275eb
|
@ -359,7 +359,7 @@ class App
|
||||||
$this->profiler->update($this->config);
|
$this->profiler->update($this->config);
|
||||||
|
|
||||||
Core\Hook::loadHooks();
|
Core\Hook::loadHooks();
|
||||||
$loader = (new Config())->createConfigFileLoader($this->getBasePath(), $_SERVER);
|
$loader = (new Config())->createConfigFileManager($this->getBasePath(), $_SERVER);
|
||||||
Core\Hook::callAll('load_config', $loader);
|
Core\Hook::callAll('load_config', $loader);
|
||||||
|
|
||||||
// Hooks are now working, reload the whole definitions with hook enabled
|
// Hooks are now working, reload the whole definitions with hook enabled
|
||||||
|
|
|
@ -56,7 +56,7 @@ class Config
|
||||||
*
|
*
|
||||||
* @return Util\ConfigFileManager
|
* @return Util\ConfigFileManager
|
||||||
*/
|
*/
|
||||||
public function createConfigFileLoader(string $basePath, array $server = []): Util\ConfigFileManager
|
public function createConfigFileManager(string $basePath, array $server = []): Util\ConfigFileManager
|
||||||
{
|
{
|
||||||
if (!empty($server[self::CONFIG_DIR_ENV]) && is_dir($server[self::CONFIG_DIR_ENV])) {
|
if (!empty($server[self::CONFIG_DIR_ENV]) && is_dir($server[self::CONFIG_DIR_ENV])) {
|
||||||
$configDir = $server[self::CONFIG_DIR_ENV];
|
$configDir = $server[self::CONFIG_DIR_ENV];
|
||||||
|
@ -65,19 +65,18 @@ class Config
|
||||||
}
|
}
|
||||||
$staticDir = $basePath . DIRECTORY_SEPARATOR . self::STATIC_DIR;
|
$staticDir = $basePath . DIRECTORY_SEPARATOR . self::STATIC_DIR;
|
||||||
|
|
||||||
return new Util\ConfigFileManager($basePath, $configDir, $staticDir, new Util\ConfigFileTransformer());
|
return new Util\ConfigFileManager($basePath, $configDir, $staticDir, $server);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Util\ConfigFileManager $configFileManager The Config Cache manager (INI/config/.htconfig)
|
* @param Util\ConfigFileManager $configFileManager The Config Cache manager (INI/config/.htconfig)
|
||||||
* @param array $server
|
|
||||||
*
|
*
|
||||||
* @return Cache
|
* @return Cache
|
||||||
*/
|
*/
|
||||||
public function createCache(Util\ConfigFileManager $configFileManager, array $server = []): Cache
|
public function createCache(Util\ConfigFileManager $configFileManager): Cache
|
||||||
{
|
{
|
||||||
$configCache = new Cache();
|
$configCache = new Cache();
|
||||||
$configFileManager->setupCache($configCache, $server);
|
$configFileManager->setupCache($configCache);
|
||||||
|
|
||||||
return $configCache;
|
return $configCache;
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,19 +39,14 @@ class Config implements IManageConfigValues
|
||||||
/** @var ConfigFileManager */
|
/** @var ConfigFileManager */
|
||||||
protected $configFileManager;
|
protected $configFileManager;
|
||||||
|
|
||||||
/** @var array */
|
|
||||||
protected $server;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param ConfigFileManager $configFileManager The configuration file manager to save back configs
|
* @param ConfigFileManager $configFileManager The configuration file manager to save back configs
|
||||||
* @param Cache $configCache The configuration cache (based on the config-files)
|
* @param Cache $configCache The configuration cache (based on the config-files)
|
||||||
* @param array $server The $_SERVER variable
|
|
||||||
*/
|
*/
|
||||||
public function __construct(ConfigFileManager $configFileManager, Cache $configCache, array $server = [])
|
public function __construct(ConfigFileManager $configFileManager, Cache $configCache)
|
||||||
{
|
{
|
||||||
$this->configFileManager = $configFileManager;
|
$this->configFileManager = $configFileManager;
|
||||||
$this->configCache = $configCache;
|
$this->configCache = $configCache;
|
||||||
$this->server = $server;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -87,7 +82,7 @@ class Config implements IManageConfigValues
|
||||||
$configCache = new Cache();
|
$configCache = new Cache();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$this->configFileManager->setupCache($configCache, $this->server);
|
$this->configFileManager->setupCache($configCache);
|
||||||
} catch (ConfigFileException $e) {
|
} catch (ConfigFileException $e) {
|
||||||
throw new ConfigPersistenceException('Cannot reload config', $e);
|
throw new ConfigPersistenceException('Cannot reload config', $e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,16 +69,22 @@ class ConfigFileManager
|
||||||
*/
|
*/
|
||||||
private $staticDir;
|
private $staticDir;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
private $server;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $baseDir The base
|
* @param string $baseDir The base
|
||||||
* @param string $configDir
|
* @param string $configDir
|
||||||
* @param string $staticDir
|
* @param string $staticDir
|
||||||
*/
|
*/
|
||||||
public function __construct(string $baseDir, string $configDir, string $staticDir)
|
public function __construct(string $baseDir, string $configDir, string $staticDir, array $server = [])
|
||||||
{
|
{
|
||||||
$this->baseDir = $baseDir;
|
$this->baseDir = $baseDir;
|
||||||
$this->configDir = $configDir;
|
$this->configDir = $configDir;
|
||||||
$this->staticDir = $staticDir;
|
$this->staticDir = $staticDir;
|
||||||
|
$this->server = $server;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -88,12 +94,11 @@ class ConfigFileManager
|
||||||
* expected local.config.php
|
* expected local.config.php
|
||||||
*
|
*
|
||||||
* @param Cache $config The config cache to load to
|
* @param Cache $config The config cache to load to
|
||||||
* @param array $server The $_SERVER array
|
|
||||||
* @param bool $raw Set up the raw config format
|
* @param bool $raw Set up the raw config format
|
||||||
*
|
*
|
||||||
* @throws ConfigFileException
|
* @throws ConfigFileException
|
||||||
*/
|
*/
|
||||||
public function setupCache(Cache $config, array $server = [], bool $raw = false)
|
public function setupCache(Cache $config, bool $raw = false)
|
||||||
{
|
{
|
||||||
// Load static config files first, the order is important
|
// Load static config files first, the order is important
|
||||||
$config->load($this->loadStaticConfig('defaults'), Cache::SOURCE_STATIC);
|
$config->load($this->loadStaticConfig('defaults'), Cache::SOURCE_STATIC);
|
||||||
|
@ -109,7 +114,7 @@ class ConfigFileManager
|
||||||
// Now load the node.config.php file with the node specific config values (based on admin gui/console actions)
|
// Now load the node.config.php file with the node specific config values (based on admin gui/console actions)
|
||||||
$this->loadDataConfig($config);
|
$this->loadDataConfig($config);
|
||||||
|
|
||||||
$config->load($this->loadEnvConfig($server), Cache::SOURCE_ENV);
|
$config->load($this->loadEnvConfig(), Cache::SOURCE_ENV);
|
||||||
|
|
||||||
// In case of install mode, add the found basepath (because there isn't a basepath set yet
|
// In case of install mode, add the found basepath (because there isn't a basepath set yet
|
||||||
if (!$raw && empty($config->get('system', 'basepath'))) {
|
if (!$raw && empty($config->get('system', 'basepath'))) {
|
||||||
|
@ -250,13 +255,11 @@ class ConfigFileManager
|
||||||
/**
|
/**
|
||||||
* Tries to load environment specific variables, based on the `env.config.php` mapping table
|
* Tries to load environment specific variables, based on the `env.config.php` mapping table
|
||||||
*
|
*
|
||||||
* @param array $server The $_SERVER variable
|
|
||||||
*
|
|
||||||
* @return array The config array (empty if no config was found)
|
* @return array The config array (empty if no config was found)
|
||||||
*
|
*
|
||||||
* @throws ConfigFileException if the configuration file isn't readable
|
* @throws ConfigFileException if the configuration file isn't readable
|
||||||
*/
|
*/
|
||||||
public function loadEnvConfig(array $server): array
|
protected function loadEnvConfig(): array
|
||||||
{
|
{
|
||||||
$filepath = $this->staticDir . DIRECTORY_SEPARATOR . // /var/www/html/static/
|
$filepath = $this->staticDir . DIRECTORY_SEPARATOR . // /var/www/html/static/
|
||||||
"env.config.php"; // env.config.php
|
"env.config.php"; // env.config.php
|
||||||
|
@ -270,8 +273,8 @@ class ConfigFileManager
|
||||||
$return = [];
|
$return = [];
|
||||||
|
|
||||||
foreach ($envConfig as $envKey => $configStructure) {
|
foreach ($envConfig as $envKey => $configStructure) {
|
||||||
if (isset($server[$envKey])) {
|
if (isset($this->server[$envKey])) {
|
||||||
$return[$configStructure[0]][$configStructure[1]] = $server[$envKey];
|
$return[$configStructure[0]][$configStructure[1]] = $this->server[$envKey];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -296,7 +299,9 @@ class ConfigFileManager
|
||||||
$sampleEnd = self::SAMPLE_END . ($ini ? '.ini.php' : '.config.php');
|
$sampleEnd = self::SAMPLE_END . ($ini ? '.ini.php' : '.config.php');
|
||||||
|
|
||||||
foreach ($files as $filename) {
|
foreach ($files as $filename) {
|
||||||
if (fnmatch($filePattern, $filename) && substr_compare($filename, $sampleEnd, -strlen($sampleEnd))) {
|
if (fnmatch($filePattern, $filename) &&
|
||||||
|
substr_compare($filename, $sampleEnd, -strlen($sampleEnd)) &&
|
||||||
|
$filename !== self::CONFIG_DATA_FILE) {
|
||||||
$found[] = $this->configDir . '/' . $filename;
|
$found[] = $this->configDir . '/' . $filename;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -154,7 +154,7 @@ class Summary extends BaseAdmin
|
||||||
}
|
}
|
||||||
|
|
||||||
// check legacy basepath settings
|
// check legacy basepath settings
|
||||||
$configLoader = (new Config())->createConfigFileLoader($a->getBasePath(), $_SERVER);
|
$configLoader = (new Config())->createConfigFileManager($a->getBasePath(), $_SERVER);
|
||||||
$configCache = new Cache();
|
$configCache = new Cache();
|
||||||
$configLoader->setupCache($configCache);
|
$configLoader->setupCache($configCache);
|
||||||
$confBasepath = $configCache->get('system', 'basepath');
|
$confBasepath = $configCache->get('system', 'basepath');
|
||||||
|
|
|
@ -79,7 +79,7 @@ return [
|
||||||
Config\Util\ConfigFileManager::class => [
|
Config\Util\ConfigFileManager::class => [
|
||||||
'instanceOf' => Config\Factory\Config::class,
|
'instanceOf' => Config\Factory\Config::class,
|
||||||
'call' => [
|
'call' => [
|
||||||
['createConfigFileLoader', [
|
['createConfigFileManager', [
|
||||||
[Dice::INSTANCE => '$basepath'],
|
[Dice::INSTANCE => '$basepath'],
|
||||||
$_SERVER,
|
$_SERVER,
|
||||||
], Dice::CHAIN_CALL],
|
], Dice::CHAIN_CALL],
|
||||||
|
@ -88,7 +88,7 @@ return [
|
||||||
Config\ValueObject\Cache::class => [
|
Config\ValueObject\Cache::class => [
|
||||||
'instanceOf' => Config\Factory\Config::class,
|
'instanceOf' => Config\Factory\Config::class,
|
||||||
'call' => [
|
'call' => [
|
||||||
['createCache', [$_SERVER], Dice::CHAIN_CALL],
|
['createCache', [], Dice::CHAIN_CALL],
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
App\Mode::class => [
|
App\Mode::class => [
|
||||||
|
|
|
@ -62,7 +62,7 @@ abstract class FixtureTest extends DatabaseTest
|
||||||
->addRules(include __DIR__ . '/../static/dependencies.config.php')
|
->addRules(include __DIR__ . '/../static/dependencies.config.php')
|
||||||
->addRule(ConfigFileManager::class, [
|
->addRule(ConfigFileManager::class, [
|
||||||
'instanceOf' => Config::class,
|
'instanceOf' => Config::class,
|
||||||
'call' => [['createConfigFileLoader', [$this->root->url(), $server,],
|
'call' => [['createConfigFileManager', [$this->root->url(), $server,],
|
||||||
Dice::CHAIN_CALL]]])
|
Dice::CHAIN_CALL]]])
|
||||||
->addRule(Database::class, ['instanceOf' => StaticDatabase::class, 'shared' => true])
|
->addRule(Database::class, ['instanceOf' => StaticDatabase::class, 'shared' => true])
|
||||||
->addRule(IHandleSessions::class, ['instanceOf' => Memory::class, 'shared' => true, 'call' => null])
|
->addRule(IHandleSessions::class, ['instanceOf' => Memory::class, 'shared' => true, 'call' => null])
|
||||||
|
|
|
@ -54,11 +54,11 @@ class DatabaseCacheTest extends CacheTest
|
||||||
$profiler->shouldReceive('saveTimestamp')->withAnyArgs()->andReturn(true);
|
$profiler->shouldReceive('saveTimestamp')->withAnyArgs()->andReturn(true);
|
||||||
|
|
||||||
// load real config to avoid mocking every config-entry which is related to the Database class
|
// load real config to avoid mocking every config-entry which is related to the Database class
|
||||||
$configFactory = new Config();
|
$configFactory = new Config();
|
||||||
$loader = (new Config())->createConfigFileLoader($this->root->url(), []);
|
$configFileManager = (new Config())->createConfigFileManager($this->root->url(), []);
|
||||||
$configCache = $configFactory->createCache($loader);
|
$configCache = $configFactory->createCache($configFileManager);
|
||||||
|
|
||||||
$dbaDefinition = (new DbaDefinition($configCache->get('system', 'basepath')))->load();
|
$dbaDefinition = (new DbaDefinition($configCache->get('system', 'basepath')))->load();
|
||||||
$viewDefinition = (new ViewDefinition($configCache->get('system', 'basepath')))->load();
|
$viewDefinition = (new ViewDefinition($configCache->get('system', 'basepath')))->load();
|
||||||
|
|
||||||
$dba = new StaticDatabase($configCache, $profiler, $dbaDefinition, $viewDefinition);
|
$dba = new StaticDatabase($configCache, $profiler, $dbaDefinition, $viewDefinition);
|
||||||
|
|
|
@ -51,6 +51,7 @@ class ConfigFileManagerTest extends MockedTest
|
||||||
$this->root->url() . DIRECTORY_SEPARATOR . Config::CONFIG_DIR,
|
$this->root->url() . DIRECTORY_SEPARATOR . Config::CONFIG_DIR,
|
||||||
$this->root->url() . DIRECTORY_SEPARATOR . Config::STATIC_DIR
|
$this->root->url() . DIRECTORY_SEPARATOR . Config::STATIC_DIR
|
||||||
);
|
);
|
||||||
|
|
||||||
$configCache = new Cache();
|
$configCache = new Cache();
|
||||||
|
|
||||||
$configFileLoader->setupCache($configCache);
|
$configFileLoader->setupCache($configCache);
|
||||||
|
@ -69,15 +70,15 @@ class ConfigFileManagerTest extends MockedTest
|
||||||
$this->delConfigFile('local.config.php');
|
$this->delConfigFile('local.config.php');
|
||||||
|
|
||||||
vfsStream::newFile('local.config.php')
|
vfsStream::newFile('local.config.php')
|
||||||
->at($this->root->getChild('config'))
|
->at($this->root->getChild('config'))
|
||||||
->setContent('<?php return true;');
|
->setContent('<?php return true;');
|
||||||
|
|
||||||
$configFileLoader = new ConfigFileManager(
|
$configFileLoader = new ConfigFileManager(
|
||||||
$this->root->url(),
|
$this->root->url(),
|
||||||
$this->root->url() . DIRECTORY_SEPARATOR . Config::CONFIG_DIR,
|
$this->root->url() . DIRECTORY_SEPARATOR . Config::CONFIG_DIR,
|
||||||
$this->root->url() . DIRECTORY_SEPARATOR . Config::STATIC_DIR
|
$this->root->url() . DIRECTORY_SEPARATOR . Config::STATIC_DIR
|
||||||
);
|
);
|
||||||
$configCache = new Cache();
|
$configCache = new Cache();
|
||||||
|
|
||||||
$configFileLoader->setupCache($configCache);
|
$configFileLoader->setupCache($configCache);
|
||||||
}
|
}
|
||||||
|
@ -90,23 +91,23 @@ class ConfigFileManagerTest extends MockedTest
|
||||||
$this->delConfigFile('local.config.php');
|
$this->delConfigFile('local.config.php');
|
||||||
|
|
||||||
$file = dirname(__DIR__) . DIRECTORY_SEPARATOR .
|
$file = dirname(__DIR__) . DIRECTORY_SEPARATOR .
|
||||||
'..' . DIRECTORY_SEPARATOR .
|
'..' . DIRECTORY_SEPARATOR .
|
||||||
'..' . DIRECTORY_SEPARATOR .
|
'..' . DIRECTORY_SEPARATOR .
|
||||||
'..' . DIRECTORY_SEPARATOR .
|
'..' . DIRECTORY_SEPARATOR .
|
||||||
'datasets' . DIRECTORY_SEPARATOR .
|
'datasets' . DIRECTORY_SEPARATOR .
|
||||||
'config' . DIRECTORY_SEPARATOR .
|
'config' . DIRECTORY_SEPARATOR .
|
||||||
'A.config.php';
|
'A.config.php';
|
||||||
|
|
||||||
vfsStream::newFile('local.config.php')
|
vfsStream::newFile('local.config.php')
|
||||||
->at($this->root->getChild('config'))
|
->at($this->root->getChild('config'))
|
||||||
->setContent(file_get_contents($file));
|
->setContent(file_get_contents($file));
|
||||||
|
|
||||||
$configFileLoader = new ConfigFileManager(
|
$configFileLoader = new ConfigFileManager(
|
||||||
$this->root->url(),
|
$this->root->url(),
|
||||||
$this->root->url() . DIRECTORY_SEPARATOR . Config::CONFIG_DIR,
|
$this->root->url() . DIRECTORY_SEPARATOR . Config::CONFIG_DIR,
|
||||||
$this->root->url() . DIRECTORY_SEPARATOR . Config::STATIC_DIR
|
$this->root->url() . DIRECTORY_SEPARATOR . Config::STATIC_DIR
|
||||||
);
|
);
|
||||||
$configCache = new Cache();
|
$configCache = new Cache();
|
||||||
|
|
||||||
$configFileLoader->setupCache($configCache);
|
$configFileLoader->setupCache($configCache);
|
||||||
|
|
||||||
|
@ -127,23 +128,23 @@ class ConfigFileManagerTest extends MockedTest
|
||||||
$this->delConfigFile('local.config.php');
|
$this->delConfigFile('local.config.php');
|
||||||
|
|
||||||
$file = dirname(__DIR__) . DIRECTORY_SEPARATOR .
|
$file = dirname(__DIR__) . DIRECTORY_SEPARATOR .
|
||||||
'..' . DIRECTORY_SEPARATOR .
|
'..' . DIRECTORY_SEPARATOR .
|
||||||
'..' . DIRECTORY_SEPARATOR .
|
'..' . DIRECTORY_SEPARATOR .
|
||||||
'..' . DIRECTORY_SEPARATOR .
|
'..' . DIRECTORY_SEPARATOR .
|
||||||
'datasets' . DIRECTORY_SEPARATOR .
|
'datasets' . DIRECTORY_SEPARATOR .
|
||||||
'config' . DIRECTORY_SEPARATOR .
|
'config' . DIRECTORY_SEPARATOR .
|
||||||
'A.ini.php';
|
'A.ini.php';
|
||||||
|
|
||||||
vfsStream::newFile('local.ini.php')
|
vfsStream::newFile('local.ini.php')
|
||||||
->at($this->root->getChild('config'))
|
->at($this->root->getChild('config'))
|
||||||
->setContent(file_get_contents($file));
|
->setContent(file_get_contents($file));
|
||||||
|
|
||||||
$configFileLoader = new ConfigFileManager(
|
$configFileLoader = new ConfigFileManager(
|
||||||
$this->root->url(),
|
$this->root->url(),
|
||||||
$this->root->url() . DIRECTORY_SEPARATOR . Config::CONFIG_DIR,
|
$this->root->url() . DIRECTORY_SEPARATOR . Config::CONFIG_DIR,
|
||||||
$this->root->url() . DIRECTORY_SEPARATOR . Config::STATIC_DIR
|
$this->root->url() . DIRECTORY_SEPARATOR . Config::STATIC_DIR
|
||||||
);
|
);
|
||||||
$configCache = new Cache();
|
$configCache = new Cache();
|
||||||
|
|
||||||
$configFileLoader->setupCache($configCache);
|
$configFileLoader->setupCache($configCache);
|
||||||
|
|
||||||
|
@ -163,23 +164,23 @@ class ConfigFileManagerTest extends MockedTest
|
||||||
$this->delConfigFile('local.config.php');
|
$this->delConfigFile('local.config.php');
|
||||||
|
|
||||||
$file = dirname(__DIR__) . DIRECTORY_SEPARATOR .
|
$file = dirname(__DIR__) . DIRECTORY_SEPARATOR .
|
||||||
'..' . DIRECTORY_SEPARATOR .
|
'..' . DIRECTORY_SEPARATOR .
|
||||||
'..' . DIRECTORY_SEPARATOR .
|
'..' . DIRECTORY_SEPARATOR .
|
||||||
'..' . DIRECTORY_SEPARATOR .
|
'..' . DIRECTORY_SEPARATOR .
|
||||||
'datasets' . DIRECTORY_SEPARATOR .
|
'datasets' . DIRECTORY_SEPARATOR .
|
||||||
'config' . DIRECTORY_SEPARATOR .
|
'config' . DIRECTORY_SEPARATOR .
|
||||||
'.htconfig.php';
|
'.htconfig.php';
|
||||||
|
|
||||||
vfsStream::newFile('.htconfig.php')
|
vfsStream::newFile('.htconfig.php')
|
||||||
->at($this->root)
|
->at($this->root)
|
||||||
->setContent(file_get_contents($file));
|
->setContent(file_get_contents($file));
|
||||||
|
|
||||||
$configFileLoader = new ConfigFileManager(
|
$configFileLoader = new ConfigFileManager(
|
||||||
$this->root->url(),
|
$this->root->url(),
|
||||||
$this->root->url() . DIRECTORY_SEPARATOR . Config::CONFIG_DIR,
|
$this->root->url() . DIRECTORY_SEPARATOR . Config::CONFIG_DIR,
|
||||||
$this->root->url() . DIRECTORY_SEPARATOR . Config::STATIC_DIR
|
$this->root->url() . DIRECTORY_SEPARATOR . Config::STATIC_DIR
|
||||||
);
|
);
|
||||||
$configCache = new Cache();
|
$configCache = new Cache();
|
||||||
|
|
||||||
$configFileLoader->setupCache($configCache);
|
$configFileLoader->setupCache($configCache);
|
||||||
|
|
||||||
|
@ -217,16 +218,16 @@ class ConfigFileManagerTest extends MockedTest
|
||||||
vfsStream::create($structure, $this->root);
|
vfsStream::create($structure, $this->root);
|
||||||
|
|
||||||
$file = dirname(__DIR__) . DIRECTORY_SEPARATOR .
|
$file = dirname(__DIR__) . DIRECTORY_SEPARATOR .
|
||||||
'..' . DIRECTORY_SEPARATOR .
|
'..' . DIRECTORY_SEPARATOR .
|
||||||
'..' . DIRECTORY_SEPARATOR .
|
'..' . DIRECTORY_SEPARATOR .
|
||||||
'..' . DIRECTORY_SEPARATOR .
|
'..' . DIRECTORY_SEPARATOR .
|
||||||
'datasets' . DIRECTORY_SEPARATOR .
|
'datasets' . DIRECTORY_SEPARATOR .
|
||||||
'config' . DIRECTORY_SEPARATOR .
|
'config' . DIRECTORY_SEPARATOR .
|
||||||
'A.config.php';
|
'A.config.php';
|
||||||
|
|
||||||
vfsStream::newFile('test.config.php')
|
vfsStream::newFile('test.config.php')
|
||||||
->at($this->root->getChild('addon')->getChild('test')->getChild('config'))
|
->at($this->root->getChild('addon')->getChild('test')->getChild('config'))
|
||||||
->setContent(file_get_contents($file));
|
->setContent(file_get_contents($file));
|
||||||
|
|
||||||
$configFileLoader = new ConfigFileManager(
|
$configFileLoader = new ConfigFileManager(
|
||||||
$this->root->url(),
|
$this->root->url(),
|
||||||
|
@ -252,25 +253,25 @@ class ConfigFileManagerTest extends MockedTest
|
||||||
$this->delConfigFile('local.config.php');
|
$this->delConfigFile('local.config.php');
|
||||||
|
|
||||||
$fileDir = dirname(__DIR__) . DIRECTORY_SEPARATOR .
|
$fileDir = dirname(__DIR__) . DIRECTORY_SEPARATOR .
|
||||||
'..' . DIRECTORY_SEPARATOR .
|
'..' . DIRECTORY_SEPARATOR .
|
||||||
'..' . DIRECTORY_SEPARATOR .
|
'..' . DIRECTORY_SEPARATOR .
|
||||||
'..' . DIRECTORY_SEPARATOR .
|
'..' . DIRECTORY_SEPARATOR .
|
||||||
'datasets' . DIRECTORY_SEPARATOR .
|
'datasets' . DIRECTORY_SEPARATOR .
|
||||||
'config' . DIRECTORY_SEPARATOR;
|
'config' . DIRECTORY_SEPARATOR;
|
||||||
|
|
||||||
vfsStream::newFile('A.config.php')
|
vfsStream::newFile('A.config.php')
|
||||||
->at($this->root->getChild('config'))
|
->at($this->root->getChild('config'))
|
||||||
->setContent(file_get_contents($fileDir . 'A.config.php'));
|
->setContent(file_get_contents($fileDir . 'A.config.php'));
|
||||||
vfsStream::newFile('B.config.php')
|
vfsStream::newFile('B.config.php')
|
||||||
->at($this->root->getChild('config'))
|
->at($this->root->getChild('config'))
|
||||||
->setContent(file_get_contents($fileDir . 'B.config.php'));
|
->setContent(file_get_contents($fileDir . 'B.config.php'));
|
||||||
|
|
||||||
$configFileLoader = new ConfigFileManager(
|
$configFileLoader = new ConfigFileManager(
|
||||||
$this->root->url(),
|
$this->root->url(),
|
||||||
$this->root->url() . DIRECTORY_SEPARATOR . Config::CONFIG_DIR,
|
$this->root->url() . DIRECTORY_SEPARATOR . Config::CONFIG_DIR,
|
||||||
$this->root->url() . DIRECTORY_SEPARATOR . Config::STATIC_DIR
|
$this->root->url() . DIRECTORY_SEPARATOR . Config::STATIC_DIR
|
||||||
);
|
);
|
||||||
$configCache = new Cache();
|
$configCache = new Cache();
|
||||||
|
|
||||||
$configFileLoader->setupCache($configCache);
|
$configFileLoader->setupCache($configCache);
|
||||||
|
|
||||||
|
@ -286,25 +287,25 @@ class ConfigFileManagerTest extends MockedTest
|
||||||
$this->delConfigFile('local.config.php');
|
$this->delConfigFile('local.config.php');
|
||||||
|
|
||||||
$fileDir = dirname(__DIR__) . DIRECTORY_SEPARATOR .
|
$fileDir = dirname(__DIR__) . DIRECTORY_SEPARATOR .
|
||||||
'..' . DIRECTORY_SEPARATOR .
|
|
||||||
'..' . DIRECTORY_SEPARATOR .
|
|
||||||
'..' . DIRECTORY_SEPARATOR .
|
'..' . DIRECTORY_SEPARATOR .
|
||||||
'datasets' . DIRECTORY_SEPARATOR .
|
'..' . DIRECTORY_SEPARATOR .
|
||||||
'config' . DIRECTORY_SEPARATOR;
|
'..' . DIRECTORY_SEPARATOR .
|
||||||
|
'datasets' . DIRECTORY_SEPARATOR .
|
||||||
|
'config' . DIRECTORY_SEPARATOR;
|
||||||
|
|
||||||
vfsStream::newFile('A.ini.php')
|
vfsStream::newFile('A.ini.php')
|
||||||
->at($this->root->getChild('config'))
|
->at($this->root->getChild('config'))
|
||||||
->setContent(file_get_contents($fileDir . 'A.ini.php'));
|
->setContent(file_get_contents($fileDir . 'A.ini.php'));
|
||||||
vfsStream::newFile('B.ini.php')
|
vfsStream::newFile('B.ini.php')
|
||||||
->at($this->root->getChild('config'))
|
->at($this->root->getChild('config'))
|
||||||
->setContent(file_get_contents($fileDir . 'B.ini.php'));
|
->setContent(file_get_contents($fileDir . 'B.ini.php'));
|
||||||
|
|
||||||
$configFileLoader = new ConfigFileManager(
|
$configFileLoader = new ConfigFileManager(
|
||||||
$this->root->url(),
|
$this->root->url(),
|
||||||
$this->root->url() . DIRECTORY_SEPARATOR . Config::CONFIG_DIR,
|
$this->root->url() . DIRECTORY_SEPARATOR . Config::CONFIG_DIR,
|
||||||
$this->root->url() . DIRECTORY_SEPARATOR . Config::STATIC_DIR
|
$this->root->url() . DIRECTORY_SEPARATOR . Config::STATIC_DIR
|
||||||
);
|
);
|
||||||
$configCache = new Cache();
|
$configCache = new Cache();
|
||||||
|
|
||||||
$configFileLoader->setupCache($configCache);
|
$configFileLoader->setupCache($configCache);
|
||||||
|
|
||||||
|
@ -320,24 +321,25 @@ class ConfigFileManagerTest extends MockedTest
|
||||||
$this->delConfigFile('local.config.php');
|
$this->delConfigFile('local.config.php');
|
||||||
|
|
||||||
$fileDir = dirname(__DIR__) . DIRECTORY_SEPARATOR .
|
$fileDir = dirname(__DIR__) . DIRECTORY_SEPARATOR .
|
||||||
'..' . DIRECTORY_SEPARATOR .
|
|
||||||
'..' . DIRECTORY_SEPARATOR .
|
'..' . DIRECTORY_SEPARATOR .
|
||||||
'..' . DIRECTORY_SEPARATOR .
|
'..' . DIRECTORY_SEPARATOR .
|
||||||
'datasets' . DIRECTORY_SEPARATOR .
|
'..' . DIRECTORY_SEPARATOR .
|
||||||
'config' . DIRECTORY_SEPARATOR;
|
'datasets' . DIRECTORY_SEPARATOR .
|
||||||
|
'config' . DIRECTORY_SEPARATOR;
|
||||||
|
|
||||||
vfsStream::newFile('A.ini.php')
|
vfsStream::newFile('A.ini.php')
|
||||||
->at($this->root->getChild('config'))
|
->at($this->root->getChild('config'))
|
||||||
->setContent(file_get_contents($fileDir . 'A.ini.php'));
|
->setContent(file_get_contents($fileDir . 'A.ini.php'));
|
||||||
vfsStream::newFile('B-sample.ini.php')
|
vfsStream::newFile('B-sample.ini.php')
|
||||||
->at($this->root->getChild('config'))
|
->at($this->root->getChild('config'))
|
||||||
->setContent(file_get_contents($fileDir . 'B.ini.php'));
|
->setContent(file_get_contents($fileDir . 'B.ini.php'));
|
||||||
|
|
||||||
$configFileLoader = new ConfigFileManager(
|
$configFileLoader = new ConfigFileManager(
|
||||||
$this->root->url(),
|
$this->root->url(),
|
||||||
$this->root->url() . DIRECTORY_SEPARATOR . Config::CONFIG_DIR,
|
$this->root->url() . DIRECTORY_SEPARATOR . Config::CONFIG_DIR,
|
||||||
$this->root->url() . DIRECTORY_SEPARATOR . Config::STATIC_DIR
|
$this->root->url() . DIRECTORY_SEPARATOR . Config::STATIC_DIR
|
||||||
);
|
);
|
||||||
|
|
||||||
$configCache = new Cache();
|
$configCache = new Cache();
|
||||||
|
|
||||||
$configFileLoader->setupCache($configCache);
|
$configFileLoader->setupCache($configCache);
|
||||||
|
@ -353,10 +355,10 @@ class ConfigFileManagerTest extends MockedTest
|
||||||
{
|
{
|
||||||
$this->delConfigFile('local.config.php');
|
$this->delConfigFile('local.config.php');
|
||||||
|
|
||||||
$configFileLoader = (new Config())->createConfigFileLoader($this->root->url(), ['FRIENDICA_CONFIG_DIR' => '/a/wrong/dir/']);
|
$configFileManager = (new Config())->createConfigFileManager($this->root->url(), ['FRIENDICA_CONFIG_DIR' => '/a/wrong/dir/']);
|
||||||
$configCache = new Cache();
|
$configCache = new Cache();
|
||||||
|
|
||||||
$configFileLoader->setupCache($configCache);
|
$configFileManager->setupCache($configCache);
|
||||||
|
|
||||||
self::assertEquals($this->root->url(), $configCache->get('system', 'basepath'));
|
self::assertEquals($this->root->url(), $configCache->get('system', 'basepath'));
|
||||||
}
|
}
|
||||||
|
@ -379,10 +381,13 @@ class ConfigFileManagerTest extends MockedTest
|
||||||
->at($this->root->getChild('config2'))
|
->at($this->root->getChild('config2'))
|
||||||
->setContent(file_get_contents($fileDir . 'B.config.php'));
|
->setContent(file_get_contents($fileDir . 'B.config.php'));
|
||||||
|
|
||||||
$configFileLoader = (new Config())->createConfigFileLoader($this->root->url(), ['FRIENDICA_CONFIG_DIR' => $this->root->getChild('config2')->url()]);
|
$configFileManager = (new Config())->createConfigFileManager($this->root->url(),
|
||||||
$configCache = new Cache();
|
[
|
||||||
|
'FRIENDICA_CONFIG_DIR' => $this->root->getChild('config2')->url(),
|
||||||
|
]);
|
||||||
|
$configCache = new Cache();
|
||||||
|
|
||||||
$configFileLoader->setupCache($configCache);
|
$configFileManager->setupCache($configCache);
|
||||||
|
|
||||||
self::assertEquals('newValue', $configCache->get('system', 'newKey'));
|
self::assertEquals('newValue', $configCache->get('system', 'newKey'));
|
||||||
}
|
}
|
||||||
|
@ -402,10 +407,13 @@ class ConfigFileManagerTest extends MockedTest
|
||||||
->at($this->root->getChild('config2'))
|
->at($this->root->getChild('config2'))
|
||||||
->setContent(file_get_contents($fileDir . 'B.config.php'));
|
->setContent(file_get_contents($fileDir . 'B.config.php'));
|
||||||
|
|
||||||
$configFileLoader = (new Config())->createConfigFileLoader($this->root->url(), ['FRIENDICA_CONFIG_DIR' => $this->root->getChild('config2')->url()]);
|
$configFileManager = (new Config())->createConfigFileManager($this->root->url(),
|
||||||
$configCache = new Cache();
|
[
|
||||||
|
'FRIENDICA_CONFIG_DIR' => $this->root->getChild('config2')->url(),
|
||||||
|
]);
|
||||||
|
$configCache = new Cache();
|
||||||
|
|
||||||
$configFileLoader->setupCache($configCache);
|
$configFileManager->setupCache($configCache);
|
||||||
|
|
||||||
$specialChars = '!"§$%&/()(/&%$\'><?$a,;:[]}{}\\?¿¿ß';
|
$specialChars = '!"§$%&/()(/&%$\'><?$a,;:[]}{}\\?¿¿ß';
|
||||||
|
|
||||||
|
@ -414,19 +422,19 @@ class ConfigFileManagerTest extends MockedTest
|
||||||
$configCache->set('config', 'test', 'it', Cache::SOURCE_DATA);
|
$configCache->set('config', 'test', 'it', Cache::SOURCE_DATA);
|
||||||
$configCache->set('system', 'test_2', 2, Cache::SOURCE_DATA);
|
$configCache->set('system', 'test_2', 2, Cache::SOURCE_DATA);
|
||||||
$configCache->set('special_chars', 'special', $specialChars, Cache::SOURCE_DATA);
|
$configCache->set('special_chars', 'special', $specialChars, Cache::SOURCE_DATA);
|
||||||
$configFileLoader->saveData($configCache);
|
$configFileManager->saveData($configCache);
|
||||||
|
|
||||||
// Reload the configCache with the new values
|
// Reload the configCache with the new values
|
||||||
$configCache2 = new Cache();
|
$configCache2 = new Cache();
|
||||||
$configFileLoader->setupCache($configCache2);
|
$configFileManager->setupCache($configCache2);
|
||||||
|
|
||||||
self::assertEquals($configCache, $configCache2);
|
self::assertEquals($configCache, $configCache2);
|
||||||
self::assertEquals([
|
self::assertEquals([
|
||||||
'system' => [
|
'system' => [
|
||||||
'test' => 'it',
|
'test' => 'it',
|
||||||
'test_2' => 2
|
'test_2' => 2
|
||||||
],
|
],
|
||||||
'config' => [
|
'config' => [
|
||||||
'test' => 'it',
|
'test' => 'it',
|
||||||
],
|
],
|
||||||
'special_chars' => [
|
'special_chars' => [
|
||||||
|
|
|
@ -76,7 +76,7 @@ class ConfigTest extends MockedTest
|
||||||
*/
|
*/
|
||||||
public function getInstance()
|
public function getInstance()
|
||||||
{
|
{
|
||||||
$this->configFileManager->setupCache($this->configCache, []);
|
$this->configFileManager->setupCache($this->configCache);
|
||||||
return new Config($this->configFileManager, $this->configCache);
|
return new Config($this->configFileManager, $this->configCache);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,11 +53,11 @@ class DatabaseStorageTest extends StorageTest
|
||||||
$profiler->shouldReceive('saveTimestamp')->withAnyArgs()->andReturn(true);
|
$profiler->shouldReceive('saveTimestamp')->withAnyArgs()->andReturn(true);
|
||||||
|
|
||||||
// load real config to avoid mocking every config-entry which is related to the Database class
|
// load real config to avoid mocking every config-entry which is related to the Database class
|
||||||
$configFactory = new Config();
|
$configFactory = new Config();
|
||||||
$loader = (new Config())->createConfigFileLoader($this->root->url(), []);
|
$configFileManager = (new Config())->createConfigFileManager($this->root->url());
|
||||||
$configCache = $configFactory->createCache($loader);
|
$configCache = $configFactory->createCache($configFileManager);
|
||||||
|
|
||||||
$dbaDefinition = (new DbaDefinition($configCache->get('system', 'basepath')))->load();
|
$dbaDefinition = (new DbaDefinition($configCache->get('system', 'basepath')))->load();
|
||||||
$viewDefinition = (new ViewDefinition($configCache->get('system', 'basepath')))->load();
|
$viewDefinition = (new ViewDefinition($configCache->get('system', 'basepath')))->load();
|
||||||
|
|
||||||
$dba = new StaticDatabase($configCache, $profiler, $dbaDefinition, $viewDefinition);
|
$dba = new StaticDatabase($configCache, $profiler, $dbaDefinition, $viewDefinition);
|
||||||
|
|
|
@ -52,6 +52,7 @@ use Friendica\Test\Util\SampleStorageBackend;
|
||||||
class StorageManagerTest extends DatabaseTest
|
class StorageManagerTest extends DatabaseTest
|
||||||
{
|
{
|
||||||
use VFSTrait;
|
use VFSTrait;
|
||||||
|
|
||||||
/** @var Database */
|
/** @var Database */
|
||||||
private $dba;
|
private $dba;
|
||||||
/** @var IManageConfigValues */
|
/** @var IManageConfigValues */
|
||||||
|
@ -77,18 +78,19 @@ class StorageManagerTest extends DatabaseTest
|
||||||
$profiler->shouldReceive('saveTimestamp')->withAnyArgs()->andReturn(true);
|
$profiler->shouldReceive('saveTimestamp')->withAnyArgs()->andReturn(true);
|
||||||
|
|
||||||
// load real config to avoid mocking every config-entry which is related to the Database class
|
// load real config to avoid mocking every config-entry which is related to the Database class
|
||||||
$configFactory = new Config();
|
$configFactory = new Config();
|
||||||
$loader = $configFactory->createConfigFileLoader($this->root->url(), []);
|
$configFileManager = $configFactory->createConfigFileManager($this->root->url());
|
||||||
$configCache = $configFactory->createCache($loader);
|
$configCache = $configFactory->createCache($configFileManager);
|
||||||
|
|
||||||
$dbaDefinition = (new DbaDefinition($configCache->get('system', 'basepath')))->load();
|
$dbaDefinition = (new DbaDefinition($configCache->get('system', 'basepath')))->load();
|
||||||
$viewDefinition = (new ViewDefinition($configCache->get('system', 'basepath')))->load();
|
$viewDefinition = (new ViewDefinition($configCache->get('system', 'basepath')))->load();
|
||||||
|
|
||||||
$this->dba = new StaticDatabase($configCache, $profiler, $dbaDefinition, $viewDefinition);
|
$this->dba = new StaticDatabase($configCache, $profiler, $dbaDefinition, $viewDefinition);
|
||||||
|
|
||||||
$this->config = new \Friendica\Core\Config\Model\Config($loader, $configCache);
|
$this->config = new \Friendica\Core\Config\Model\Config($configFileManager, $configCache);
|
||||||
$this->config->set('storage', 'name', 'Database');
|
$this->config->set('storage', 'name', 'Database');
|
||||||
$this->config->set('storage', 'filesystem_path', $this->root->getChild(Type\FilesystemConfig::DEFAULT_BASE_FOLDER)->url());
|
$this->config->set('storage', 'filesystem_path', $this->root->getChild(Type\FilesystemConfig::DEFAULT_BASE_FOLDER)
|
||||||
|
->url());
|
||||||
|
|
||||||
$this->l10n = \Mockery::mock(L10n::class);
|
$this->l10n = \Mockery::mock(L10n::class);
|
||||||
}
|
}
|
||||||
|
@ -113,21 +115,21 @@ class StorageManagerTest extends DatabaseTest
|
||||||
public function dataStorages()
|
public function dataStorages()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'empty' => [
|
'empty' => [
|
||||||
'name' => '',
|
'name' => '',
|
||||||
'valid' => false,
|
'valid' => false,
|
||||||
'interface' => ICanReadFromStorage::class,
|
'interface' => ICanReadFromStorage::class,
|
||||||
'assert' => null,
|
'assert' => null,
|
||||||
'assertName' => '',
|
'assertName' => '',
|
||||||
],
|
],
|
||||||
'database' => [
|
'database' => [
|
||||||
'name' => Type\Database::NAME,
|
'name' => Type\Database::NAME,
|
||||||
'valid' => true,
|
'valid' => true,
|
||||||
'interface' => ICanWriteToStorage::class,
|
'interface' => ICanWriteToStorage::class,
|
||||||
'assert' => Type\Database::class,
|
'assert' => Type\Database::class,
|
||||||
'assertName' => Type\Database::NAME,
|
'assertName' => Type\Database::NAME,
|
||||||
],
|
],
|
||||||
'filesystem' => [
|
'filesystem' => [
|
||||||
'name' => Filesystem::NAME,
|
'name' => Filesystem::NAME,
|
||||||
'valid' => true,
|
'valid' => true,
|
||||||
'interface' => ICanWriteToStorage::class,
|
'interface' => ICanWriteToStorage::class,
|
||||||
|
@ -141,7 +143,7 @@ class StorageManagerTest extends DatabaseTest
|
||||||
'assert' => SystemResource::class,
|
'assert' => SystemResource::class,
|
||||||
'assertName' => SystemResource::NAME,
|
'assertName' => SystemResource::NAME,
|
||||||
],
|
],
|
||||||
'invalid' => [
|
'invalid' => [
|
||||||
'name' => 'invalid',
|
'name' => 'invalid',
|
||||||
'valid' => false,
|
'valid' => false,
|
||||||
'interface' => null,
|
'interface' => null,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user