Refactor Cache/Lock to DICE

- Refactor Cache classes
- Refactor Lock classes
- Improved test speed (removed some seperate class annotations)
This commit is contained in:
Philipp Holzer 2019-08-03 20:48:56 +02:00
parent b95d4f41b9
commit d56bd28a07
No known key found for this signature in database
GPG key ID: D8365C3D36B77D90
40 changed files with 766 additions and 621 deletions

View file

@ -4,15 +4,10 @@ namespace Friendica\Test\src\Core\Cache;
use Friendica\Core\Cache\MemcachedCacheDriver;
use Friendica\Test\MockedTest;
use Friendica\Test\Util\AppMockTrait;
use Friendica\Test\Util\VFSTrait;
use Friendica\Util\PidFile;
abstract class CacheTest extends MockedTest
{
use VFSTrait;
use AppMockTrait;
/**
* @var int Start time of the mock (used for time operations)
*/
@ -30,6 +25,7 @@ abstract class CacheTest extends MockedTest
/**
* Dataset for test setting different types in the cache
*
* @return array
*/
public function dataTypesInCache()
@ -48,6 +44,7 @@ abstract class CacheTest extends MockedTest
/**
* Dataset for simple value sets/gets
*
* @return array
*/
public function dataSimple()
@ -66,12 +63,6 @@ abstract class CacheTest extends MockedTest
protected function setUp()
{
$this->setUpVfsDir();
$this->mockApp($this->root);
$this->app
->shouldReceive('getHostname')
->andReturn('friendica.local');
parent::setUp();
$this->instance = $this->getInstance();
@ -82,10 +73,12 @@ abstract class CacheTest extends MockedTest
/**
* @small
* @dataProvider dataSimple
*
* @param mixed $value1 a first
* @param mixed $value2 a second
*/
function testSimple($value1, $value2) {
function testSimple($value1, $value2)
{
$this->assertNull($this->instance->get('value1'));
$this->instance->set('value1', $value1);
@ -110,12 +103,14 @@ abstract class CacheTest extends MockedTest
/**
* @small
* @dataProvider dataSimple
*
* @param mixed $value1 a first
* @param mixed $value2 a second
* @param mixed $value3 a third
* @param mixed $value4 a fourth
*/
function testClear($value1, $value2, $value3, $value4) {
function testClear($value1, $value2, $value3, $value4)
{
$value = 'ipsum lorum';
$this->instance->set('1_value1', $value1);
$this->instance->set('1_value2', $value2);
@ -166,7 +161,8 @@ abstract class CacheTest extends MockedTest
/**
* @medium
*/
function testTTL() {
function testTTL()
{
$this->markTestSkipped('taking too much time without mocking');
$this->assertNull($this->instance->get('value1'));
@ -183,10 +179,13 @@ abstract class CacheTest extends MockedTest
/**
* @small
*
* @param $data mixed the data to store in the cache
*
* @dataProvider dataTypesInCache
*/
function testDifferentTypesInCache($data) {
function testDifferentTypesInCache($data)
{
$this->instance->set('val', $data);
$received = $this->instance->get('val');
$this->assertEquals($data, $received, 'Value type changed from ' . gettype($data) . ' to ' . gettype($received));
@ -194,12 +193,15 @@ abstract class CacheTest extends MockedTest
/**
* @small
*
* @param mixed $value1 a first
* @param mixed $value2 a second
* @param mixed $value3 a third
*
* @dataProvider dataSimple
*/
public function testGetAllKeys($value1, $value2, $value3) {
public function testGetAllKeys($value1, $value2, $value3)
{
if ($this->cache instanceof MemcachedCacheDriver) {
$this->markTestSkipped('Memcached doesn\'t support getAllKeys anymore');
}