]> git.mxchange.org Git - friendica.git/commitdiff
Fixed & added unittests
authorPhilipp Holzer <admin@philipp.info>
Sat, 7 Jul 2018 18:35:42 +0000 (20:35 +0200)
committerPhilipp Holzer <admin@philipp.info>
Sat, 7 Jul 2018 18:35:42 +0000 (20:35 +0200)
tests/src/Core/Cache/ArrayCacheDriverTest.php
tests/src/Core/Cache/DatabaseCacheDriverTest.php
tests/src/Core/Cache/MemcacheCacheDriverTest.php
tests/src/Core/Cache/MemcachedCacheDriverTest.php
tests/src/Core/Cache/MemoryCacheTest.php [new file with mode: 0644]
tests/src/Core/Cache/RedisCacheDriverTest.php

index 860e566d88c4252711ddd288546a746c1f36ebbb..0cad6e9c7f5ddd5a9464cd6f4bbab170b078fb40 100644 (file)
@@ -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();
        }
 
index ed2e47fb47e36a66f1a31c58229adf34cf0f69e2..5df00fc913581a36d0afffa51f38ecf81424a71b 100644 (file)
@@ -19,7 +19,7 @@ class DatabaseCacheDriverTest extends CacheTest
 
        public function tearDown()
        {
-               $this->cache->clear();
+               $this->cache->clear(false);
                parent::tearDown();
        }
 }
index 4dbd10289e717383b790b117f7ecdc83714fbbe8..d2078236e2ed1abb47375983f4fe79d6372660e5 100644 (file)
@@ -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();
        }
index ff76ddefc48c3fec9daeab1f2607ac71cbf75b3c..2484517424c476f0c0fbfa4c219158d776471d30 100644 (file)
@@ -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();
        }
diff --git a/tests/src/Core/Cache/MemoryCacheTest.php b/tests/src/Core/Cache/MemoryCacheTest.php
new file mode 100644 (file)
index 0000000..3f7af71
--- /dev/null
@@ -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');
+       }
+}
\ No newline at end of file
index 44ff0d42b1c9c3071f0bba54a0e07a274000a245..e13d95df4d7f4319715c656af9405315b9262ed3 100644 (file)
@@ -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();
        }