mirror of
https://git.friendi.ca/friendica/friendica.git
synced 2025-06-11 09:44:32 +02:00
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
12 changed files with 134 additions and 125 deletions
|
@ -54,11 +54,11 @@ class DatabaseCacheTest extends CacheTest
|
|||
$profiler->shouldReceive('saveTimestamp')->withAnyArgs()->andReturn(true);
|
||||
|
||||
// load real config to avoid mocking every config-entry which is related to the Database class
|
||||
$configFactory = new Config();
|
||||
$loader = (new Config())->createConfigFileLoader($this->root->url(), []);
|
||||
$configCache = $configFactory->createCache($loader);
|
||||
$configFactory = new Config();
|
||||
$configFileManager = (new Config())->createConfigFileManager($this->root->url(), []);
|
||||
$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();
|
||||
|
||||
$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::STATIC_DIR
|
||||
);
|
||||
|
||||
$configCache = new Cache();
|
||||
|
||||
$configFileLoader->setupCache($configCache);
|
||||
|
@ -69,15 +70,15 @@ class ConfigFileManagerTest extends MockedTest
|
|||
$this->delConfigFile('local.config.php');
|
||||
|
||||
vfsStream::newFile('local.config.php')
|
||||
->at($this->root->getChild('config'))
|
||||
->setContent('<?php return true;');
|
||||
->at($this->root->getChild('config'))
|
||||
->setContent('<?php return true;');
|
||||
|
||||
$configFileLoader = new ConfigFileManager(
|
||||
$this->root->url(),
|
||||
$this->root->url() . DIRECTORY_SEPARATOR . Config::CONFIG_DIR,
|
||||
$this->root->url() . DIRECTORY_SEPARATOR . Config::STATIC_DIR
|
||||
);
|
||||
$configCache = new Cache();
|
||||
$configCache = new Cache();
|
||||
|
||||
$configFileLoader->setupCache($configCache);
|
||||
}
|
||||
|
@ -90,23 +91,23 @@ class ConfigFileManagerTest extends MockedTest
|
|||
$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';
|
||||
'..' . 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));
|
||||
->at($this->root->getChild('config'))
|
||||
->setContent(file_get_contents($file));
|
||||
|
||||
$configFileLoader = new ConfigFileManager(
|
||||
$this->root->url(),
|
||||
$this->root->url() . DIRECTORY_SEPARATOR . Config::CONFIG_DIR,
|
||||
$this->root->url() . DIRECTORY_SEPARATOR . Config::STATIC_DIR
|
||||
);
|
||||
$configCache = new Cache();
|
||||
$configCache = new Cache();
|
||||
|
||||
$configFileLoader->setupCache($configCache);
|
||||
|
||||
|
@ -127,23 +128,23 @@ class ConfigFileManagerTest extends MockedTest
|
|||
$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';
|
||||
'..' . 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));
|
||||
->at($this->root->getChild('config'))
|
||||
->setContent(file_get_contents($file));
|
||||
|
||||
$configFileLoader = new ConfigFileManager(
|
||||
$this->root->url(),
|
||||
$this->root->url() . DIRECTORY_SEPARATOR . Config::CONFIG_DIR,
|
||||
$this->root->url() . DIRECTORY_SEPARATOR . Config::STATIC_DIR
|
||||
);
|
||||
$configCache = new Cache();
|
||||
$configCache = new Cache();
|
||||
|
||||
$configFileLoader->setupCache($configCache);
|
||||
|
||||
|
@ -163,23 +164,23 @@ class ConfigFileManagerTest extends MockedTest
|
|||
$this->delConfigFile('local.config.php');
|
||||
|
||||
$file = dirname(__DIR__) . DIRECTORY_SEPARATOR .
|
||||
'..' . DIRECTORY_SEPARATOR .
|
||||
'..' . DIRECTORY_SEPARATOR .
|
||||
'..' . DIRECTORY_SEPARATOR .
|
||||
'datasets' . DIRECTORY_SEPARATOR .
|
||||
'config' . DIRECTORY_SEPARATOR .
|
||||
'.htconfig.php';
|
||||
'..' . 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));
|
||||
->at($this->root)
|
||||
->setContent(file_get_contents($file));
|
||||
|
||||
$configFileLoader = new ConfigFileManager(
|
||||
$this->root->url(),
|
||||
$this->root->url() . DIRECTORY_SEPARATOR . Config::CONFIG_DIR,
|
||||
$this->root->url() . DIRECTORY_SEPARATOR . Config::STATIC_DIR
|
||||
);
|
||||
$configCache = new Cache();
|
||||
$configCache = new Cache();
|
||||
|
||||
$configFileLoader->setupCache($configCache);
|
||||
|
||||
|
@ -217,16 +218,16 @@ class ConfigFileManagerTest extends MockedTest
|
|||
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';
|
||||
'..' . 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));
|
||||
->at($this->root->getChild('addon')->getChild('test')->getChild('config'))
|
||||
->setContent(file_get_contents($file));
|
||||
|
||||
$configFileLoader = new ConfigFileManager(
|
||||
$this->root->url(),
|
||||
|
@ -252,25 +253,25 @@ class ConfigFileManagerTest extends MockedTest
|
|||
$this->delConfigFile('local.config.php');
|
||||
|
||||
$fileDir = dirname(__DIR__) . DIRECTORY_SEPARATOR .
|
||||
'..' . DIRECTORY_SEPARATOR .
|
||||
'..' . DIRECTORY_SEPARATOR .
|
||||
'..' . DIRECTORY_SEPARATOR .
|
||||
'datasets' . DIRECTORY_SEPARATOR .
|
||||
'config' . 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'));
|
||||
->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'));
|
||||
->at($this->root->getChild('config'))
|
||||
->setContent(file_get_contents($fileDir . 'B.config.php'));
|
||||
|
||||
$configFileLoader = new ConfigFileManager(
|
||||
$this->root->url(),
|
||||
$this->root->url() . DIRECTORY_SEPARATOR . Config::CONFIG_DIR,
|
||||
$this->root->url() . DIRECTORY_SEPARATOR . Config::STATIC_DIR
|
||||
);
|
||||
$configCache = new Cache();
|
||||
$configCache = new Cache();
|
||||
|
||||
$configFileLoader->setupCache($configCache);
|
||||
|
||||
|
@ -286,25 +287,25 @@ class ConfigFileManagerTest extends MockedTest
|
|||
$this->delConfigFile('local.config.php');
|
||||
|
||||
$fileDir = dirname(__DIR__) . DIRECTORY_SEPARATOR .
|
||||
'..' . DIRECTORY_SEPARATOR .
|
||||
'..' . DIRECTORY_SEPARATOR .
|
||||
'..' . DIRECTORY_SEPARATOR .
|
||||
'datasets' . DIRECTORY_SEPARATOR .
|
||||
'config' . 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'));
|
||||
->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'));
|
||||
->at($this->root->getChild('config'))
|
||||
->setContent(file_get_contents($fileDir . 'B.ini.php'));
|
||||
|
||||
$configFileLoader = new ConfigFileManager(
|
||||
$this->root->url(),
|
||||
$this->root->url() . DIRECTORY_SEPARATOR . Config::CONFIG_DIR,
|
||||
$this->root->url() . DIRECTORY_SEPARATOR . Config::STATIC_DIR
|
||||
);
|
||||
$configCache = new Cache();
|
||||
$configCache = new Cache();
|
||||
|
||||
$configFileLoader->setupCache($configCache);
|
||||
|
||||
|
@ -320,24 +321,25 @@ class ConfigFileManagerTest extends MockedTest
|
|||
$this->delConfigFile('local.config.php');
|
||||
|
||||
$fileDir = dirname(__DIR__) . DIRECTORY_SEPARATOR .
|
||||
'..' . DIRECTORY_SEPARATOR .
|
||||
'..' . DIRECTORY_SEPARATOR .
|
||||
'..' . DIRECTORY_SEPARATOR .
|
||||
'datasets' . DIRECTORY_SEPARATOR .
|
||||
'config' . 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'));
|
||||
->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'));
|
||||
->at($this->root->getChild('config'))
|
||||
->setContent(file_get_contents($fileDir . 'B.ini.php'));
|
||||
|
||||
$configFileLoader = new ConfigFileManager(
|
||||
$this->root->url(),
|
||||
$this->root->url() . DIRECTORY_SEPARATOR . Config::CONFIG_DIR,
|
||||
$this->root->url() . DIRECTORY_SEPARATOR . Config::STATIC_DIR
|
||||
);
|
||||
|
||||
$configCache = new Cache();
|
||||
|
||||
$configFileLoader->setupCache($configCache);
|
||||
|
@ -353,10 +355,10 @@ class ConfigFileManagerTest extends MockedTest
|
|||
{
|
||||
$this->delConfigFile('local.config.php');
|
||||
|
||||
$configFileLoader = (new Config())->createConfigFileLoader($this->root->url(), ['FRIENDICA_CONFIG_DIR' => '/a/wrong/dir/']);
|
||||
$configCache = new Cache();
|
||||
$configFileManager = (new Config())->createConfigFileManager($this->root->url(), ['FRIENDICA_CONFIG_DIR' => '/a/wrong/dir/']);
|
||||
$configCache = new Cache();
|
||||
|
||||
$configFileLoader->setupCache($configCache);
|
||||
$configFileManager->setupCache($configCache);
|
||||
|
||||
self::assertEquals($this->root->url(), $configCache->get('system', 'basepath'));
|
||||
}
|
||||
|
@ -379,10 +381,13 @@ class ConfigFileManagerTest extends MockedTest
|
|||
->at($this->root->getChild('config2'))
|
||||
->setContent(file_get_contents($fileDir . 'B.config.php'));
|
||||
|
||||
$configFileLoader = (new Config())->createConfigFileLoader($this->root->url(), ['FRIENDICA_CONFIG_DIR' => $this->root->getChild('config2')->url()]);
|
||||
$configCache = new Cache();
|
||||
$configFileManager = (new Config())->createConfigFileManager($this->root->url(),
|
||||
[
|
||||
'FRIENDICA_CONFIG_DIR' => $this->root->getChild('config2')->url(),
|
||||
]);
|
||||
$configCache = new Cache();
|
||||
|
||||
$configFileLoader->setupCache($configCache);
|
||||
$configFileManager->setupCache($configCache);
|
||||
|
||||
self::assertEquals('newValue', $configCache->get('system', 'newKey'));
|
||||
}
|
||||
|
@ -402,10 +407,13 @@ class ConfigFileManagerTest extends MockedTest
|
|||
->at($this->root->getChild('config2'))
|
||||
->setContent(file_get_contents($fileDir . 'B.config.php'));
|
||||
|
||||
$configFileLoader = (new Config())->createConfigFileLoader($this->root->url(), ['FRIENDICA_CONFIG_DIR' => $this->root->getChild('config2')->url()]);
|
||||
$configCache = new Cache();
|
||||
$configFileManager = (new Config())->createConfigFileManager($this->root->url(),
|
||||
[
|
||||
'FRIENDICA_CONFIG_DIR' => $this->root->getChild('config2')->url(),
|
||||
]);
|
||||
$configCache = new Cache();
|
||||
|
||||
$configFileLoader->setupCache($configCache);
|
||||
$configFileManager->setupCache($configCache);
|
||||
|
||||
$specialChars = '!"§$%&/()(/&%$\'><?$a,;:[]}{}\\?¿¿ß';
|
||||
|
||||
|
@ -414,19 +422,19 @@ class ConfigFileManagerTest extends MockedTest
|
|||
$configCache->set('config', 'test', 'it', Cache::SOURCE_DATA);
|
||||
$configCache->set('system', 'test_2', 2, 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
|
||||
$configCache2 = new Cache();
|
||||
$configFileLoader->setupCache($configCache2);
|
||||
$configFileManager->setupCache($configCache2);
|
||||
|
||||
self::assertEquals($configCache, $configCache2);
|
||||
self::assertEquals([
|
||||
'system' => [
|
||||
'test' => 'it',
|
||||
'system' => [
|
||||
'test' => 'it',
|
||||
'test_2' => 2
|
||||
],
|
||||
'config' => [
|
||||
'config' => [
|
||||
'test' => 'it',
|
||||
],
|
||||
'special_chars' => [
|
||||
|
|
|
@ -76,7 +76,7 @@ class ConfigTest extends MockedTest
|
|||
*/
|
||||
public function getInstance()
|
||||
{
|
||||
$this->configFileManager->setupCache($this->configCache, []);
|
||||
$this->configFileManager->setupCache($this->configCache);
|
||||
return new Config($this->configFileManager, $this->configCache);
|
||||
}
|
||||
|
||||
|
|
|
@ -53,11 +53,11 @@ class DatabaseStorageTest extends StorageTest
|
|||
$profiler->shouldReceive('saveTimestamp')->withAnyArgs()->andReturn(true);
|
||||
|
||||
// load real config to avoid mocking every config-entry which is related to the Database class
|
||||
$configFactory = new Config();
|
||||
$loader = (new Config())->createConfigFileLoader($this->root->url(), []);
|
||||
$configCache = $configFactory->createCache($loader);
|
||||
$configFactory = new Config();
|
||||
$configFileManager = (new Config())->createConfigFileManager($this->root->url());
|
||||
$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();
|
||||
|
||||
$dba = new StaticDatabase($configCache, $profiler, $dbaDefinition, $viewDefinition);
|
||||
|
|
|
@ -52,6 +52,7 @@ use Friendica\Test\Util\SampleStorageBackend;
|
|||
class StorageManagerTest extends DatabaseTest
|
||||
{
|
||||
use VFSTrait;
|
||||
|
||||
/** @var Database */
|
||||
private $dba;
|
||||
/** @var IManageConfigValues */
|
||||
|
@ -77,18 +78,19 @@ class StorageManagerTest extends DatabaseTest
|
|||
$profiler->shouldReceive('saveTimestamp')->withAnyArgs()->andReturn(true);
|
||||
|
||||
// load real config to avoid mocking every config-entry which is related to the Database class
|
||||
$configFactory = new Config();
|
||||
$loader = $configFactory->createConfigFileLoader($this->root->url(), []);
|
||||
$configCache = $configFactory->createCache($loader);
|
||||
$configFactory = new Config();
|
||||
$configFileManager = $configFactory->createConfigFileManager($this->root->url());
|
||||
$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();
|
||||
|
||||
$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', '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);
|
||||
}
|
||||
|
@ -113,21 +115,21 @@ class StorageManagerTest extends DatabaseTest
|
|||
public function dataStorages()
|
||||
{
|
||||
return [
|
||||
'empty' => [
|
||||
'empty' => [
|
||||
'name' => '',
|
||||
'valid' => false,
|
||||
'interface' => ICanReadFromStorage::class,
|
||||
'assert' => null,
|
||||
'assertName' => '',
|
||||
],
|
||||
'database' => [
|
||||
'database' => [
|
||||
'name' => Type\Database::NAME,
|
||||
'valid' => true,
|
||||
'interface' => ICanWriteToStorage::class,
|
||||
'assert' => Type\Database::class,
|
||||
'assertName' => Type\Database::NAME,
|
||||
],
|
||||
'filesystem' => [
|
||||
'filesystem' => [
|
||||
'name' => Filesystem::NAME,
|
||||
'valid' => true,
|
||||
'interface' => ICanWriteToStorage::class,
|
||||
|
@ -141,7 +143,7 @@ class StorageManagerTest extends DatabaseTest
|
|||
'assert' => SystemResource::class,
|
||||
'assertName' => SystemResource::NAME,
|
||||
],
|
||||
'invalid' => [
|
||||
'invalid' => [
|
||||
'name' => 'invalid',
|
||||
'valid' => false,
|
||||
'interface' => null,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue