renamed Logger::setLogger() to Logger::init()
authorPhilipp Holzer <admin@philipp.info>
Mon, 11 Feb 2019 20:36:26 +0000 (21:36 +0100)
committerPhilipp Holzer <admin@philipp.info>
Sun, 17 Feb 2019 19:44:08 +0000 (20:44 +0100)
12 files changed:
src/Core/Config/Adapter/IConfigAdapter.php
src/Core/Config/Adapter/IPConfigAdapter.php
src/Core/Config/Adapter/JITConfigAdapter.php
src/Core/Config/Adapter/JITPConfigAdapter.php
src/Core/Config/Adapter/PreloadConfigAdapter.php
src/Core/Config/Adapter/PreloadPConfigAdapter.php
src/Core/Config/Configuration.php
src/Core/Config/PConfiguration.php
src/Core/Logger.php
src/Factory/LoggerFactory.php
tests/src/Core/Config/ConfigurationTest.php
tests/src/Core/Config/PConfigurationTest.php

index 3bbbbbe..8223d33 100644 (file)
@@ -29,8 +29,7 @@ interface IConfigAdapter
        public function get($cat, $key);
 
        /**
-        * Stores a config value ($value) in the category ($family) under the key ($key)
-        * for the user_id $uid.
+        * Stores a config value ($value) in the category ($family) under the key ($key).
         *
         * Note: Please do not store booleans - convert to 0/1 integer values!
         *
@@ -59,4 +58,14 @@ interface IConfigAdapter
         * @return bool
         */
        public function isConnected();
+
+       /**
+        * Checks, if a config value ($value) in the category ($cat) is already loaded.
+        *
+        * @param string $cat The configuration category
+        * @param string $key The configuration key
+        *
+        * @return bool
+        */
+       public function isLoaded($cat, $key);
 }
index 3e821ef..e9f3892 100644 (file)
@@ -69,4 +69,15 @@ interface IPConfigAdapter
         * @return bool
         */
        public function isConnected();
+
+       /**
+        * Checks, if a config value ($value) in the category ($cat) is already loaded for the user_id $uid.
+        *
+        * @param string $uid The user_id
+        * @param string $cat The configuration category
+        * @param string $key The configuration key
+        *
+        * @return bool
+        */
+       public function isLoaded($uid, $cat, $key);
 }
index 8dadfff..9521177 100644 (file)
@@ -120,4 +120,16 @@ class JITConfigAdapter extends AbstractDbaConfigAdapter implements IConfigAdapte
 
                return $result;
        }
+
+       /**
+        * {@inheritdoc}
+        */
+       public function isLoaded($cat, $key)
+       {
+               if (!$this->isConnected()) {
+                       return false;
+               }
+
+               return (isset($this->in_db[$cat][$key])) && $this->in_db[$cat][$key];
+       }
 }
index 950dd58..697e271 100644 (file)
@@ -36,7 +36,7 @@ class JITPConfigAdapter extends AbstractDbaConfigAdapter implements IPConfigAdap
                        }
                } else if ($cat != 'config') {
                        // Negative caching
-                       $return[null] = "!<unset>!";
+                       $return = "!<unset>!";
                }
                DBA::close($pconfigs);
 
@@ -123,4 +123,16 @@ class JITPConfigAdapter extends AbstractDbaConfigAdapter implements IPConfigAdap
 
                return $result;
        }
+
+       /**
+        * {@inheritdoc}
+        */
+       public function isLoaded($uid, $cat, $key)
+       {
+               if (!$this->isConnected()) {
+                       return false;
+               }
+
+               return (isset($this->in_db[$uid][$cat][$key])) && $this->in_db[$uid][$cat][$key];
+       }
 }
index 8cad5c5..a12c2a7 100644 (file)
@@ -32,13 +32,13 @@ class PreloadConfigAdapter extends AbstractDbaConfigAdapter implements IConfigAd
 
                $configs = DBA::select('config', ['cat', 'v', 'k']);
                while ($config = DBA::fetch($configs)) {
-                       $return[$config['k']] = $config['v'];
+                       $return[$config['cat']][$config['k']] = $config['v'];
                }
                DBA::close($configs);
 
                $this->config_loaded = true;
 
-               return [$cat => $return];
+               return $return;
        }
 
        /**
@@ -101,4 +101,16 @@ class PreloadConfigAdapter extends AbstractDbaConfigAdapter implements IConfigAd
 
                return $result;
        }
+
+       /**
+        * {@inheritdoc}
+        */
+       public function isLoaded($cat, $key)
+       {
+               if (!$this->isConnected()) {
+                       return false;
+               }
+
+               return $this->config_loaded;
+       }
 }
index d117ed3..d1c44d9 100644 (file)
@@ -44,13 +44,13 @@ class PreloadPConfigAdapter extends AbstractDbaConfigAdapter implements IPConfig
 
                $pconfigs = DBA::select('pconfig', ['cat', 'v', 'k'], ['uid' => $uid]);
                while ($pconfig = DBA::fetch($pconfigs)) {
-                       $return[$pconfig['k']] = $pconfig['v'];
+                       $return[$pconfig['cat']][$pconfig['k']] = $pconfig['v'];
                }
                DBA::close($pconfigs);
 
                $this->config_loaded = true;
 
-               return [$cat => $return];
+               return $return;
        }
 
        /**
@@ -123,4 +123,16 @@ class PreloadPConfigAdapter extends AbstractDbaConfigAdapter implements IPConfig
 
                return $result;
        }
+
+       /**
+        * {@inheritdoc}
+        */
+       public function isLoaded($uid, $cat, $key)
+       {
+               if (!$this->isConnected()) {
+                       return false;
+               }
+
+               return $this->config_loaded;
+       }
 }
