mirror of
https://github.com/friendica/friendica
synced 2025-04-30 09:44:22 +02:00
Introduce ISetConfigValuesTransactional for transactional config behaviour
This commit is contained in:
parent
4d4b4a8858
commit
65d79d4c93
14 changed files with 588 additions and 150 deletions
|
@ -358,4 +358,52 @@ class CacheTest extends MockedTest
|
|||
$this->assertEquals(['system' => ['test_2' => 'with_data']], $configCache->getDataBySource(Cache::SOURCE_DATA));
|
||||
$this->assertEquals($data, $configCache->getDataBySource(Cache::SOURCE_FILE));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataTests
|
||||
*/
|
||||
public function testMerge($data)
|
||||
{
|
||||
$configCache = new Cache();
|
||||
$configCache->load($data, Cache::SOURCE_FILE);
|
||||
|
||||
$configCache->set('system', 'test_2','with_data', Cache::SOURCE_DATA);
|
||||
$configCache->set('config', 'test_override','with_another_data', Cache::SOURCE_DATA);
|
||||
|
||||
$newCache = new Cache();
|
||||
$newCache->set('config', 'test_override','override it again', Cache::SOURCE_DATA);
|
||||
$newCache->set('system', 'test_3','new value', Cache::SOURCE_DATA);
|
||||
|
||||
$mergedCache = $configCache->merge($newCache);
|
||||
|
||||
self::assertEquals('with_data', $mergedCache->get('system', 'test_2'));
|
||||
self::assertEquals('override it again', $mergedCache->get('config', 'test_override'));
|
||||
self::assertEquals('new value', $mergedCache->get('system', 'test_3'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataTests
|
||||
*/
|
||||
public function testDiff($data)
|
||||
{
|
||||
$configCache = new Cache();
|
||||
$configCache->load($data, Cache::SOURCE_FILE);
|
||||
|
||||
$configCache->set('system', 'test_2','with_data', Cache::SOURCE_DATA);
|
||||
$configCache->set('config', 'test_override','with_another_data', Cache::SOURCE_DATA);
|
||||
|
||||
$newCache = new Cache();
|
||||
$newCache->set('config', 'test_override','override it again', Cache::SOURCE_DATA);
|
||||
$newCache->set('system', 'test_3','new value', Cache::SOURCE_DATA);
|
||||
|
||||
$mergedCache = $configCache->diff($newCache);
|
||||
|
||||
print_r($mergedCache);
|
||||
|
||||
self::assertEquals('with_data', $mergedCache->get('system', 'test_2'));
|
||||
// existing entry was dropped
|
||||
self::assertNull($mergedCache->get('config', 'test_override'));
|
||||
// the newCache entry wasn't set, because we Diff
|
||||
self::assertNull($mergedCache->get('system', 'test_3'));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,8 +21,8 @@
|
|||
|
||||
namespace Friendica\Test\src\Core\Config\Cache;
|
||||
|
||||
use Friendica\Core\Config\Cache;
|
||||
use Friendica\Core\Config\Factory\Config;
|
||||
use Friendica\Core\Config\ValueObject\Cache;
|
||||
use Friendica\Test\MockedTest;
|
||||
use Friendica\Test\Util\VFSTrait;
|
||||
use Friendica\Core\Config\Util\ConfigFileManager;
|
||||
|
@ -51,7 +51,7 @@ class ConfigFileLoaderTest extends MockedTest
|
|||
$this->root->url() . DIRECTORY_SEPARATOR . Config::CONFIG_DIR,
|
||||
$this->root->url() . DIRECTORY_SEPARATOR . Config::STATIC_DIR
|
||||
);
|
||||
$configCache = new \Friendica\Core\Config\ValueObject\Cache();
|
||||
$configCache = new Cache();
|
||||
|
||||
$configFileLoader->setupCache($configCache);
|
||||
|
||||
|
@ -77,7 +77,7 @@ class ConfigFileLoaderTest extends MockedTest
|
|||
$this->root->url() . DIRECTORY_SEPARATOR . Config::CONFIG_DIR,
|
||||
$this->root->url() . DIRECTORY_SEPARATOR . Config::STATIC_DIR
|
||||
);
|
||||
$configCache = new \Friendica\Core\Config\ValueObject\Cache();
|
||||
$configCache = new Cache();
|
||||
|
||||
$configFileLoader->setupCache($configCache);
|
||||
}
|
||||
|
@ -106,7 +106,7 @@ class ConfigFileLoaderTest extends MockedTest
|
|||
$this->root->url() . DIRECTORY_SEPARATOR . Config::CONFIG_DIR,
|
||||
$this->root->url() . DIRECTORY_SEPARATOR . Config::STATIC_DIR
|
||||
);
|
||||
$configCache = new \Friendica\Core\Config\ValueObject\Cache();
|
||||
$configCache = new Cache();
|
||||
|
||||
$configFileLoader->setupCache($configCache);
|
||||
|
||||
|
@ -143,7 +143,7 @@ class ConfigFileLoaderTest extends MockedTest
|
|||
$this->root->url() . DIRECTORY_SEPARATOR . Config::CONFIG_DIR,
|
||||
$this->root->url() . DIRECTORY_SEPARATOR . Config::STATIC_DIR
|
||||
);
|
||||
$configCache = new \Friendica\Core\Config\ValueObject\Cache();
|
||||
$configCache = new Cache();
|
||||
|
||||
$configFileLoader->setupCache($configCache);
|
||||
|
||||
|
@ -179,7 +179,7 @@ class ConfigFileLoaderTest extends MockedTest
|
|||
$this->root->url() . DIRECTORY_SEPARATOR . Config::CONFIG_DIR,
|
||||
$this->root->url() . DIRECTORY_SEPARATOR . Config::STATIC_DIR
|
||||
);
|
||||
$configCache = new \Friendica\Core\Config\ValueObject\Cache();
|
||||
$configCache = new Cache();
|
||||
|
||||
$configFileLoader->setupCache($configCache);
|
||||
|
||||
|
@ -270,7 +270,7 @@ class ConfigFileLoaderTest extends MockedTest
|
|||
$this->root->url() . DIRECTORY_SEPARATOR . Config::CONFIG_DIR,
|
||||
$this->root->url() . DIRECTORY_SEPARATOR . Config::STATIC_DIR
|
||||
);
|
||||
$configCache = new \Friendica\Core\Config\ValueObject\Cache();
|
||||
$configCache = new Cache();
|
||||
|
||||
$configFileLoader->setupCache($configCache);
|
||||
|
||||
|
@ -304,7 +304,7 @@ class ConfigFileLoaderTest extends MockedTest
|
|||
$this->root->url() . DIRECTORY_SEPARATOR . Config::CONFIG_DIR,
|
||||
$this->root->url() . DIRECTORY_SEPARATOR . Config::STATIC_DIR
|
||||
);
|
||||
$configCache = new \Friendica\Core\Config\ValueObject\Cache();
|
||||
$configCache = new Cache();
|
||||
|
||||
$configFileLoader->setupCache($configCache);
|
||||
|
||||
|
@ -338,7 +338,7 @@ class ConfigFileLoaderTest extends MockedTest
|
|||
$this->root->url() . DIRECTORY_SEPARATOR . Config::CONFIG_DIR,
|
||||
$this->root->url() . DIRECTORY_SEPARATOR . Config::STATIC_DIR
|
||||
);
|
||||
$configCache = new \Friendica\Core\Config\ValueObject\Cache();
|
||||
$configCache = new Cache();
|
||||
|
||||
$configFileLoader->setupCache($configCache);
|
||||
|
||||
|
@ -354,7 +354,7 @@ class ConfigFileLoaderTest extends MockedTest
|
|||
$this->delConfigFile('local.config.php');
|
||||
|
||||
$configFileLoader = (new Config())->createConfigFileLoader($this->root->url(), ['FRIENDICA_CONFIG_DIR' => '/a/wrong/dir/']);
|
||||
$configCache = new \Friendica\Core\Config\ValueObject\Cache();
|
||||
$configCache = new Cache();
|
||||
|
||||
$configFileLoader->setupCache($configCache);
|
||||
|
||||
|
@ -380,7 +380,7 @@ class ConfigFileLoaderTest extends MockedTest
|
|||
->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 \Friendica\Core\Config\ValueObject\Cache();
|
||||
$configCache = new Cache();
|
||||
|
||||
$configFileLoader->setupCache($configCache);
|
||||
|
||||
|
@ -403,18 +403,18 @@ class ConfigFileLoaderTest extends MockedTest
|
|||
->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 \Friendica\Core\Config\ValueObject\Cache();
|
||||
$configCache = new Cache();
|
||||
|
||||
$configFileLoader->setupCache($configCache);
|
||||
|
||||
// overwrite some data and save it back to the config file
|
||||
$configCache->set('system', 'test', 'it', \Friendica\Core\Config\ValueObject\Cache::SOURCE_DATA);
|
||||
$configCache->set('config', 'test', 'it', \Friendica\Core\Config\ValueObject\Cache::SOURCE_DATA);
|
||||
$configCache->set('system', 'test_2', 2, \Friendica\Core\Config\ValueObject\Cache::SOURCE_DATA);
|
||||
$configCache->set('system', 'test', 'it', Cache::SOURCE_DATA);
|
||||
$configCache->set('config', 'test', 'it', Cache::SOURCE_DATA);
|
||||
$configCache->set('system', 'test_2', 2, Cache::SOURCE_DATA);
|
||||
$configFileLoader->saveData($configCache);
|
||||
|
||||
// Reload the configCache with the new values
|
||||
$configCache2 = new \Friendica\Core\Config\ValueObject\Cache();
|
||||
$configCache2 = new Cache();
|
||||
$configFileLoader->setupCache($configCache2);
|
||||
|
||||
self::assertEquals($configCache, $configCache2);
|
||||
|
@ -425,6 +425,6 @@ class ConfigFileLoaderTest extends MockedTest
|
|||
],
|
||||
'config' => [
|
||||
'test' => 'it'
|
||||
]], $configCache2->getDataBySource(\Friendica\Core\Config\ValueObject\Cache::SOURCE_DATA));
|
||||
]], $configCache2->getDataBySource(Cache::SOURCE_DATA));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue