simplifying unittests (#5395)
* simplifying unittests - use @requires instead class_exist - define @small and @medium * simplifying unittests - removed unnecessary throwings
This commit is contained in:
parent
2fa6cc0000
commit
2d0446bd38
|
@ -31,6 +31,9 @@ abstract class CacheTest extends DatabaseTest
|
||||||
Config::set('system', 'theme', 'system_theme');
|
Config::set('system', 'theme', 'system_theme');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @small
|
||||||
|
*/
|
||||||
function testSimple() {
|
function testSimple() {
|
||||||
$this->assertNull($this->instance->get('value1'));
|
$this->assertNull($this->instance->get('value1'));
|
||||||
|
|
||||||
|
@ -56,6 +59,9 @@ abstract class CacheTest extends DatabaseTest
|
||||||
$this->assertNull($this->instance->get('value1'));
|
$this->assertNull($this->instance->get('value1'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @small
|
||||||
|
*/
|
||||||
function testClear() {
|
function testClear() {
|
||||||
$value = 'ipsum lorum';
|
$value = 'ipsum lorum';
|
||||||
$this->instance->set('1_value1', $value . '1');
|
$this->instance->set('1_value1', $value . '1');
|
||||||
|
@ -90,6 +96,9 @@ abstract class CacheTest extends DatabaseTest
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @medium
|
||||||
|
*/
|
||||||
function testTTL() {
|
function testTTL() {
|
||||||
$this->assertNull($this->instance->get('value1'));
|
$this->assertNull($this->instance->get('value1'));
|
||||||
|
|
||||||
|
@ -103,6 +112,9 @@ abstract class CacheTest extends DatabaseTest
|
||||||
$this->assertNull($this->instance->get('value1'));
|
$this->assertNull($this->instance->get('value1'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @small
|
||||||
|
*/
|
||||||
function testDifferentTypesInCache() {
|
function testDifferentTypesInCache() {
|
||||||
// String test
|
// String test
|
||||||
$value = "foobar";
|
$value = "foobar";
|
||||||
|
|
|
@ -6,6 +6,9 @@ namespace Friendica\Test\src\Core\Cache;
|
||||||
|
|
||||||
use Friendica\Core\Cache\CacheDriverFactory;
|
use Friendica\Core\Cache\CacheDriverFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @requires extension memcache
|
||||||
|
*/
|
||||||
class MemcacheCacheDriverTest extends MemoryCacheTest
|
class MemcacheCacheDriverTest extends MemoryCacheTest
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
@ -15,24 +18,14 @@ class MemcacheCacheDriverTest extends MemoryCacheTest
|
||||||
|
|
||||||
protected function getInstance()
|
protected function getInstance()
|
||||||
{
|
{
|
||||||
if (class_exists('Memcache')) {
|
|
||||||
try {
|
|
||||||
$this->cache = CacheDriverFactory::create('memcache');
|
$this->cache = CacheDriverFactory::create('memcache');
|
||||||
} catch (\Exception $exception) {
|
|
||||||
throw new \Exception("Memcache - TestCase failed: " . $exception->getMessage(), $exception->getCode(), $exception);
|
|
||||||
}
|
|
||||||
return $this->cache;
|
return $this->cache;
|
||||||
} else {
|
|
||||||
$this->markTestSkipped('Memcache driver isn\'t available');
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function tearDown()
|
public function tearDown()
|
||||||
{
|
{
|
||||||
if (class_exists('Memcache')) {
|
|
||||||
$this->cache->clear(false);
|
$this->cache->clear(false);
|
||||||
}
|
|
||||||
parent::tearDown();
|
parent::tearDown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,9 @@ namespace Friendica\Test\src\Core\Cache;
|
||||||
|
|
||||||
use Friendica\Core\Cache\CacheDriverFactory;
|
use Friendica\Core\Cache\CacheDriverFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @requires extension memcached
|
||||||
|
*/
|
||||||
class MemcachedCacheDriverTest extends MemoryCacheTest
|
class MemcachedCacheDriverTest extends MemoryCacheTest
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
@ -15,24 +18,13 @@ class MemcachedCacheDriverTest extends MemoryCacheTest
|
||||||
|
|
||||||
protected function getInstance()
|
protected function getInstance()
|
||||||
{
|
{
|
||||||
if (class_exists('Memcached')) {
|
|
||||||
try {
|
|
||||||
$this->cache = CacheDriverFactory::create('memcached');
|
$this->cache = CacheDriverFactory::create('memcached');
|
||||||
} catch (\Exception $exception) {
|
|
||||||
throw new \Exception("Memcached - TestCase failed: " . $exception->getMessage(), $exception->getCode(), $exception);
|
|
||||||
}
|
|
||||||
return $this->cache;
|
return $this->cache;
|
||||||
} else {
|
|
||||||
$this->markTestSkipped('Memcached driver isn\'t available');
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function tearDown()
|
public function tearDown()
|
||||||
{
|
{
|
||||||
if (class_exists('Memcached')) {
|
|
||||||
$this->cache->clear(false);
|
$this->cache->clear(false);
|
||||||
}
|
|
||||||
parent::tearDown();
|
parent::tearDown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,9 @@ abstract class MemoryCacheTest extends CacheTest
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @small
|
||||||
|
*/
|
||||||
function testCompareSet() {
|
function testCompareSet() {
|
||||||
$this->assertNull($this->instance->get('value1'));
|
$this->assertNull($this->instance->get('value1'));
|
||||||
|
|
||||||
|
@ -33,6 +36,9 @@ abstract class MemoryCacheTest extends CacheTest
|
||||||
$this->assertEquals($newValue, $received, 'Value not overwritten by compareSet');
|
$this->assertEquals($newValue, $received, 'Value not overwritten by compareSet');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @small
|
||||||
|
*/
|
||||||
function testNegativeCompareSet() {
|
function testNegativeCompareSet() {
|
||||||
$this->assertNull($this->instance->get('value1'));
|
$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');
|
$this->assertEquals($value, $received, 'Value was wrongly overwritten by any other value');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @small
|
||||||
|
*/
|
||||||
function testCompareDelete() {
|
function testCompareDelete() {
|
||||||
$this->assertNull($this->instance->get('value1'));
|
$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');
|
$this->assertNull($this->instance->get('value1'), 'Value was not deleted by compareDelete');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @small
|
||||||
|
*/
|
||||||
function testNegativeCompareDelete() {
|
function testNegativeCompareDelete() {
|
||||||
$this->assertNull($this->instance->get('value1'));
|
$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');
|
$this->assertNull($this->instance->get('value1'), 'Value was wrongly NOT deleted by compareDelete');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @small
|
||||||
|
*/
|
||||||
function testAdd() {
|
function testAdd() {
|
||||||
$this->assertNull($this->instance->get('value1'));
|
$this->assertNull($this->instance->get('value1'));
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,9 @@ namespace Friendica\Test\src\Core\Cache;
|
||||||
|
|
||||||
use Friendica\Core\Cache\CacheDriverFactory;
|
use Friendica\Core\Cache\CacheDriverFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @requires extension redis
|
||||||
|
*/
|
||||||
class RedisCacheDriverTest extends MemoryCacheTest
|
class RedisCacheDriverTest extends MemoryCacheTest
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
@ -15,24 +18,13 @@ class RedisCacheDriverTest extends MemoryCacheTest
|
||||||
|
|
||||||
protected function getInstance()
|
protected function getInstance()
|
||||||
{
|
{
|
||||||
if (class_exists('Redis')) {
|
|
||||||
try {
|
|
||||||
$this->cache = CacheDriverFactory::create('redis');
|
$this->cache = CacheDriverFactory::create('redis');
|
||||||
} catch (\Exception $exception) {
|
|
||||||
throw new \Exception("Redis - TestCase failed: " . $exception->getMessage(), $exception->getCode(), $exception);
|
|
||||||
}
|
|
||||||
return $this->cache;
|
return $this->cache;
|
||||||
} else {
|
|
||||||
$this->markTestSkipped('Redis driver isn\'t available');
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function tearDown()
|
public function tearDown()
|
||||||
{
|
{
|
||||||
if (class_exists('Redis')) {
|
|
||||||
$this->cache->clear(false);
|
$this->cache->clear(false);
|
||||||
}
|
|
||||||
parent::tearDown();
|
parent::tearDown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,12 +30,18 @@ abstract class LockTest extends DatabaseTest
|
||||||
Config::set('system', 'theme', 'system_theme');
|
Config::set('system', 'theme', 'system_theme');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @small
|
||||||
|
*/
|
||||||
public function testLock() {
|
public function testLock() {
|
||||||
$this->instance->acquireLock('foo', 1);
|
$this->instance->acquireLock('foo', 1);
|
||||||
$this->assertTrue($this->instance->isLocked('foo'));
|
$this->assertTrue($this->instance->isLocked('foo'));
|
||||||
$this->assertFalse($this->instance->isLocked('bar'));
|
$this->assertFalse($this->instance->isLocked('bar'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @small
|
||||||
|
*/
|
||||||
public function testDoubleLock() {
|
public function testDoubleLock() {
|
||||||
$this->instance->acquireLock('foo', 1);
|
$this->instance->acquireLock('foo', 1);
|
||||||
$this->assertTrue($this->instance->isLocked('foo'));
|
$this->assertTrue($this->instance->isLocked('foo'));
|
||||||
|
@ -43,6 +49,9 @@ abstract class LockTest extends DatabaseTest
|
||||||
$this->assertTrue($this->instance->acquireLock('foo', 1));
|
$this->assertTrue($this->instance->acquireLock('foo', 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @small
|
||||||
|
*/
|
||||||
public function testReleaseLock() {
|
public function testReleaseLock() {
|
||||||
$this->instance->acquireLock('foo', 1);
|
$this->instance->acquireLock('foo', 1);
|
||||||
$this->assertTrue($this->instance->isLocked('foo'));
|
$this->assertTrue($this->instance->isLocked('foo'));
|
||||||
|
@ -50,6 +59,9 @@ abstract class LockTest extends DatabaseTest
|
||||||
$this->assertFalse($this->instance->isLocked('foo'));
|
$this->assertFalse($this->instance->isLocked('foo'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @small
|
||||||
|
*/
|
||||||
public function testReleaseAll() {
|
public function testReleaseAll() {
|
||||||
$this->instance->acquireLock('foo', 1);
|
$this->instance->acquireLock('foo', 1);
|
||||||
$this->instance->acquireLock('bar', 1);
|
$this->instance->acquireLock('bar', 1);
|
||||||
|
@ -66,6 +78,9 @@ abstract class LockTest extends DatabaseTest
|
||||||
$this->assertFalse($this->instance->isLocked('nice'));
|
$this->assertFalse($this->instance->isLocked('nice'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @small
|
||||||
|
*/
|
||||||
public function testReleaseAfterUnlock() {
|
public function testReleaseAfterUnlock() {
|
||||||
$this->instance->acquireLock('foo', 1);
|
$this->instance->acquireLock('foo', 1);
|
||||||
$this->instance->acquireLock('bar', 1);
|
$this->instance->acquireLock('bar', 1);
|
||||||
|
@ -83,6 +98,9 @@ abstract class LockTest extends DatabaseTest
|
||||||
$this->assertFalse($this->instance->isLocked('nice'));
|
$this->assertFalse($this->instance->isLocked('nice'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @medium
|
||||||
|
*/
|
||||||
function testLockTTL() {
|
function testLockTTL() {
|
||||||
|
|
||||||
// TODO [nupplaphil] - Because of the Datetime-Utils for the database, we have to wait a FULL second between the checks to invalidate the db-locks/cache
|
// TODO [nupplaphil] - Because of the Datetime-Utils for the database, we have to wait a FULL second between the checks to invalidate the db-locks/cache
|
||||||
|
|
|
@ -7,6 +7,9 @@ namespace Friendica\Test\src\Core\Lock;
|
||||||
use Friendica\Core\Cache\CacheDriverFactory;
|
use Friendica\Core\Cache\CacheDriverFactory;
|
||||||
use Friendica\Core\Lock\CacheLockDriver;
|
use Friendica\Core\Lock\CacheLockDriver;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @requires extension Memcache
|
||||||
|
*/
|
||||||
class MemcacheCacheLockDriverTest extends LockTest
|
class MemcacheCacheLockDriverTest extends LockTest
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
@ -16,25 +19,13 @@ class MemcacheCacheLockDriverTest extends LockTest
|
||||||
|
|
||||||
protected function getInstance()
|
protected function getInstance()
|
||||||
{
|
{
|
||||||
if (class_exists('Memcache')) {
|
|
||||||
try {
|
|
||||||
$this->cache = CacheDriverFactory::create('memcache');
|
$this->cache = CacheDriverFactory::create('memcache');
|
||||||
} catch (\Exception $exception) {
|
|
||||||
print "Memcache - TestCase failed: " . $exception->getMessage();
|
|
||||||
throw new \Exception();
|
|
||||||
}
|
|
||||||
return new CacheLockDriver($this->cache);
|
return new CacheLockDriver($this->cache);
|
||||||
} else {
|
|
||||||
$this->markTestSkipped('Memcache driver isn\'t available');
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function tearDown()
|
public function tearDown()
|
||||||
{
|
{
|
||||||
if (class_exists('Memcache')) {
|
|
||||||
$this->cache->clear();
|
$this->cache->clear();
|
||||||
}
|
|
||||||
parent::tearDown();
|
parent::tearDown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,9 @@ namespace Friendica\Test\src\Core\Lock;
|
||||||
use Friendica\Core\Cache\CacheDriverFactory;
|
use Friendica\Core\Cache\CacheDriverFactory;
|
||||||
use Friendica\Core\Lock\CacheLockDriver;
|
use Friendica\Core\Lock\CacheLockDriver;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @requires extension memcached
|
||||||
|
*/
|
||||||
class MemcachedCacheLockDriverTest extends LockTest
|
class MemcachedCacheLockDriverTest extends LockTest
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
@ -16,25 +19,13 @@ class MemcachedCacheLockDriverTest extends LockTest
|
||||||
|
|
||||||
protected function getInstance()
|
protected function getInstance()
|
||||||
{
|
{
|
||||||
if (class_exists('Memcached')) {
|
|
||||||
try {
|
|
||||||
$this->cache = CacheDriverFactory::create('memcached');
|
$this->cache = CacheDriverFactory::create('memcached');
|
||||||
} catch (\Exception $exception) {
|
|
||||||
print "Memcached - TestCase failed: " . $exception->getMessage();
|
|
||||||
throw new \Exception();
|
|
||||||
}
|
|
||||||
return new CacheLockDriver($this->cache);
|
return new CacheLockDriver($this->cache);
|
||||||
} else {
|
|
||||||
$this->markTestSkipped('Memcached driver isn\'t available');
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function tearDown()
|
public function tearDown()
|
||||||
{
|
{
|
||||||
if (class_exists('Memcached')) {
|
|
||||||
$this->cache->clear();
|
$this->cache->clear();
|
||||||
}
|
|
||||||
parent::tearDown();
|
parent::tearDown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,9 @@ namespace Friendica\Test\src\Core\Lock;
|
||||||
use Friendica\Core\Cache\CacheDriverFactory;
|
use Friendica\Core\Cache\CacheDriverFactory;
|
||||||
use Friendica\Core\Lock\CacheLockDriver;
|
use Friendica\Core\Lock\CacheLockDriver;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @requires extension redis
|
||||||
|
*/
|
||||||
class RedisCacheLockDriverTest extends LockTest
|
class RedisCacheLockDriverTest extends LockTest
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
@ -16,25 +19,14 @@ class RedisCacheLockDriverTest extends LockTest
|
||||||
|
|
||||||
protected function getInstance()
|
protected function getInstance()
|
||||||
{
|
{
|
||||||
if (class_exists('Redis')) {
|
|
||||||
try {
|
|
||||||
$this->cache = CacheDriverFactory::create('redis');
|
$this->cache = CacheDriverFactory::create('redis');
|
||||||
} catch (\Exception $exception) {
|
|
||||||
print "Redis - TestCase failed: " . $exception->getMessage();
|
|
||||||
throw new \Exception();
|
|
||||||
}
|
|
||||||
return new CacheLockDriver($this->cache);
|
return new CacheLockDriver($this->cache);
|
||||||
} else {
|
|
||||||
$this->markTestSkipped('Redis driver isn\'t available');
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function tearDown()
|
public function tearDown()
|
||||||
{
|
{
|
||||||
if (class_exists('Redis')) {
|
|
||||||
$this->cache->clear();
|
$this->cache->clear();
|
||||||
}
|
|
||||||
parent::tearDown();
|
parent::tearDown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue