mirror of
https://github.com/friendica/friendica
synced 2025-04-27 07:50:10 +00:00
Dynamic config loading
- Move settings, defaults and dbstructure to directory 'static' - Dynamic loading of config files (after the static loading) - Filter out '-sample.config.php' and '-sample.ini.php' files - Remove unnecessary ConfigFileManager - Move ConfigFileLoader to Utils - Add tests for multi-loading for INI, config and sample-filtering
This commit is contained in:
parent
966043712f
commit
92fb0a82ca
25 changed files with 325 additions and 161 deletions
|
@ -6,7 +6,7 @@ use Friendica\App;
|
|||
use Friendica\Core\Config\Cache\ConfigCache;
|
||||
use Friendica\Test\MockedTest;
|
||||
use Friendica\Test\Util\VFSTrait;
|
||||
use Friendica\Util\Config\ConfigFileLoader;
|
||||
use Friendica\Util\ConfigFileLoader;
|
||||
use Mockery\MockInterface;
|
||||
use org\bovigo\vfs\vfsStream;
|
||||
|
||||
|
@ -73,7 +73,7 @@ class ConfigFileLoaderTest extends MockedTest
|
|||
'..' . DIRECTORY_SEPARATOR .
|
||||
'datasets' . DIRECTORY_SEPARATOR .
|
||||
'config' . DIRECTORY_SEPARATOR .
|
||||
'local.config.php';
|
||||
'A.config.php';
|
||||
|
||||
vfsStream::newFile('local.config.php')
|
||||
->at($this->root->getChild('config'))
|
||||
|
@ -105,7 +105,7 @@ class ConfigFileLoaderTest extends MockedTest
|
|||
'..' . DIRECTORY_SEPARATOR .
|
||||
'datasets' . DIRECTORY_SEPARATOR .
|
||||
'config' . DIRECTORY_SEPARATOR .
|
||||
'local.ini.php';
|
||||
'A.ini.php';
|
||||
|
||||
vfsStream::newFile('local.ini.php')
|
||||
->at($this->root->getChild('config'))
|
||||
|
@ -185,7 +185,7 @@ class ConfigFileLoaderTest extends MockedTest
|
|||
'..' . DIRECTORY_SEPARATOR .
|
||||
'datasets' . DIRECTORY_SEPARATOR .
|
||||
'config' . DIRECTORY_SEPARATOR .
|
||||
'local.config.php';
|
||||
'A.config.php';
|
||||
|
||||
vfsStream::newFile('test.config.php')
|
||||
->at($this->root->getChild('addon')->getChild('test')->getChild('config'))
|
||||
|
@ -202,4 +202,91 @@ class ConfigFileLoaderTest extends MockedTest
|
|||
|
||||
$this->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 .
|
||||
'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->mode);
|
||||
$configCache = new ConfigCache();
|
||||
|
||||
$configFileLoader->setupCache($configCache);
|
||||
|
||||
$this->assertEquals('admin@overwritten.local', $configCache->get('config', 'admin_email'));
|
||||
$this->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 .
|
||||
'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->mode);
|
||||
$configCache = new ConfigCache();
|
||||
|
||||
$configFileLoader->setupCache($configCache);
|
||||
|
||||
$this->assertEquals('admin@overwritten.local', $configCache->get('config', 'admin_email'));
|
||||
$this->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 .
|
||||
'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->mode);
|
||||
$configCache = new ConfigCache();
|
||||
|
||||
$configFileLoader->setupCache($configCache);
|
||||
|
||||
$this->assertEquals('admin@test.it', $configCache->get('config', 'admin_email'));
|
||||
$this->assertEmpty($configCache->get('system', 'NewKey'));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue