]> git.mxchange.org Git - friendica.git/commitdiff
Fixed memcache & unittests
authorPhilipp Holzer <admin@philipp.info>
Sat, 7 Jul 2018 18:07:07 +0000 (20:07 +0200)
committerPhilipp Holzer <admin@philipp.info>
Sat, 7 Jul 2018 18:07:07 +0000 (20:07 +0200)
.travis.yml
src/Core/Cache/MemcacheCacheDriver.php
tests/src/Core/Cache/MemcacheCacheDriverTest.php [new file with mode: 0644]
tests/src/Core/Lock/MemcacheCacheLockDriverTest.php [new file with mode: 0644]

index 6e7ac1c2e0b0f1c2dbcd02e828173c04400b5962..93d1190f239d9362ae648f6186395b0e79c5c23c 100644 (file)
@@ -21,3 +21,4 @@ before_script:
  - mysql -utravis test < database.sql
  - echo "extension=redis.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
  - echo "extension=memcached.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
+ - echo "extension=memcache.so" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
\ No newline at end of file
index cd12be8ecd9a58d7f40490936b4ccfcdf17cce45..bff543b542478ed4db0f80f9e7488f49cae758ed 100644 (file)
@@ -111,6 +111,6 @@ class MemcacheCacheDriver extends AbstractCacheDriver implements IMemoryCacheDri
        public function add($key, $value, $ttl = Cache::FIVE_MINUTES)
        {
                $cachekey = $this->getCacheKey($key);
-               return $this->memcache->add($cachekey, $value, $ttl);
+               return $this->memcache->add($cachekey, serialize($value), MEMCACHE_COMPRESSED, $ttl);
        }
 }
diff --git a/tests/src/Core/Cache/MemcacheCacheDriverTest.php b/tests/src/Core/Cache/MemcacheCacheDriverTest.php
new file mode 100644 (file)
index 0000000..4dbd102
--- /dev/null
@@ -0,0 +1,39 @@
+<?php
+
+
+namespace Friendica\Test\src\Core\Cache;
+
+
+use Friendica\Core\Cache\CacheDriverFactory;
+
+class MemcachedCacheDriverTest extends CacheTest
+{
+       /**
+        * @var \Friendica\Core\Cache\IMemoryCacheDriver
+        */
+       private $cache;
+
+       protected function getInstance()
+       {
+               if (class_exists('Memcache')) {
+                       try {
+                               $this->cache = CacheDriverFactory::create('memcache');
+                       } catch (\Exception $exception) {
+                               print "Memcache - TestCase failed: " . $exception->getMessage();
+                               throw new \Exception();
+                       }
+                       return $this->cache;
+               } else {
+                       $this->markTestSkipped('Memcache driver isn\'t available');
+                       return null;
+               }
+       }
+
+       public function tearDown()
+       {
+               if (class_exists('Memcache')) {
+                       $this->cache->clear();
+               }
+               parent::tearDown();
+       }
+}
diff --git a/tests/src/Core/Lock/MemcacheCacheLockDriverTest.php b/tests/src/Core/Lock/MemcacheCacheLockDriverTest.php
new file mode 100644 (file)
index 0000000..67ccdb5
--- /dev/null
@@ -0,0 +1,40 @@
+<?php
+
+
+namespace Friendica\Test\src\Core\Lock;
+
+
+use Friendica\Core\Cache\CacheDriverFactory;
+use Friendica\Core\Lock\CacheLockDriver;
+
+class MemcacheCacheLockDriverTest extends LockTest
+{
+       /**
+        * @var \Friendica\Core\Cache\IMemoryCacheDriver
+        */
+       private $cache;
+
+       protected function getInstance()
+       {
+               if (class_exists('Memcache')) {
+                       try {
+                               $this->cache = CacheDriverFactory::create('memcache');
+                       } catch (\Exception $exception) {
+                               print "Memcache - TestCase failed: " . $exception->getMessage();
+                               throw new \Exception();
+                       }
+                       return new CacheLockDriver($this->cache);
+               } else {
+                       $this->markTestSkipped('Memcache driver isn\'t available');
+                       return null;
+               }
+       }
+
+       public function tearDown()
+       {
+               if (class_exists('Memcache')) {
+                       $this->cache->clear();
+               }
+               parent::tearDown();
+       }
+}