Config FollowUp
- New Configuration (Config is now only holding the instance) - New PConfiguration (PConfig is now only holding the instance) - Config & PConfig-Adapter don't need "ConfigCache" anymore - DB-Connection is now outside App->reload() for better dependency-chaining
This commit is contained in:
parent
c36a0eabdb
commit
eafcf3592d
59 changed files with 1754 additions and 1038 deletions
|
@ -1,9 +1,9 @@
|
|||
<?php
|
||||
|
||||
namespace Friendica\Test\Core\Config;
|
||||
namespace Friendica\Test\Core\Config\Cache;
|
||||
|
||||
use Friendica\Core\Config\ConfigCache;
|
||||
use Friendica\Core\Config\ConfigCacheLoader;
|
||||
use Friendica\Core\Config\Cache\ConfigCache;
|
||||
use Friendica\Core\Config\Cache\ConfigCacheLoader;
|
||||
use Friendica\Test\MockedTest;
|
||||
use Friendica\Test\Util\VFSTrait;
|
||||
use org\bovigo\vfs\vfsStream;
|
||||
|
@ -59,6 +59,7 @@ class ConfigCacheLoaderTest extends MockedTest
|
|||
$this->delConfigFile('local.config.php');
|
||||
|
||||
$file = dirname(__DIR__) . DIRECTORY_SEPARATOR .
|
||||
'..' . DIRECTORY_SEPARATOR .
|
||||
'..' . DIRECTORY_SEPARATOR .
|
||||
'..' . DIRECTORY_SEPARATOR .
|
||||
'datasets' . DIRECTORY_SEPARATOR .
|
||||
|
@ -91,6 +92,7 @@ class ConfigCacheLoaderTest extends MockedTest
|
|||
$this->delConfigFile('local.config.php');
|
||||
|
||||
$file = dirname(__DIR__) . DIRECTORY_SEPARATOR .
|
||||
'..' . DIRECTORY_SEPARATOR .
|
||||
'..' . DIRECTORY_SEPARATOR .
|
||||
'..' . DIRECTORY_SEPARATOR .
|
||||
'datasets' . DIRECTORY_SEPARATOR .
|
||||
|
@ -122,6 +124,7 @@ class ConfigCacheLoaderTest extends MockedTest
|
|||
$this->delConfigFile('local.config.php');
|
||||
|
||||
$file = dirname(__DIR__) . DIRECTORY_SEPARATOR .
|
||||
'..' . DIRECTORY_SEPARATOR .
|
||||
'..' . DIRECTORY_SEPARATOR .
|
||||
'..' . DIRECTORY_SEPARATOR .
|
||||
'datasets' . DIRECTORY_SEPARATOR .
|
||||
|
@ -160,6 +163,7 @@ class ConfigCacheLoaderTest extends MockedTest
|
|||
vfsStream::create($structure, $this->root);
|
||||
|
||||
$file = dirname(__DIR__) . DIRECTORY_SEPARATOR .
|
||||
'..' . DIRECTORY_SEPARATOR .
|
||||
'..' . DIRECTORY_SEPARATOR .
|
||||
'..' . DIRECTORY_SEPARATOR .
|
||||
'datasets' . DIRECTORY_SEPARATOR .
|
|
@ -1,8 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace Friendica\Test\Core\Config;
|
||||
namespace Friendica\Test\Core\Config\Cache;
|
||||
|
||||
use Friendica\Core\Config\ConfigCache;
|
||||
use Friendica\Core\Config\Cache\ConfigCache;
|
||||
use Friendica\Test\MockedTest;
|
||||
|
||||
class ConfigCacheTest extends MockedTest
|
||||
|
@ -48,7 +48,7 @@ class ConfigCacheTest extends MockedTest
|
|||
public function testLoadConfigArray($data)
|
||||
{
|
||||
$configCache = new ConfigCache();
|
||||
$configCache->loadConfigArray($data);
|
||||
$configCache->load($data);
|
||||
|
||||
$this->assertConfigValues($data, $configCache);
|
||||
}
|
||||
|
@ -67,18 +67,38 @@ class ConfigCacheTest extends MockedTest
|
|||
];
|
||||
|
||||
$configCache = new ConfigCache();
|
||||
$configCache->loadConfigArray($data);
|
||||
$configCache->loadConfigArray($override);
|
||||
$configCache->load($data);
|
||||
$configCache->load($override);
|
||||
|
||||
$this->assertConfigValues($data, $configCache);
|
||||
|
||||
// override the value
|
||||
$configCache->loadConfigArray($override, true);
|
||||
$configCache->load($override, true);
|
||||
|
||||
$this->assertEquals($override['system']['test'], $configCache->get('system', 'test'));
|
||||
$this->assertEquals($override['system']['boolTrue'], $configCache->get('system', 'boolTrue'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the loadConfigArray() method with wrong/empty datasets
|
||||
*/
|
||||
public function testLoadConfigArrayWrong()
|
||||
{
|
||||
$configCache = new ConfigCache();
|
||||
|
||||
// empty dataset
|
||||
$configCache->load([]);
|
||||
$this->assertEmpty($configCache->getAll());
|
||||
|
||||
// wrong dataset
|
||||
$configCache->load(['system' => 'not_array']);
|
||||
$this->assertEmpty($configCache->getAll());
|
||||
|
||||
// incomplete dataset (key is integer ID of the array)
|
||||
$configCache->load(['system' => ['value']]);
|
||||
$this->assertEquals('value', $configCache->get('system', 0));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the getAll() method
|
||||
* @dataProvider dataTests
|
||||
|
@ -86,14 +106,12 @@ class ConfigCacheTest extends MockedTest
|
|||
public function testGetAll($data)
|
||||
{
|
||||
$configCache = new ConfigCache();
|
||||
$configCache->loadConfigArray($data);
|
||||
$configCache->load($data);
|
||||
|
||||
$all = $configCache->getAll();
|
||||
|
||||
$this->assertContains($data['system'], $all);
|
||||
|
||||
// config values are stored directly in the array base
|
||||
$this->assertEquals($data['config']['a'], $all['a']);
|
||||
$this->assertContains($data['config'], $all);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -113,6 +131,33 @@ class ConfigCacheTest extends MockedTest
|
|||
$this->assertConfigValues($data, $configCache);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the get() method without a value
|
||||
*/
|
||||
public function testGetEmpty()
|
||||
{
|
||||
$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'));
|
||||
|
||||
$configCache->set('system', 'test', 'it');
|
||||
$this->assertTrue($configCache->has('system', 'test'));
|
||||
|
||||
$this->assertFalse($configCache->has('system', null));
|
||||
$configCache->set('system', null, 'it');
|
||||
$this->assertTrue($configCache->has('system', null));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the delete() method
|
||||
* @dataProvider dataTests
|
||||
|
@ -172,4 +217,22 @@ 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'));
|
||||
|
||||
$configCache->setP($uid, 'system', 'test', 'it');
|
||||
$this->assertTrue($configCache->hasP($uid, 'system', 'test'));
|
||||
|
||||
$this->assertFalse($configCache->hasP($uid, 'system', null));
|
||||
$configCache->setP($uid, 'system', null, 'it');
|
||||
$this->assertTrue($configCache->hasP($uid, 'system', null));
|
||||
}
|
||||
}
|
215
tests/src/Core/Config/ConfigurationTest.php
Normal file
215
tests/src/Core/Config/ConfigurationTest.php
Normal file
|
@ -0,0 +1,215 @@
|
|||
<?php
|
||||
|
||||
namespace Friendica\Test\Core\Config;
|
||||
|
||||
use Friendica\Core\Config\Cache\ConfigCache;
|
||||
use Friendica\Core\Config\Cache\IConfigCache;
|
||||
use Friendica\Core\Config\Configuration;
|
||||
use Friendica\Test\MockedTest;
|
||||
|
||||
class ConfigurationTest extends MockedTest
|
||||
{
|
||||
/**
|
||||
* Test the configuration initialization
|
||||
*/
|
||||
public function testSetUp()
|
||||
{
|
||||
$configCache = new ConfigCache();
|
||||
$configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IConfigAdapter');
|
||||
$configAdapter->shouldReceive('isConnected')->andReturn(false)->once();
|
||||
|
||||
$configuration = new Configuration($configCache, $configAdapter);
|
||||
|
||||
$this->assertInstanceOf(IConfigCache::class, $configuration->getCache());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the configuration load() method
|
||||
*/
|
||||
public function testCacheLoad()
|
||||
{
|
||||
$configCache = new ConfigCache();
|
||||
$configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IConfigAdapter');
|
||||
$configAdapter->shouldReceive('isConnected')->andReturn(true)->twice();
|
||||
// constructor loading
|
||||
$configAdapter->shouldReceive('load')->andReturn([])->once();
|
||||
// expected loading
|
||||
$configAdapter->shouldReceive('load')->andReturn(['testing' => ['test' => 'it']])->once();
|
||||
|
||||
$configuration = new Configuration($configCache, $configAdapter);
|
||||
$configuration->load('testing');
|
||||
|
||||
$this->assertEquals('it', $configuration->get('testing', 'test'));
|
||||
$this->assertEquals('it', $configuration->getCache()->get('testing', 'test'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if 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);
|
||||
// constructor loading
|
||||
$configAdapter->shouldReceive('load')->andReturn([])->once();
|
||||
// expected loading
|
||||
$configAdapter->shouldReceive('load')->andReturn(['testing' => ['test' => 'it']])->once();
|
||||
// expected next loading
|
||||
$configAdapter->shouldReceive('load')->andReturn(['testing' => ['test' => 'again']])->once();
|
||||
|
||||
$configuration = new Configuration($configCache, $configAdapter);
|
||||
$configuration->load('testing');
|
||||
|
||||
$this->assertEquals('it', $configuration->get('testing', 'test'));
|
||||
$this->assertEquals('it', $configuration->getCache()->get('testing', 'test'));
|
||||
|
||||
$configuration->load('testing');
|
||||
|
||||
$this->assertEquals('again', $configuration->get('testing', 'test'));
|
||||
$this->assertEquals('again', $configuration->getCache()->get('testing', 'test'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the configuration get() and set() methods without adapter
|
||||
*/
|
||||
public function testSetGetWithoutDB()
|
||||
{
|
||||
$configCache = new ConfigCache();
|
||||
$configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IConfigAdapter');
|
||||
$configAdapter->shouldReceive('isConnected')->andReturn(false)->twice();
|
||||
|
||||
$configuration = new Configuration($configCache, $configAdapter);
|
||||
|
||||
$this->assertTrue($configuration->set('test', 'it', 'now'));
|
||||
|
||||
$this->assertEquals('now', $configuration->get('test', 'it'));
|
||||
$this->assertEquals('now', $configuration->getCache()->get('test', 'it'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the configuration get() and set() methods with adapter
|
||||
*/
|
||||
public function testSetGetWithDB()
|
||||
{
|
||||
$configCache = new ConfigCache();
|
||||
$configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IConfigAdapter');
|
||||
$configAdapter->shouldReceive('isConnected')->andReturn(true)->twice();
|
||||
// constructor loading
|
||||
$configAdapter->shouldReceive('load')->andReturn([])->once();
|
||||
$configAdapter->shouldReceive('set')->with('test', 'it', 'now')->andReturn(true)->once();
|
||||
|
||||
$configuration = new Configuration($configCache, $configAdapter);
|
||||
|
||||
$this->assertTrue($configuration->set('test', 'it', 'now'));
|
||||
|
||||
$this->assertEquals('now', $configuration->get('test', 'it'));
|
||||
$this->assertEquals('now', $configuration->getCache()->get('test', 'it'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the configuration get() method with wrong value and no db
|
||||
*/
|
||||
public function testGetWrongWithoutDB()
|
||||
{
|
||||
$configCache = new ConfigCache();
|
||||
$configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IConfigAdapter');
|
||||
$configAdapter->shouldReceive('isConnected')->andReturn(false)->times(4);
|
||||
|
||||
$configuration = new Configuration($configCache, $configAdapter);
|
||||
|
||||
// without refresh
|
||||
$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'));
|
||||
|
||||
// with default value
|
||||
$this->assertEquals('default', $configuration->get('test', 'it', 'default'));
|
||||
|
||||
// with default value and refresh
|
||||
$this->assertEquals('default', $configuration->get('test', 'it', 'default', true));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the configuration get() method with refresh
|
||||
*/
|
||||
public function testGetWithRefresh()
|
||||
{
|
||||
$configCache = new ConfigCache(['test' => ['it' => 'now']]);
|
||||
$configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IConfigAdapter');
|
||||
$configAdapter->shouldReceive('isConnected')->andReturn(true)->times(3);
|
||||
// constructor loading
|
||||
$configAdapter->shouldReceive('load')->andReturn([])->once();
|
||||
$configAdapter->shouldReceive('get')->with('test', 'it')->andReturn('again')->once();
|
||||
$configAdapter->shouldReceive('get')->with('test', 'not')->andReturn('!<unset>!')->once();
|
||||
|
||||
$configuration = new Configuration($configCache, $configAdapter);
|
||||
|
||||
// without refresh
|
||||
$this->assertEquals('now', $configuration->get('test', 'it'));
|
||||
$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'));
|
||||
|
||||
// without refresh and wrong value and default
|
||||
$this->assertEquals('default', $configuration->get('test', 'not', 'default'));
|
||||
$this->assertEquals('!<unset>!', $configuration->getCache()->get('test', 'not'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the configuration delete() method without adapter
|
||||
*/
|
||||
public function testDeleteWithoutDB()
|
||||
{
|
||||
$configCache = new ConfigCache(['test' => ['it' => 'now']]);
|
||||
$configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IConfigAdapter');
|
||||
$configAdapter->shouldReceive('isConnected')->andReturn(false)->times(3);
|
||||
|
||||
$configuration = new Configuration($configCache, $configAdapter);
|
||||
|
||||
$this->assertEquals('now', $configuration->get('test', 'it'));
|
||||
$this->assertEquals('now', $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'));
|
||||
|
||||
$this->assertEmpty($configuration->getCache()->getAll());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the configuration delete() method with adapter
|
||||
*/
|
||||
public function testDeleteWithDB()
|
||||
{
|
||||
$configCache = new ConfigCache(['test' => ['it' => 'now', 'quarter' => 'true']]);
|
||||
$configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IConfigAdapter');
|
||||
$configAdapter->shouldReceive('isConnected')->andReturn(true)->times(5);
|
||||
// constructor loading
|
||||
$configAdapter->shouldReceive('load')->andReturn([])->once();
|
||||
$configAdapter->shouldReceive('delete')->with('test', 'it')->andReturn(false)->once();
|
||||
|
||||
$configAdapter->shouldReceive('delete')->with('test', 'second')->andReturn(true)->once();
|
||||
$configAdapter->shouldReceive('delete')->with('test', 'third')->andReturn(false)->once();
|
||||
$configAdapter->shouldReceive('delete')->with('test', 'quarter')->andReturn(true)->once();
|
||||
|
||||
$configuration = new Configuration($configCache, $configAdapter);
|
||||
|
||||
$this->assertEquals('now', $configuration->get('test', 'it'));
|
||||
$this->assertEquals('now', $configuration->getCache()->get('test', 'it'));
|
||||
|
||||
// delete from cache only
|
||||
$this->assertTrue($configuration->delete('test', 'it'));
|
||||
// delete from db only
|
||||
$this->assertTrue($configuration->delete('test', 'second'));
|
||||
// no delete
|
||||
$this->assertFalse($configuration->delete('test', 'third'));
|
||||
// delete both
|
||||
$this->assertTrue($configuration->delete('test', 'quarter'));
|
||||
|
||||
$this->assertEmpty($configuration->getCache()->getAll());
|
||||
}
|
||||
}
|
186
tests/src/Core/Config/PConfigurationTest.php
Normal file
186
tests/src/Core/Config/PConfigurationTest.php
Normal file
|
@ -0,0 +1,186 @@
|
|||
<?php
|
||||
|
||||
namespace Friendica\Test\Core\Config;
|
||||
|
||||
use Friendica\Core\Config\Cache\ConfigCache;
|
||||
use Friendica\Core\Config\PConfiguration;
|
||||
use Friendica\Test\MockedTest;
|
||||
|
||||
class PConfigurationTest extends MockedTest
|
||||
{
|
||||
/**
|
||||
* Test if 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();
|
||||
// expected loading
|
||||
$configAdapter->shouldReceive('load')->andReturn(['testing' => ['test' => 'it']])->once();
|
||||
|
||||
$configuration = new PConfiguration($configCache, $configAdapter);
|
||||
$configuration->load($uid, 'testing');
|
||||
|
||||
$this->assertEquals('it', $configuration->get($uid, 'testing', 'test'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if 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();
|
||||
// expected loading
|
||||
$configAdapter->shouldReceive('load')->andReturn(['testing' => ['test' => 'it']])->once();
|
||||
// expected next loading
|
||||
$configAdapter->shouldReceive('load')->andReturn(['testing' => ['test' => 'again']])->once();
|
||||
|
||||
$configuration = new PConfiguration($configCache, $configAdapter);
|
||||
$configuration->load($uid, 'testing');
|
||||
|
||||
$this->assertEquals('it', $configuration->get($uid, 'testing', 'test'));
|
||||
|
||||
$configuration->load($uid, 'testing');
|
||||
|
||||
$this->assertEquals('again', $configuration->get($uid, 'testing', 'test'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the configuration get() and set() methods without adapter
|
||||
*/
|
||||
public function testSetGetWithoutDB()
|
||||
{
|
||||
$uid = 234;
|
||||
$configCache = new ConfigCache();
|
||||
$configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IPConfigAdapter');
|
||||
$configAdapter->shouldReceive('isConnected')->andReturn(false)->once();
|
||||
|
||||
$configuration = new PConfiguration($configCache, $configAdapter);
|
||||
|
||||
$this->assertTrue($configuration->set($uid, 'test', 'it', 'now'));
|
||||
|
||||
$this->assertEquals('now', $configuration->get($uid, 'test', 'it'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if the configuration get() and set() methods with adapter
|
||||
*/
|
||||
public function testSetGetWithDB()
|
||||
{
|
||||
$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();
|
||||
|
||||
$configuration = new PConfiguration($configCache, $configAdapter);
|
||||
|
||||
$this->assertTrue($configuration->set($uid, 'test', 'it', 'now'));
|
||||
|
||||
$this->assertEquals('now', $configuration->get($uid, 'test', 'it'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the configuration get() method with wrong value and no db
|
||||
*/
|
||||
public function testGetWrongWithoutDB()
|
||||
{
|
||||
$uid = 234;
|
||||
$configCache = new ConfigCache();
|
||||
$configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IPConfigAdapter');
|
||||
$configAdapter->shouldReceive('isConnected')->andReturn(false)->times(3);
|
||||
|
||||
$configuration = new PConfiguration($configCache, $configAdapter);
|
||||
|
||||
// without refresh
|
||||
$this->assertNull($configuration->get($uid, 'test', 'it'));
|
||||
|
||||
// with default value
|
||||
$this->assertEquals('default', $configuration->get($uid, 'test', 'it', 'default'));
|
||||
|
||||
// with default value and refresh
|
||||
$this->assertEquals('default', $configuration->get($uid, 'test', 'it', 'default', true));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the configuration get() method with refresh
|
||||
*/
|
||||
public function testGetWithRefresh()
|
||||
{
|
||||
$uid = 234;
|
||||
$configCache = new ConfigCache();
|
||||
$configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IPConfigAdapter');
|
||||
$configAdapter->shouldReceive('isConnected')->andReturn(true)->times(3);
|
||||
$configAdapter->shouldReceive('get')->with($uid, 'test', 'it')->andReturn('now')->once();
|
||||
$configAdapter->shouldReceive('get')->with($uid, 'test', 'it')->andReturn('again')->once();
|
||||
$configAdapter->shouldReceive('get')->with($uid, 'test', 'not')->andReturn('!<unset>!')->once();
|
||||
|
||||
$configuration = new PConfiguration($configCache, $configAdapter);
|
||||
|
||||
// without refresh
|
||||
$this->assertEquals('now', $configuration->get($uid, 'test', 'it'));
|
||||
// use the cache again
|
||||
$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));
|
||||
|
||||
// without refresh and wrong value and default
|
||||
$this->assertEquals('default', $configuration->get($uid, 'test', 'not', 'default'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the configuration delete() method without adapter
|
||||
*/
|
||||
public function testDeleteWithoutDB()
|
||||
{
|
||||
$uid = 234;
|
||||
$configCache = new ConfigCache();
|
||||
$configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IPConfigAdapter');
|
||||
$configAdapter->shouldReceive('isConnected')->andReturn(false)->times(3);
|
||||
|
||||
$configuration = new PConfiguration($configCache, $configAdapter);
|
||||
|
||||
$this->assertTrue($configuration->set($uid, 'test', 'it', 'now'));
|
||||
$this->assertEquals('now', $configuration->get($uid, 'test', 'it'));
|
||||
|
||||
$this->assertTrue($configuration->delete($uid, 'test', 'it'));
|
||||
$this->assertNull($configuration->get($uid, 'test', 'it'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the configuration delete() method with adapter
|
||||
*/
|
||||
public function testDeleteWithDB()
|
||||
{
|
||||
$uid = 234;
|
||||
$configCache = new ConfigCache();
|
||||
$configAdapter = \Mockery::mock('Friendica\Core\Config\Adapter\IPConfigAdapter');
|
||||
$configAdapter->shouldReceive('isConnected')->andReturn(true)->times(5);
|
||||
$configAdapter->shouldReceive('set')->with($uid, 'test', 'it', 'now')->andReturn(false)->once();
|
||||
$configAdapter->shouldReceive('delete')->with($uid, 'test', 'it')->andReturn(false)->once();
|
||||
|
||||
$configAdapter->shouldReceive('delete')->with($uid, 'test', 'second')->andReturn(true)->once();
|
||||
$configAdapter->shouldReceive('delete')->with($uid, 'test', 'third')->andReturn(false)->once();
|
||||
$configAdapter->shouldReceive('delete')->with($uid, 'test', 'quarter')->andReturn(true)->once();
|
||||
|
||||
$configuration = new PConfiguration($configCache, $configAdapter);
|
||||
|
||||
$this->assertFalse($configuration->set($uid, 'test', 'it', 'now'));
|
||||
$this->assertEquals('now', $configuration->get($uid, 'test', 'it'));
|
||||
|
||||
// delete from set
|
||||
$this->assertTrue($configuration->delete($uid, 'test', 'it'));
|
||||
// delete from db only
|
||||
$this->assertTrue($configuration->delete($uid, 'test', 'second'));
|
||||
// no delete
|
||||
$this->assertFalse($configuration->delete($uid, 'test', 'third'));
|
||||
// delete both
|
||||
$this->assertTrue($configuration->delete($uid, 'test', 'quarter'));
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue