1
0
Fork 0

simplifying unittests (#5395)

* simplifying unittests

- use @requires instead class_exist
- define @small and @medium

* simplifying unittests

- removed unnecessary throwings
This commit is contained in:
Philipp 2018-07-18 21:04:18 +02:00 committed by Hypolite Petovan
commit 2d0446bd38
9 changed files with 83 additions and 87 deletions

View file

@ -31,6 +31,9 @@ abstract class CacheTest extends DatabaseTest
Config::set('system', 'theme', 'system_theme');
}
/**
* @small
*/
function testSimple() {
$this->assertNull($this->instance->get('value1'));
@ -56,6 +59,9 @@ abstract class CacheTest extends DatabaseTest
$this->assertNull($this->instance->get('value1'));
}
/**
* @small
*/
function testClear() {
$value = 'ipsum lorum';
$this->instance->set('1_value1', $value . '1');
@ -90,6 +96,9 @@ abstract class CacheTest extends DatabaseTest
]);
}
/**
* @medium
*/
function testTTL() {
$this->assertNull($this->instance->get('value1'));
@ -103,6 +112,9 @@ abstract class CacheTest extends DatabaseTest
$this->assertNull($this->instance->get('value1'));
}
/**
* @small
*/
function testDifferentTypesInCache() {
// String test
$value = "foobar";

View file

@ -6,6 +6,9 @@ namespace Friendica\Test\src\Core\Cache;
use Friendica\Core\Cache\CacheDriverFactory;
/**
* @requires extension memcache
*/
class MemcacheCacheDriverTest extends MemoryCacheTest
{
/**
@ -15,24 +18,14 @@ class MemcacheCacheDriverTest extends MemoryCacheTest
protected function getInstance()
{
if (class_exists('Memcache')) {
try {
$this->cache = CacheDriverFactory::create('memcache');
} catch (\Exception $exception) {
throw new \Exception("Memcache - TestCase failed: " . $exception->getMessage(), $exception->getCode(), $exception);
}
return $this->cache;
} else {
$this->markTestSkipped('Memcache driver isn\'t available');
return null;
}
$this->cache = CacheDriverFactory::create('memcache');
return $this->cache;
}
public function tearDown()
{
if (class_exists('Memcache')) {
$this->cache->clear(false);
}
$this->cache->clear(false);
parent::tearDown();
}
}

View file

@ -6,6 +6,9 @@ namespace Friendica\Test\src\Core\Cache;
use Friendica\Core\Cache\CacheDriverFactory;
/**
* @requires extension memcached
*/
class MemcachedCacheDriverTest extends MemoryCacheTest
{
/**
@ -15,24 +18,13 @@ class MemcachedCacheDriverTest extends MemoryCacheTest
protected function getInstance()
{
if (class_exists('Memcached')) {
try {
$this->cache = CacheDriverFactory::create('memcached');
} catch (\Exception $exception) {
throw new \Exception("Memcached - TestCase failed: " . $exception->getMessage(), $exception->getCode(), $exception);
}
return $this->cache;
} else {
$this->markTestSkipped('Memcached driver isn\'t available');
return null;
}
$this->cache = CacheDriverFactory::create('memcached');
return $this->cache;
}
public function tearDown()
{
if (class_exists('Memcached')) {
$this->cache->clear(false);
}
$this->cache->clear(false);
parent::tearDown();
}
}

View file

@ -19,6 +19,9 @@ abstract class MemoryCacheTest extends CacheTest
}
}
/**
* @small
*/
function testCompareSet() {
$this->assertNull($this->instance->get('value1'));
@ -33,6 +36,9 @@ abstract class MemoryCacheTest extends CacheTest
$this->assertEquals($newValue, $received, 'Value not overwritten by compareSet');
}
/**
* @small
*/
function testNegativeCompareSet() {
$this->assertNull($this->instance->get('value1'));
@ -48,6 +54,9 @@ abstract class MemoryCacheTest extends CacheTest
$this->assertEquals($value, $received, 'Value was wrongly overwritten by any other value');
}
/**
* @small
*/
function testCompareDelete() {
$this->assertNull($this->instance->get('value1'));
@ -59,6 +68,9 @@ abstract class MemoryCacheTest extends CacheTest
$this->assertNull($this->instance->get('value1'), 'Value was not deleted by compareDelete');
}
/**
* @small
*/
function testNegativeCompareDelete() {
$this->assertNull($this->instance->get('value1'));
@ -73,6 +85,9 @@ abstract class MemoryCacheTest extends CacheTest
$this->assertNull($this->instance->get('value1'), 'Value was wrongly NOT deleted by compareDelete');
}
/**
* @small
*/
function testAdd() {
$this->assertNull($this->instance->get('value1'));

View file

@ -6,6 +6,9 @@ namespace Friendica\Test\src\Core\Cache;
use Friendica\Core\Cache\CacheDriverFactory;
/**
* @requires extension redis
*/
class RedisCacheDriverTest extends MemoryCacheTest
{
/**
@ -15,24 +18,13 @@ class RedisCacheDriverTest extends MemoryCacheTest
protected function getInstance()
{
if (class_exists('Redis')) {
try {
$this->cache = CacheDriverFactory::create('redis');
} catch (\Exception $exception) {
throw new \Exception("Redis - TestCase failed: " . $exception->getMessage(), $exception->getCode(), $exception);
}
return $this->cache;
} else {
$this->markTestSkipped('Redis driver isn\'t available');
return null;
}
$this->cache = CacheDriverFactory::create('redis');
return $this->cache;
}
public function tearDown()
{
if (class_exists('Redis')) {
$this->cache->clear(false);
}
$this->cache->clear(false);
parent::tearDown();
}
}