fixing tests and preload config

This commit is contained in:
Philipp Holzer 2019-02-23 00:09:57 +01:00
parent 8d56fb8fbe
commit 1dee89f215
No known key found for this signature in database
GPG key ID: 517BE60E2CE5C8A5
6 changed files with 12 additions and 60 deletions

View file

@ -33,7 +33,7 @@ class PreloadConfigAdapter extends AbstractDbaConfigAdapter implements IConfigAd
$configs = DBA::select('config', ['cat', 'v', 'k']);
while ($config = DBA::fetch($configs)) {
$value = $config['v'];
if (isset($value) && $value !== '') {
if (isset($value)) {
$return[$config['cat']][$config['k']] = $value;
}
}
@ -58,7 +58,7 @@ class PreloadConfigAdapter extends AbstractDbaConfigAdapter implements IConfigAd
// manage array value
$value = (preg_match("|^a:[0-9]+:{.*}$|s", $config['v']) ? unserialize($config['v']) : $config['v']);
if (isset($value) && $value !== '') {
if (isset($value)) {
return $value;
}
}

View file

@ -50,7 +50,7 @@ class PreloadPConfigAdapter extends AbstractDbaConfigAdapter implements IPConfig
$pconfigs = DBA::select('pconfig', ['cat', 'v', 'k'], ['uid' => $uid]);
while ($pconfig = DBA::fetch($pconfigs)) {
$value = $pconfig['v'];
if (isset($value) && $value !== '') {
if (isset($value)) {
$return[$pconfig['cat']][$pconfig['k']] = $value;
}
}
@ -79,7 +79,7 @@ class PreloadPConfigAdapter extends AbstractDbaConfigAdapter implements IPConfig
// manage array value
$value = (preg_match("|^a:[0-9]+:{.*}$|s", $config['v']) ? unserialize($config['v']) : $config['v']);
if (isset($value) && $value !== '') {
if (isset($value)) {
return $value;
}
}

View file

@ -19,19 +19,6 @@ class ConfigCacheLoaderTest extends MockedTest
$this->setUpVfsDir();
}
/**
* Test the loadConfigFiles() method with default values
*/
public function testLoadConfigFiles()
{
$configCacheLoader = new ConfigCacheLoader($this->root->url());
$configCache = new ConfigCache();
$configCacheLoader->loadConfigFiles($configCache);
$this->assertEquals($this->root->url(), $configCache->get('system', 'basepath'));
}
/**
* Test the loadConfigFiles() method with a wrong local.config.php
* @expectedException \Exception

View file

@ -138,22 +138,7 @@ class ConfigCacheTest extends MockedTest
{
$configCache = new ConfigCache();
$this->assertEquals('!<unset>!', $configCache->get('something', 'value'));
}
/**
* Test the has() method
*/
public function testHas()
{
$configCache = new ConfigCache();
$this->assertFalse($configCache->has('system', 'test'));
$this->assertFalse($configCache->has('system'));
$configCache->set('system', 'test', 'it');
$this->assertTrue($configCache->has('system', 'test'));
$this->assertTrue($configCache->has('system'));
$this->assertNull($configCache->get('something', 'value'));
}
/**
@ -171,8 +156,6 @@ class ConfigCacheTest extends MockedTest
],
]);
$this->assertTrue($configCache->has('system'));
$this->assertEquals([
'key1' => 'value1',
'key2' => 'value2',
@ -233,8 +216,6 @@ class ConfigCacheTest extends MockedTest
],
]);
$this->assertTrue($configCache->hasP($uid,'system'));
$this->assertEquals([
'key1' => 'value1',
'key2' => 'value2',
@ -264,20 +245,4 @@ class ConfigCacheTest extends MockedTest
$this->assertEmpty($configCache->getAll());
}
/**
* Test the hasP() method
*/
public function testHasP()
{
$configCache = new ConfigCache();
$uid = 345;
$this->assertFalse($configCache->hasP($uid, 'system', 'test'));
$this->assertFalse($configCache->hasP($uid, 'system'));
$configCache->setP($uid, 'system', 'test', 'it');
$this->assertTrue($configCache->hasP($uid, 'system', 'test'));
$this->assertTrue($configCache->hasP($uid, 'system'));
}
}

