Fixed & added unittests

pull/5331/head
Philipp Holzer 4 years ago
parent 065b83d148
commit 3cde7a3e4b
No known key found for this signature in database
GPG Key ID: 58160D7D6AF942B6
  1. 4
      tests/src/Core/Cache/ArrayCacheDriverTest.php
  2. 2
      tests/src/Core/Cache/DatabaseCacheDriverTest.php
  3. 4
      tests/src/Core/Cache/MemcacheCacheDriverTest.php
  4. 4
      tests/src/Core/Cache/MemcachedCacheDriverTest.php
  5. 92
      tests/src/Core/Cache/MemoryCacheTest.php
  6. 4
      tests/src/Core/Cache/RedisCacheDriverTest.php

@ -5,7 +5,7 @@ namespace Friendica\Test\src\Core\Cache;
use Friendica\Core\Cache\ArrayCache;
class ArrayCacheDriverTest extends CacheTest
class ArrayCacheDriverTest extends MemoryCacheTest
{
/**
* @var \Friendica\Core\Cache\IMemoryCacheDriver
@ -20,7 +20,7 @@ class ArrayCacheDriverTest extends CacheTest
public function tearDown()
{
$this->cache->clear();
$this->cache->clear(false);
parent::tearDown();
}

@ -19,7 +19,7 @@ class DatabaseCacheDriverTest extends CacheTest
public function tearDown()
{
$this->cache->clear();
$this->cache->clear(false);
parent::tearDown();
}
}

@ -6,7 +6,7 @@ namespace Friendica\Test\src\Core\Cache;
use Friendica\Core\Cache\CacheDriverFactory;
class MemcachedCacheDriverTest extends CacheTest
class MemcacheCacheDriverTest extends MemoryCacheTest
{
/**
* @var \Friendica\Core\Cache\IMemoryCacheDriver
@ -32,7 +32,7 @@ class MemcachedCacheDriverTest extends CacheTest
public function tearDown()
{
if (class_exists('Memcache')) {
$this->cache->clear();
$this->cache->clear(false);
}
parent::tearDown();
}

@ -6,7 +6,7 @@ namespace Friendica\Test\src\Core\Cache;
use Friendica\Core\Cache\CacheDriverFactory;
class MemcachedCacheDriverTest extends CacheTest
class MemcachedCacheDriverTest extends MemoryCacheTest
{
/**
* @var \Friendica\Core\Cache\IMemoryCacheDriver
@ -32,7 +32,7 @@ class MemcachedCacheDriverTest extends CacheTest
public function tearDown()
{
if (class_exists('Memcached')) {
$this->cache->clear();
$this->cache->clear(false);
}
parent::tearDown();
}

@ -0,0 +1,92 @@
<?php
namespace Friendica\Test\src\Core\Cache;
use Friendica\Core\Cache\IMemoryCacheDriver;
abstract class MemoryCacheTest extends CacheTest
{
/**
* @var \Friendica\Core\Cache\IMemoryCacheDriver
*/
protected $instance;
function setUp()
{
parent::setUp();
if (!($this->instance instanceof IMemoryCacheDriver)) {
throw new \Exception('MemoryCacheTest unsupported');
}
}
function testCompareSet() {
$this->assertNull($this->instance->get('value1'));
$value='foobar';
$this->instance->add('value1', $value);
$received=$this->instance->get('value1');
$this->assertEquals($value, $received, 'Value received from cache not equal to the original');
$newValue='ipsum lorum';
$this->instance->compareSet('value1', $value, $newValue);
$received=$this->instance->get('value1');
$this->assertEquals($newValue, $received, 'Value not overwritten by compareSet');
}
function testNegativeCompareSet() {
$this->assertNull($this->instance->get('value1'));
$value='foobar';
$this->instance->add('value1', $value);
$received=$this->instance->get('value1');
$this->assertEquals($value, $received, 'Value received from cache not equal to the original');
$newValue='ipsum lorum';
$this->instance->compareSet('value1', 'wrong', $newValue);
$received=$this->instance->get('value1');
$this->assertNotEquals($newValue, $received, 'Value was wrongly overwritten by compareSet');
$this->assertEquals($value, $received, 'Value was wrongly overwritten by any other value');
}
function testCompareDelete() {
$this->assertNull($this->instance->get('value1'));
$value='foobar';
$this->instance->add('value1', $value);
$received=$this->instance->get('value1');
$this->assertEquals($value, $received, 'Value received from cache not equal to the original');
$this->instance->compareDelete('value1', $value);
$this->assertNull($this->instance->get('value1'), 'Value was not deleted by compareDelete');
}
function testNegativeCompareDelete() {
$this->assertNull($this->instance->get('value1'));
$value='foobar';
$this->instance->add('value1', $value);
$received=$this->instance->get('value1');
$this->assertEquals($value, $received, 'Value received from cache not equal to the original');
$this->instance->compareDelete('value1', 'wrong');
$this->assertNotNull($this->instance->get('value1'), 'Value was wrongly compareDeleted');
$this->instance->compareDelete('value1', $value);
$this->assertNull($this->instance->get('value1'), 'Value was wrongly NOT deleted by compareDelete');
}
function testAdd() {
$this->assertNull($this->instance->get('value1'));
$value='foobar';
$this->instance->add('value1', $value);
$newValue='ipsum lorum';
$this->instance->add('value1', $newValue);
$received=$this->instance->get('value1');
$this->assertNotEquals($newValue, $received, 'Value was wrongly overwritten by add');
$this->assertEquals($value, $received, 'Value was wrongly overwritten by any other value');
$this->instance->delete('value1');
$this->instance->add('value1', $newValue);
$received=$this->instance->get('value1');
$this->assertEquals($newValue, $received, 'Value was not overwritten by add');
$this->assertNotEquals($value, $received, 'Value was not overwritten by any other value');
}
}

@ -6,7 +6,7 @@ namespace Friendica\Test\src\Core\Cache;
use Friendica\Core\Cache\CacheDriverFactory;
class RedisCacheDriverTest extends CacheTest
class RedisCacheDriverTest extends MemoryCacheTest
{
/**
* @var \Friendica\Core\Cache\IMemoryCacheDriver
@ -32,7 +32,7 @@ class RedisCacheDriverTest extends CacheTest
public function tearDown()
{
if (class_exists('Redis')) {
$this->cache->clear();
$this->cache->clear(false);
}
parent::tearDown();
}

Loading…
Cancel
Save