/**
* Loads a given DB fixture for this DB test
*
- * @param string $fixture The path to the fixture
+ * @param string[][] $fixture The fixture array
* @param Database $dba The DB connection
*
* @throws \Exception
*/
- protected function loadFixture(string $fixture, Database $dba)
+ protected function loadDirectFixture(array $fixture, Database $dba)
{
- $data = include $fixture;
-
- foreach ($data as $tableName => $rows) {
+ foreach ($fixture as $tableName => $rows) {
if (is_numeric($tableName)) {
continue;
}
}
}
}
+
+ /**
+ * Loads a given DB fixture-file for this DB test
+ *
+ * @param string $fixture The path to the fixture
+ * @param Database $dba The DB connection
+ *
+ * @throws \Exception
+ */
+ protected function loadFixture(string $fixture, Database $dba)
+ {
+ $data = include $fixture;
+
+ $this->loadDirectFixture($data, $dba);
+ }
}
use Friendica\Core\Config\Model\DatabaseConfig;
use Friendica\Core\Config\Model\ReadOnlyFileConfig;
use Friendica\Core\Config\Util\ConfigFileManager;
-use Friendica\Core\Config\Util\ConfigFileTransformer;
use Friendica\Core\Config\ValueObject\Cache;
use Friendica\Test\DatabaseTest;
use Friendica\Test\Util\CreateDatabaseTrait;
];
}
+ public function configToDbArray(array $config): array
+ {
+ $dbarray = [];
+
+ foreach ($config as $category => $data) {
+ foreach ($data as $key => $value) {
+ $dbarray[] = [
+ 'cat' => $category,
+ 'k' => $key,
+ 'v' => $value,
+ ];
+ }
+ }
+
+ return ['config' => $dbarray];
+ }
+
/**
* Test the configuration initialization
* @dataProvider dataConfigLoad
*/
public function testSetUp(array $data)
{
- vfsStream::newFile(ConfigFileManager::CONFIG_DATA_FILE)
- ->at($this->root->getChild('config'))
- ->setContent(print_r($data, true));
+ $this->loadDirectFixture($this->configToDbArray($data) , $this->getDbInstance());
$this->testedConfig = $this->getInstance();
self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
*/
public function testReload(array $data, array $load)
{
- vfsStream::newFile(ConfigFileManager::CONFIG_DATA_FILE)
- ->at($this->root->getChild('config'))
- ->setContent(print_r($data, true));
+ $this->loadDirectFixture($this->configToDbArray($data), $this->getDbInstance());
$this->testedConfig = $this->getInstance();
self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
*/
public function testCacheLoadDouble(array $data1, array $data2, array $expect = [])
{
- vfsStream::newFile(ConfigFileManager::CONFIG_DATA_FILE)
- ->at($this->root->getChild('config'))
- ->setContent(print_r($data1, true));
+ $this->loadDirectFixture($this->configToDbArray($data1), $this->getDbInstance());
$this->testedConfig = $this->getInstance();
self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
self::assertConfig($cat, $data);
}
- vfsStream::newFile(ConfigFileManager::CONFIG_DATA_FILE)
- ->at($this->root->getChild('config'))
- ->setContent(print_r($data2, true));
+ $this->loadDirectFixture($this->configToDbArray($data2), $this->getDbInstance());
$this->testedConfig->reload();
*/
public function testSetGetLowPrio()
{
- vfsStream::newFile(ConfigFileManager::CONFIG_DATA_FILE)
- ->at($this->root->getChild('config'))
- ->setContent(print_r([
- 'config' => ['test' => 'it'],
- ], true));
+ $this->loadDirectFixture(['config' => [['cat' => 'config', 'k' => 'test', 'v' => 'it']]], $this->getDbInstance());
$this->testedConfig = $this->getInstance();
self::assertInstanceOf(Cache::class, $this->testedConfig->getCache());
self::assertEquals('it', $this->testedConfig->get('config', 'test'));
$this->testedConfig->getCache()->set('config', 'test', 'prio', 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'));
+ // You can set a config value, but if there's a value with a higher priority (environment), this value will persist when retrieving
+ self::assertTrue($this->testedConfig->set('config', 'test', '123'));
self::assertEquals('prio', $this->testedConfig->get('config', 'test', '', true));
}
self::assertEquals($assertion, $config->get($category));
}
-
- /**
- * Tests, if an overwritten value of an existing key will reset to it's default after deletion
- */
- public function testDeleteReturnsDefault()
- {
- vfsStream::newFile(ConfigFileManager::CONFIG_DATA_FILE)
- ->at($this->root->getChild('config'))
- ->setContent(print_r([
- 'config' => ['sitename' => 'overritten'],
- ], true));
-
- $config = $this->getInstance();
- self::assertEquals('overritten', $config->get('config', 'sitename'));
-
- $config->delete('config', 'sitename');
- self::assertEquals('Friendica Social Network', $config->get('config', 'sitename'));
- }
}