Merge pull request #6641 from nupplaphil/config_followup

Config FollowUp
This commit is contained in:
Hypolite Petovan 2019-02-17 17:56:31 -05:00 committed by GitHub
commit 256e845c5d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
75 changed files with 2606 additions and 1368 deletions

View file

@ -67,8 +67,7 @@ abstract class CacheTest extends MockedTest
protected function setUp()
{
$this->setUpVfsDir();
$configMock = \Mockery::mock('Friendica\Core\Config\ConfigCache');
$this->mockApp($this->root, $configMock);
$this->mockApp($this->root);
$this->app
->shouldReceive('getHostname')
->andReturn('friendica.local');

View file

@ -12,14 +12,14 @@ class MemcacheCacheDriverTest extends MemoryCacheTest
{
protected function getInstance()
{
$this->configCache
$this->configMock
->shouldReceive('get')
->with('system', 'memcache_host', NULL)
->with('system', 'memcache_host')
->andReturn('localhost');
$this->configCache
$this->configMock
->shouldReceive('get')
->with('system', 'memcache_port', NULL)
->with('system', 'memcache_port')
->andReturn(11211);
$this->cache = CacheDriverFactory::create('memcache');

View file

@ -12,9 +12,9 @@ class MemcachedCacheDriverTest extends MemoryCacheTest
{
protected function getInstance()
{
$this->configCache
$this->configMock
->shouldReceive('get')
->with('system', 'memcached_hosts', NULL)
->with('system', 'memcached_hosts')
->andReturn([0 => 'localhost, 11211']);
$this->cache = CacheDriverFactory::create('memcached');

View file

@ -12,14 +12,14 @@ class RedisCacheDriverTest extends MemoryCacheTest
{
protected function getInstance()
{
$this->configCache
$this->configMock
->shouldReceive('get')
->with('system', 'redis_host', NULL)
->with('system', 'redis_host')
->andReturn('localhost');
$this->configCache
$this->configMock
->shouldReceive('get')
->with('system', 'redis_port', NULL)
->with('system', 'redis_port')
->andReturn(null);
$this->cache = CacheDriverFactory::create('redis');

View file

@ -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 .

View file

@ -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,54 @@ 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'));
$this->assertFalse($configCache->has('system'));
$configCache->set('system', 'test', 'it');
$this->assertTrue($configCache->has('system', 'test'));
$this->assertTrue($configCache->has('system'));
}
/**
* Test the get() method with a category
*/
public function testGetCat()
{
$configCache = new ConfigCache([
'system' => [
'key1' => 'value1',
'key2' => 'value2',
],
'config' => [
'key3' => 'value3',
],
]);
$this->assertTrue($configCache->has('system'));
$this->assertEquals([
'key1' => 'value1',
'key2' => 'value2',
], $configCache->get('system'));
}
/**
* Test the delete() method
* @dataProvider dataTests
@ -149,6 +215,32 @@ class ConfigCacheTest extends MockedTest
}
/**
* Test the getP() method with a category
*/
public function testGetPCat()
{
$configCache = new ConfigCache();
$uid = 345;
$configCache->loadP($uid, [
'system' => [
'key1' => 'value1',
'key2' => 'value2',
],
'config' => [
'key3' => 'value3',
],
]);
$this->assertTrue($configCache->hasP($uid,'system'));
$this->assertEquals([
'key1' => 'value1',
'key2' => 'value2',
], $configCache->get($uid, 'system'));
}
/**
* Test the deleteP() method
* @dataProvider dataTests
@ -172,4 +264,20 @@ 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

@ -0,0 +1,276 @@
<?php
namespace Friendica\Test\Core\Config;
use Friendica\Core\Config\Adapter\IConfigAdapter;
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
{
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
*/
public function testSetUp()
{
$configCache = new ConfigCache();
$configAdapter = \Mockery::mock(IConfigAdapter::class);
$configAdapter->shouldReceive('isConnected')->andReturn(false)->once();
$configuration = new Configuration($configCache, $configAdapter);
$this->assertInstanceOf(IConfigCache::class, $configuration->getCache());
}
/**
* Test the configuration load() method
*/
public function testCacheLoad()
{
$configCache = new ConfigCache();
$configAdapter = \Mockery::mock(IConfigAdapter::class);
$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');
$this->assertEquals('it', $configuration->get('testing', 'test'));
$this->assertEquals('it', $configuration->getCache()->get('testing', 'test'));
}
/**
* Test the configuration load() method with overwrite
*/
public function testCacheLoadDouble()
{
$configCache = new ConfigCache();
$configAdapter = \Mockery::mock(IConfigAdapter::class);
$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();
$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 the configuration get() and set() methods without adapter
* @dataProvider dataTests
*/
public function testSetGetWithoutDB($data)
{
$configCache = new ConfigCache();
$configAdapter = \Mockery::mock(IConfigAdapter::class);
$configAdapter->shouldReceive('isConnected')->andReturn(false)->times(3);
$configuration = new Configuration($configCache, $configAdapter);
$this->assertTrue($configuration->set('test', 'it', $data));
$this->assertEquals($data, $configuration->get('test', 'it'));
$this->assertEquals($data, $configuration->getCache()->get('test', 'it'));
}
/**
* Test the configuration get() and set() methods with adapter
* @dataProvider dataTests
*/
public function testSetGetWithDB($data)
{
$configCache = new ConfigCache();
$configAdapter = \Mockery::mock(IConfigAdapter::class);
$configAdapter->shouldReceive('isConnected')->andReturn(true)->times(3);
// constructor loading
$configAdapter->shouldReceive('load')->andReturn([])->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', $data));
$this->assertEquals($data, $configuration->get('test', 'it'));
$this->assertEquals($data, $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(IConfigAdapter::class);
$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
* @dataProvider dataTests
*/
public function testGetWithRefresh($data)
{
$configCache = new ConfigCache(['test' => ['it' => 'now']]);
$configAdapter = \Mockery::mock(IConfigAdapter::class);
$configAdapter->shouldReceive('isConnected')->andReturn(true)->times(4);
// constructor loading
$configAdapter->shouldReceive('load')->andReturn([])->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);
// without refresh
$this->assertEquals('now', $configuration->get('test', 'it'));
$this->assertEquals('now', $configuration->getCache()->get('test', 'it'));
// with refresh
$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'));
$this->assertEquals('!<unset>!', $configuration->getCache()->get('test', 'not'));
}
/**
* Test the configuration get() method with different isLoaded settings
* @dataProvider dataTests
*/
public function testGetWithoutLoaded($data)
{
$configCache = new ConfigCache(['test' => ['it' => 'now']]);
$configAdapter = \Mockery::mock(IConfigAdapter::class);
$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(IConfigAdapter::class);
$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'));
$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(IConfigAdapter::class);
$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();
$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());
}
}

View file

@ -0,0 +1,247 @@
<?php
namespace Friendica\Test\Core\Config;
use Friendica\Core\Config\Adapter\IPConfigAdapter;
use Friendica\Core\Config\Cache\ConfigCache;
use Friendica\Core\Config\PConfiguration;
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 the configuration load() method
*/
public function testCacheLoad()
{
$uid = 234;
$configCache = new ConfigCache();
$configAdapter = \Mockery::mock(IPConfigAdapter::class);
$configAdapter->shouldReceive('isConnected')->andReturn(true)->twice();
// expected loading
$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');
$this->assertEquals('it', $configuration->get($uid, 'testing', 'test'));
}
/**
* Test the configuration load() method with overwrite
*/
public function testCacheLoadDouble()
{
$uid = 234;
$configCache = new ConfigCache();
$configAdapter = \Mockery::mock(IPConfigAdapter::class);
$configAdapter->shouldReceive('isConnected')->andReturn(true)->times(4);
// expected loading
$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();
$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 the configuration get() and set() methods without adapter
* @dataProvider dataTests
*/
public function testSetGetWithoutDB($data)
{
$uid = 234;
$configCache = new ConfigCache();
$configAdapter = \Mockery::mock(IPConfigAdapter::class);
$configAdapter->shouldReceive('isConnected')->andReturn(false)->times(2);
$configuration = new PConfiguration($configCache, $configAdapter);
$this->assertTrue($configuration->set($uid, 'test', 'it', $data));
$this->assertEquals($data, $configuration->get($uid, 'test', 'it'));
}
/**
* Test the configuration get() and set() methods with adapter
* @dataProvider dataTests
*/
public function testSetGetWithDB($data)
{
$uid = 234;
$configCache = new ConfigCache();
$configAdapter = \Mockery::mock(IPConfigAdapter::class);
$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', $data));
$this->assertEquals($data, $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(IPConfigAdapter::class);
$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
* @dataProvider dataTests
*/
public function testGetWithRefresh($data)
{
$uid = 234;
$configCache = new ConfigCache();
$configAdapter = \Mockery::mock(IPConfigAdapter::class);
$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('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);
// 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($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(IPConfigAdapter::class);
$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($data)
{
$uid = 234;
$configCache = new ConfigCache();
$configAdapter = \Mockery::mock(IPConfigAdapter::class);
$configAdapter->shouldReceive('isConnected')->andReturn(false)->times(4);
$configuration = new PConfiguration($configCache, $configAdapter);
$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'));
}
/**
* Test the configuration delete() method with adapter
*/
public function testDeleteWithDB()
{
$uid = 234;
$configCache = new ConfigCache();
$configAdapter = \Mockery::mock(IPConfigAdapter::class);
$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();
$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'));
}
}

View file

@ -52,9 +52,9 @@ class AutomaticInstallationConsoleTest extends ConsoleTest
$this->db_user = getenv('MYSQL_USERNAME') . getenv('MYSQL_USER');
$this->db_pass = getenv('MYSQL_PASSWORD');
$this->configCache
$this->configMock
->shouldReceive('get')
->with('config', 'php_path', NULL)
->with('config', 'php_path')
->andReturn(false);
$this->mockL10nT();

View file

@ -32,14 +32,14 @@ class ConfigConsoleTest extends ConsoleTest
}
function testSetGetKeyValue() {
$this->configCache
$this->configMock
->shouldReceive('set')
->with('config', 'test', 'now')
->andReturn(true)
->once();
$this->configCache
$this->configMock
->shouldReceive('get')
->with('config', 'test', NULL)
->with('config', 'test')
->andReturn('now')
->twice();
@ -50,9 +50,9 @@ class ConfigConsoleTest extends ConsoleTest
$txt = $this->dumpExecute($console);
$this->assertEquals("config.test <= now\n", $txt);
$this->configCache
$this->configMock
->shouldReceive('get')
->with('config', 'test', null)
->with('config', 'test')
->andReturn('now')
->once();
@ -62,9 +62,9 @@ class ConfigConsoleTest extends ConsoleTest
$txt = $this->dumpExecute($console);
$this->assertEquals("config.test => now\n", $txt);
$this->configCache
$this->configMock
->shouldReceive('get')
->with('config', 'test', null)
->with('config', 'test')
->andReturn(null)
->once();
@ -77,9 +77,9 @@ class ConfigConsoleTest extends ConsoleTest
function testSetArrayValue() {
$testArray = [1, 2, 3];
$this->configCache
$this->configMock
->shouldReceive('get')
->with('config', 'test', null)
->with('config', 'test')
->andReturn($testArray)
->once();
@ -105,9 +105,9 @@ class ConfigConsoleTest extends ConsoleTest
}
function testVerbose() {
$this->configCache
$this->configMock
->shouldReceive('get')
->with('test', 'it', null)
->with('test', 'it')
->andReturn('now')
->once();
$console = new Config($this->consoleArgv);
@ -133,14 +133,14 @@ CONF;
}
function testUnableToSet() {
$this->configCache
$this->configMock
->shouldReceive('set')
->with('test', 'it', 'now')
->andReturn(false)
->once();
$this->configCache
$this->configMock
->shouldReceive('get')
->with('test', 'it', NULL)
->with('test', 'it')
->andReturn(NULL)
->once();
$console = new Config();

View file

@ -29,8 +29,7 @@ abstract class ConsoleTest extends MockedTest
Intercept::setUp();
$this->setUpVfsDir();
$configMock = \Mockery::mock('Friendica\Core\Config\ConfigCache');
$this->mockApp($this->root, $configMock);
$this->mockApp($this->root);
}
/**

View file

@ -27,8 +27,7 @@ abstract class LockTest extends MockedTest
{
// Reusable App object
$this->setUpVfsDir();
$configMock = \Mockery::mock('Friendica\Core\Config\ConfigCache');
$this->mockApp($this->root, $configMock);
$this->mockApp($this->root);
$this->app
->shouldReceive('getHostname')
->andReturn('friendica.local');

View file

@ -13,14 +13,14 @@ class MemcacheCacheLockDriverTest extends LockTest
{
protected function getInstance()
{
$this->configCache
$this->configMock
->shouldReceive('get')
->with('system', 'memcache_host', NULL)
->with('system', 'memcache_host')
->andReturn('localhost');
$this->configCache
$this->configMock
->shouldReceive('get')
->with('system', 'memcache_port', NULL)
->with('system', 'memcache_port')
->andReturn(11211);
return new CacheLockDriver(CacheDriverFactory::create('memcache'));

View file

@ -13,9 +13,9 @@ class MemcachedCacheLockDriverTest extends LockTest
{
protected function getInstance()
{
$this->configCache
$this->configMock
->shouldReceive('get')
->with('system', 'memcached_hosts', NULL)
->with('system', 'memcached_hosts')
->andReturn([0 => 'localhost, 11211']);
return new CacheLockDriver(CacheDriverFactory::create('memcached'));

View file

@ -13,14 +13,14 @@ class RedisCacheLockDriverTest extends LockTest
{
protected function getInstance()
{
$this->configCache
$this->configMock
->shouldReceive('get')
->with('system', 'redis_host', NULL)
->with('system', 'redis_host')
->andReturn('localhost');
$this->configCache
$this->configMock
->shouldReceive('get')
->with('system', 'redis_port', NULL)
->with('system', 'redis_port')
->andReturn(null);
return new CacheLockDriver(CacheDriverFactory::create('redis'));

View file

@ -12,9 +12,9 @@ class SemaphoreLockDriverTest extends LockTest
$this->app->shouldReceive('getHostname')->andReturn('friendica.local');
$this->configCache
$this->configMock
->shouldReceive('get')
->with('system', 'temppath', NULL)
->with('system', 'temppath')
->andReturn('/tmp/');
}