index ccb9abd..2ad11b0 100644 (file)
@@ -79,22 +79,20 @@ class Configuration
         */
        public function get($cat, $key, $default_value = null, $refresh = false)
        {
-               // Return the value of the cache if found and no refresh is forced
-               if (!$refresh && $this->configCache->has($cat, $key)) {
-                       return $this->configCache->get($cat, $key);
+               // if the value isn't loaded or refresh is needed, load it to the cache
+               if ($this->configAdapter->isConnected() &&
+                       (!$this->configAdapter->isLoaded($cat, $key) ||
+                       $refresh)) {
+                       $dbvalue = $this->configAdapter->get($cat, $key);
+
+                       if ($dbvalue !== '!<unset>!') {
+                               $this->configCache->set($cat, $key, $dbvalue);
+                       }
                }
 
-               // if we don't find the value in the cache and the adapter isn't ready, return the default value
-               if (!$this->configAdapter->isConnected()) {
-                       return $default_value;
-               }
-
-               // load DB value to cache
-               $dbvalue = $this->configAdapter->get($cat, $key);
-
-               if ($dbvalue !== '!<unset>!') {
-                       $this->configCache->set($cat, $key, $dbvalue);
-                       return $dbvalue;
+               // use the config cache for return
+               if ($this->configCache->has($cat, $key)) {
+                       return $this->configCache->get($cat, $key);
                } else {
                        return $default_value;
                }
index d3c848c..cf7ef6a 100644 (file)
@@ -71,22 +71,20 @@ class PConfiguration
         */
        public function get($uid, $cat, $key, $default_value = null, $refresh = false)
        {
-               // Return the value of the cache if found and no refresh is forced
-               if (!$refresh && $this->configCache->hasP($uid, $cat, $key)) {
-                       return $this->configCache->getP($uid, $cat, $key);
+               // if the value isn't loaded or refresh is needed, load it to the cache
+               if ($this->configAdapter->isConnected() &&
+                       (!$this->configAdapter->isLoaded($uid, $cat, $key) ||
+                               $refresh)) {
+                       $dbValue = $this->configAdapter->get($uid, $cat, $key);
+
+                       if ($dbValue !== '!<unset>!') {
+                               $this->configCache->setP($uid, $cat, $key, $dbValue);
+                       }
                }
 
-               // if we don't find the value in the cache and the adapter isn't ready, return the default value
-               if (!$this->configAdapter->isConnected()) {
-                       return $default_value;
-               }
-
-               // load DB value to cache
-               $dbvalue = $this->configAdapter->get($uid, $cat, $key);
-
-               if ($dbvalue !== '!<unset>!') {
-                       $this->configCache->setP($uid, $cat, $key, $dbvalue);
-                       return $dbvalue;
+               // use the config cache for return
+               if ($this->configCache->hasP($uid, $cat, $key)) {
+                       return $this->configCache->getP($uid, $cat, $key);
                } else {
                        return $default_value;
                }
index a2e5873..67e58ef 100644 (file)
@@ -68,7 +68,7 @@ class Logger extends BaseObject
         *
         * @param LoggerInterface $logger The Logger instance of this Application
         */
-       public static function setLogger($logger)
+       public static function init($logger)
        {
                self::$logger = $logger;
        }
index 74f55e6..bbe3b0a 100644 (file)
@@ -44,7 +44,7 @@ class LoggerFactory
                        static::addStreamHandler($logger, $stream, $loglevel);
                }
 
-               Logger::setLogger($logger);
+               Logger::init($logger);
 
                return $logger;
        }
index 6ce81a4..0437f1e 100644 (file)
@@ -9,6 +9,20 @@ use Friendica\Test\MockedTest;
 
 class ConfigurationTest extends MockedTest
 {
+       public function dataTests()
+       {
+               return [
+                       'string'       => ['data' => 'it'],
+                       'boolTrue'     => ['data' => true],
+                       'boolFalse'    => ['data' => false],
+                       'integer'      => ['data' => 235],
+                       'decimal'      => ['data' => 2.456],
+                       'array'        => ['data' => ['1', 2, '3', true, false]],
+                       'boolIntTrue'  => ['data' => 1],
+                       'boolIntFalse' => ['Data' => 0],
+               ];
+       }
+
        /**
         * Test the configuration initialization
         */
@@ -24,17 +38,18 @@ class ConfigurationTest extends MockedTest
        }
 
        /**
-        * Test if the configuration load() method
+        * Test the configuration load() method
         */
        public function testCacheLoad()
        {
                $configCache = new ConfigCache();
                $configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IConfigAdapter');
-               $configAdapter->shouldReceive('isConnected')->andReturn(true)->twice();
+               $configAdapter->shouldReceive('isConnected')->andReturn(true)->times(3);
                // constructor loading
                $configAdapter->shouldReceive('load')->andReturn([])->once();
                // expected loading
                $configAdapter->shouldReceive('load')->andReturn(['testing' => ['test' => 'it']])->once();
+               $configAdapter->shouldReceive('isLoaded')->with('testing', 'test')->andReturn(true)->once();
 
                $configuration = new Configuration($configCache, $configAdapter);
                $configuration->load('testing');
@@ -44,17 +59,18 @@ class ConfigurationTest extends MockedTest
        }
 
        /**
-        * Test if the configuration load() method with overwrite
+        * Test the configuration load() method with overwrite
         */
        public function testCacheLoadDouble()
        {
                $configCache = new ConfigCache();
                $configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IConfigAdapter');
-               $configAdapter->shouldReceive('isConnected')->andReturn(true)->times(3);
+               $configAdapter->shouldReceive('isConnected')->andReturn(true)->times(5);
                // constructor loading
                $configAdapter->shouldReceive('load')->andReturn([])->once();
                // expected loading
                $configAdapter->shouldReceive('load')->andReturn(['testing' => ['test' => 'it']])->once();
+               $configAdapter->shouldReceive('isLoaded')->with('testing', 'test')->andReturn(true)->twice();
                // expected next loading
                $configAdapter->shouldReceive('load')->andReturn(['testing' => ['test' => 'again']])->once();
 
@@ -71,40 +87,43 @@ class ConfigurationTest extends MockedTest
        }
 
        /**
-        * Test if the configuration get() and set() methods without adapter
+        * Test the configuration get() and set() methods without adapter
+        * @dataProvider dataTests
         */
-       public function testSetGetWithoutDB()
+       public function testSetGetWithoutDB($data)
        {
                $configCache = new ConfigCache();
                $configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IConfigAdapter');
-               $configAdapter->shouldReceive('isConnected')->andReturn(false)->twice();
+               $configAdapter->shouldReceive('isConnected')->andReturn(false)->times(3);
 
                $configuration = new Configuration($configCache, $configAdapter);
 
-               $this->assertTrue($configuration->set('test', 'it', 'now'));
+               $this->assertTrue($configuration->set('test', 'it', $data));
 
-               $this->assertEquals('now', $configuration->get('test', 'it'));
-               $this->assertEquals('now', $configuration->getCache()->get('test', 'it'));
+               $this->assertEquals($data, $configuration->get('test', 'it'));
+               $this->assertEquals($data, $configuration->getCache()->get('test', 'it'));
        }
 
        /**
-        * Test if the configuration get() and set() methods with adapter
+        * Test the configuration get() and set() methods with adapter
+        * @dataProvider dataTests
         */
-       public function testSetGetWithDB()
+       public function testSetGetWithDB($data)
        {
                $configCache = new ConfigCache();
                $configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IConfigAdapter');
-               $configAdapter->shouldReceive('isConnected')->andReturn(true)->twice();
+               $configAdapter->shouldReceive('isConnected')->andReturn(true)->times(3);
                // constructor loading
                $configAdapter->shouldReceive('load')->andReturn([])->once();
-               $configAdapter->shouldReceive('set')->with('test', 'it', 'now')->andReturn(true)->once();
+               $configAdapter->shouldReceive('isLoaded')->with('test', 'it')->andReturn(true)->once();
+               $configAdapter->shouldReceive('set')->with('test', 'it', $data)->andReturn(true)->once();
 
                $configuration = new Configuration($configCache, $configAdapter);
 
-               $this->assertTrue($configuration->set('test', 'it', 'now'));
+               $this->assertTrue($configuration->set('test', 'it', $data));
 
-               $this->assertEquals('now', $configuration->get('test', 'it'));
-               $this->assertEquals('now', $configuration->getCache()->get('test', 'it'));
+               $this->assertEquals($data, $configuration->get('test', 'it'));
+               $this->assertEquals($data, $configuration->getCache()->get('test', 'it'));
        }
 
        /**
@@ -133,15 +152,18 @@ class ConfigurationTest extends MockedTest
 
        /**
         * Test the configuration get() method with refresh
+        * @dataProvider dataTests
         */
-       public function testGetWithRefresh()
+       public function testGetWithRefresh($data)
        {
                $configCache = new ConfigCache(['test' => ['it' => 'now']]);
                $configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IConfigAdapter');
-               $configAdapter->shouldReceive('isConnected')->andReturn(true)->times(3);
+               $configAdapter->shouldReceive('isConnected')->andReturn(true)->times(4);
                // constructor loading
                $configAdapter->shouldReceive('load')->andReturn([])->once();
-               $configAdapter->shouldReceive('get')->with('test', 'it')->andReturn('again')->once();
+               $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();
 
                $configuration = new Configuration($configCache, $configAdapter);
@@ -151,8 +173,8 @@ class ConfigurationTest extends MockedTest
                $this->assertEquals('now', $configuration->getCache()->get('test', 'it'));
 
                // with refresh
-               $this->assertEquals('again', $configuration->get('test', 'it', null, true));
-               $this->assertEquals('again', $configuration->getCache()->get('test', 'it'));
+               $this->assertEquals($data, $configuration->get('test', 'it', null, true));
+               $this->assertEquals($data, $configuration->getCache()->get('test', 'it'));
 
                // without refresh and wrong value and default
                $this->assertEquals('default', $configuration->get('test', 'not', 'default'));
@@ -160,19 +182,55 @@ class ConfigurationTest extends MockedTest
        }
 
        /**
-        * Test the configuration delete() method without adapter
+        * Test the configuration get() method with different isLoaded settings
+        * @dataProvider dataTests
         */
-       public function testDeleteWithoutDB()
+       public function testGetWithoutLoaded($data)
        {
                $configCache = new ConfigCache(['test' => ['it' => 'now']]);
                $configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IConfigAdapter');
-               $configAdapter->shouldReceive('isConnected')->andReturn(false)->times(3);
+               $configAdapter->shouldReceive('isConnected')->andReturn(true)->times(4);
+               // constructor loading
+               $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('isLoaded')->with('test', 'it')->andReturn(false)->once();
+               $configAdapter->shouldReceive('get')->with('test', 'it')->andReturn($data)->once();
+
+               $configAdapter->shouldReceive('isLoaded')->with('test', 'it')->andReturn(true)->once();
 
                $configuration = new Configuration($configCache, $configAdapter);
 
+               // first run is not loaded and no data is found in the DB
                $this->assertEquals('now', $configuration->get('test', 'it'));
                $this->assertEquals('now', $configuration->getCache()->get('test', 'it'));
 
+               // second run is not loaded, but now data is found in the db (overwrote cache)
+               $this->assertEquals($data, $configuration->get('test', 'it'));
+               $this->assertEquals($data, $configuration->getCache()->get('test', 'it'));
+
+               // third run is loaded and therefore cache is used
+               $this->assertEquals($data, $configuration->get('test', 'it'));
+               $this->assertEquals($data, $configuration->getCache()->get('test', 'it'));
+       }
+
+       /**
+        * Test the configuration delete() method without adapter
+        * @dataProvider dataTests
+        */
+       public function testDeleteWithoutDB($data)
+       {
+               $configCache = new ConfigCache(['test' => ['it' => $data]]);
+               $configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IConfigAdapter');
+               $configAdapter->shouldReceive('isConnected')->andReturn(false)->times(4);
+
+               $configuration = new Configuration($configCache, $configAdapter);
+
+               $this->assertEquals($data, $configuration->get('test', 'it'));
+               $this->assertEquals($data, $configuration->getCache()->get('test', 'it'));
+
                $this->assertTrue($configuration->delete('test', 'it'));
                $this->assertNull($configuration->get('test', 'it'));
                $this->assertEquals('!<unset>!', $configuration->getCache()->get('test', 'it'));
@@ -187,9 +245,11 @@ class ConfigurationTest extends MockedTest
        {
                $configCache = new ConfigCache(['test' => ['it' => 'now', 'quarter' => 'true']]);
                $configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IConfigAdapter');
-               $configAdapter->shouldReceive('isConnected')->andReturn(true)->times(5);
+               $configAdapter->shouldReceive('isConnected')->andReturn(true)->times(6);
                // constructor loading
                $configAdapter->shouldReceive('load')->andReturn([])->once();
+               $configAdapter->shouldReceive('isLoaded')->with('test', 'it')->andReturn(true)->once();
+
                $configAdapter->shouldReceive('delete')->with('test', 'it')->andReturn(false)->once();
 
                $configAdapter->shouldReceive('delete')->with('test', 'second')->andReturn(true)->once();
index 3d8fb58..8ecc9bd 100644 (file)
@@ -8,17 +8,35 @@ use Friendica\Test\MockedTest;
 
 class PConfigurationTest extends MockedTest
 {
+       public function dataTests()
+       {
+               return [
+                       'string'       => ['data' => 'it'],
+                       'boolTrue'     => ['data' => true],
+                       'boolFalse'    => ['data' => false],
+                       'integer'      => ['data' => 235],
+                       'decimal'      => ['data' => 2.456],
+                       'array'        => ['data' => ['1', 2, '3', true, false]],
+                       'boolIntTrue'  => ['data' => 1],
+                       'boolIntFalse' => ['Data' => 0],
+               ];
+       }
+
        /**
-        * Test if the configuration load() method
+        * Test the configuration load() method
         */
        public function testCacheLoad()
        {
                $uid = 234;
                $configCache = new ConfigCache();
                $configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IPConfigAdapter');
-               $configAdapter->shouldReceive('isConnected')->andReturn(true)->once();
+               $configAdapter->shouldReceive('isConnected')->andReturn(true)->twice();
                // expected loading
-               $configAdapter->shouldReceive('load')->andReturn(['testing' => ['test' => 'it']])->once();
+               $configAdapter->shouldReceive('load')
+                       ->with($uid, 'testing')
+                       ->andReturn(['testing' => ['test' => 'it']])
+                       ->once();
+               $configAdapter->shouldReceive('isLoaded')->with($uid, 'testing', 'test')->andReturn(true)->once();
 
                $configuration = new PConfiguration($configCache, $configAdapter);
                $configuration->load($uid, 'testing');
@@ -27,16 +45,17 @@ class PConfigurationTest extends MockedTest
        }
 
        /**
-        * Test if the configuration load() method with overwrite
+        * Test the configuration load() method with overwrite
         */
        public function testCacheLoadDouble()
        {
                $uid = 234;
                $configCache = new ConfigCache();
                $configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IPConfigAdapter');
-               $configAdapter->shouldReceive('isConnected')->andReturn(true)->twice();
+               $configAdapter->shouldReceive('isConnected')->andReturn(true)->times(4);
                // expected loading
-               $configAdapter->shouldReceive('load')->andReturn(['testing' => ['test' => 'it']])->once();
+               $configAdapter->shouldReceive('load')->with($uid, 'testing')->andReturn(['testing' => ['test' => 'it']])->once();
+               $configAdapter->shouldReceive('isLoaded')->with($uid, 'testing', 'test')->andReturn(true)->twice();
                // expected next loading
                $configAdapter->shouldReceive('load')->andReturn(['testing' => ['test' => 'again']])->once();
 
@@ -51,38 +70,41 @@ class PConfigurationTest extends MockedTest
        }
 
        /**
-        * Test if the configuration get() and set() methods without adapter
+        * Test the configuration get() and set() methods without adapter
+        * @dataProvider dataTests
         */
-       public function testSetGetWithoutDB()
+       public function testSetGetWithoutDB($data)
        {
                $uid = 234;
                $configCache = new ConfigCache();
                $configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IPConfigAdapter');
-               $configAdapter->shouldReceive('isConnected')->andReturn(false)->once();
+               $configAdapter->shouldReceive('isConnected')->andReturn(false)->times(2);
 
                $configuration = new PConfiguration($configCache, $configAdapter);
 
-               $this->assertTrue($configuration->set($uid, 'test', 'it', 'now'));
+               $this->assertTrue($configuration->set($uid, 'test', 'it', $data));
 
-               $this->assertEquals('now', $configuration->get($uid, 'test', 'it'));
+               $this->assertEquals($data, $configuration->get($uid, 'test', 'it'));
        }
 
        /**
-        * Test if the configuration get() and set() methods with adapter
+        * Test the configuration get() and set() methods with adapter
+        * @dataProvider dataTests
         */
-       public function testSetGetWithDB()
+       public function testSetGetWithDB($data)
        {
                $uid = 234;
                $configCache = new ConfigCache();
                $configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IPConfigAdapter');
-               $configAdapter->shouldReceive('isConnected')->andReturn(true)->once();
-               $configAdapter->shouldReceive('set')->with($uid, 'test', 'it', 'now')->andReturn(true)->once();
+               $configAdapter->shouldReceive('isConnected')->andReturn(true)->times(2);
+               $configAdapter->shouldReceive('isLoaded')->with($uid, 'test', 'it')->andReturn(true)->once();
+               $configAdapter->shouldReceive('set')->with($uid, 'test', 'it', $data)->andReturn(true)->once();
 
                $configuration = new PConfiguration($configCache, $configAdapter);
 
-               $this->assertTrue($configuration->set($uid, 'test', 'it', 'now'));
+               $this->assertTrue($configuration->set($uid, 'test', 'it', $data));
 
-               $this->assertEquals('now', $configuration->get($uid, 'test', 'it'));
+               $this->assertEquals($data, $configuration->get($uid, 'test', 'it'));
        }
 
        /**
@@ -109,15 +131,19 @@ class PConfigurationTest extends MockedTest
 
        /**
         * Test the configuration get() method with refresh
+        * @dataProvider dataTests
         */
-       public function testGetWithRefresh()
+       public function testGetWithRefresh($data)
        {
                $uid = 234;
                $configCache = new ConfigCache();
                $configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IPConfigAdapter');
-               $configAdapter->shouldReceive('isConnected')->andReturn(true)->times(3);
+               $configAdapter->shouldReceive('isConnected')->andReturn(true)->times(4);
+               $configAdapter->shouldReceive('isLoaded')->with($uid, 'test', 'it')->andReturn(false)->once();
                $configAdapter->shouldReceive('get')->with($uid, 'test', 'it')->andReturn('now')->once();
-               $configAdapter->shouldReceive('get')->with($uid, 'test', 'it')->andReturn('again')->once();
+               $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();
 
                $configuration = new PConfiguration($configCache, $configAdapter);
@@ -128,26 +154,58 @@ class PConfigurationTest extends MockedTest
                $this->assertEquals('now', $configuration->get($uid, 'test', 'it'));
 
                // with refresh (and load the second value out of the db)
-               $this->assertEquals('again', $configuration->get($uid, 'test', 'it', null, true));
+               $this->assertEquals($data, $configuration->get($uid, 'test', 'it', null, true));
 
                // without refresh and wrong value and default
                $this->assertEquals('default', $configuration->get($uid, 'test', 'not', 'default'));
        }
 
+       /**
+        * Test the configuration get() method with different isLoaded settings
+        * @dataProvider dataTests
+        */
+       public function testGetWithoutLoaded($data)
+       {
+               $uid = 234;
+               $configCache = new ConfigCache();
+               $configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IPConfigAdapter');
+               $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('isLoaded')->with($uid, 'test', 'it')->andReturn(false)->once();
+               $configAdapter->shouldReceive('get')->with($uid, 'test', 'it')->andReturn($data)->once();
+
+               $configAdapter->shouldReceive('isLoaded')->with($uid, 'test', 'it')->andReturn(true)->once();
+
+               $configuration = new PConfiguration($configCache, $configAdapter);
+
+               // first run is not loaded and no data is found in the DB
+               $this->assertNull($configuration->get($uid, 'test', 'it'));
+
+               // second run is not loaded, but now data is found in the db (overwrote cache)
+               $this->assertEquals($data, $configuration->get($uid,'test', 'it'));
+
+               // third run is loaded and therefore cache is used
+               $this->assertEquals($data, $configuration->get($uid,'test', 'it'));
+       }
+
        /**
         * Test the configuration delete() method without adapter
+        * @dataProvider dataTests
         */
-       public function testDeleteWithoutDB()
+       public function testDeleteWithoutDB($data)
        {
                $uid = 234;
                $configCache = new ConfigCache();
                $configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IPConfigAdapter');
-               $configAdapter->shouldReceive('isConnected')->andReturn(false)->times(3);
+               $configAdapter->shouldReceive('isConnected')->andReturn(false)->times(4);
 
                $configuration = new PConfiguration($configCache, $configAdapter);
 
-               $this->assertTrue($configuration->set($uid, 'test', 'it', 'now'));
-               $this->assertEquals('now', $configuration->get($uid, 'test', 'it'));
+               $this->assertTrue($configuration->set($uid, 'test', 'it', $data));
+               $this->assertEquals($data, $configuration->get($uid, 'test', 'it'));
 
                $this->assertTrue($configuration->delete($uid, 'test', 'it'));
                $this->assertNull($configuration->get($uid, 'test', 'it'));
@@ -161,8 +219,10 @@ class PConfigurationTest extends MockedTest
                $uid = 234;
                $configCache = new ConfigCache();
                $configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IPConfigAdapter');
-               $configAdapter->shouldReceive('isConnected')->andReturn(true)->times(5);
+               $configAdapter->shouldReceive('isConnected')->andReturn(true)->times(6);
                $configAdapter->shouldReceive('set')->with($uid, 'test', 'it', 'now')->andReturn(false)->once();
+               $configAdapter->shouldReceive('isLoaded')->with($uid, 'test', 'it')->andReturn(true)->once();
+
                $configAdapter->shouldReceive('delete')->with($uid, 'test', 'it')->andReturn(false)->once();
 
                $configAdapter->shouldReceive('delete')->with($uid, 'test', 'second')->andReturn(true)->once();