View file

@ -142,7 +142,7 @@ class ConfigurationTest extends MockedTest
$this->assertNull($configuration->get('test', 'it'));
/// beware that the cache returns '!<unset>!' and not null for a non existing value
$this->assertEquals('!<unset>!', $configuration->getCache()->get('test', 'it'));
$this->assertNull($configuration->getCache()->get('test', 'it'));
// with default value
$this->assertEquals('default', $configuration->get('test', 'it', 'default'));
@ -165,7 +165,7 @@ class ConfigurationTest extends MockedTest
$configAdapter->shouldReceive('isLoaded')->with('test', 'it')->andReturn(true)->twice();
$configAdapter->shouldReceive('get')->with('test', 'it')->andReturn($data)->once();
$configAdapter->shouldReceive('isLoaded')->with('test', 'not')->andReturn(false)->once();
$configAdapter->shouldReceive('get')->with('test', 'not')->andReturn('!<unset>!')->once();
$configAdapter->shouldReceive('get')->with('test', 'not')->andReturn(null)->once();
$configuration = new Configuration($configCache, $configAdapter);
@ -179,7 +179,7 @@ class ConfigurationTest extends MockedTest
// without refresh and wrong value and default
$this->assertEquals('default', $configuration->get('test', 'not', 'default'));
$this->assertEquals('!<unset>!', $configuration->getCache()->get('test', 'not'));
$this->assertNull($configuration->getCache()->get('test', 'not'));
}
/**
@ -195,7 +195,7 @@ class ConfigurationTest extends MockedTest
$configAdapter->shouldReceive('load')->andReturn([])->once();
$configAdapter->shouldReceive('isLoaded')->with('test', 'it')->andReturn(false)->once();
$configAdapter->shouldReceive('get')->with('test', 'it')->andReturn('!<unset>!')->once();
$configAdapter->shouldReceive('get')->with('test', 'it')->andReturn(null)->once();
$configAdapter->shouldReceive('isLoaded')->with('test', 'it')->andReturn(false)->once();
$configAdapter->shouldReceive('get')->with('test', 'it')->andReturn($data)->once();
@ -234,7 +234,7 @@ class ConfigurationTest extends MockedTest
$this->assertTrue($configuration->delete('test', 'it'));
$this->assertNull($configuration->get('test', 'it'));
$this->assertEquals('!<unset>!', $configuration->getCache()->get('test', 'it'));
$this->assertNull($configuration->getCache()->get('test', 'it'));
$this->assertEmpty($configuration->getCache()->getAll());
}

View file

@ -145,7 +145,7 @@ class PConfigurationTest extends MockedTest
$configAdapter->shouldReceive('isLoaded')->with($uid, 'test', 'it')->andReturn(true)->twice();
$configAdapter->shouldReceive('get')->with($uid, 'test', 'it')->andReturn($data)->once();
$configAdapter->shouldReceive('isLoaded')->with($uid, 'test', 'not')->andReturn(false)->once();
$configAdapter->shouldReceive('get')->with($uid, 'test', 'not')->andReturn('!<unset>!')->once();
$configAdapter->shouldReceive('get')->with($uid, 'test', 'not')->andReturn(null)->once();
$configuration = new PConfiguration($configCache, $configAdapter);
@ -173,7 +173,7 @@ class PConfigurationTest extends MockedTest
$configAdapter->shouldReceive('isConnected')->andReturn(true)->times(3);
$configAdapter->shouldReceive('isLoaded')->with($uid, 'test', 'it')->andReturn(false)->once();
$configAdapter->shouldReceive('get')->with($uid, 'test', 'it')->andReturn('!<unset>!')->once();
$configAdapter->shouldReceive('get')->with($uid, 'test', 'it')->andReturn(null)->once();
$configAdapter->shouldReceive('isLoaded')->with($uid, 'test', 'it')->andReturn(false)->once();
$configAdapter->shouldReceive('get')->with($uid, 'test', 'it')->andReturn($data)->once();