From 065b83d148775f30712532d0242f7d1508a7d0b0 Mon Sep 17 00:00:00 2001 From: Philipp Holzer Date: Sat, 7 Jul 2018 20:07:07 +0200 Subject: [PATCH] Fixed memcache & unittests --- .travis.yml | 1 + src/Core/Cache/MemcacheCacheDriver.php | 2 +- .../Core/Cache/MemcacheCacheDriverTest.php | 39 ++++++++++++++++++ .../Core/Lock/MemcacheCacheLockDriverTest.php | 40 +++++++++++++++++++ 4 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 tests/src/Core/Cache/MemcacheCacheDriverTest.php create mode 100644 tests/src/Core/Lock/MemcacheCacheLockDriverTest.php diff --git a/.travis.yml b/.travis.yml index 6e7ac1c2e..93d1190f2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/src/Core/Cache/MemcacheCacheDriver.php b/src/Core/Cache/MemcacheCacheDriver.php index cd12be8ec..bff543b54 100644 --- a/src/Core/Cache/MemcacheCacheDriver.php +++ b/src/Core/Cache/MemcacheCacheDriver.php @@ -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 index 000000000..4dbd10289 --- /dev/null +++ b/tests/src/Core/Cache/MemcacheCacheDriverTest.php @@ -0,0 +1,39 @@ +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 index 000000000..67ccdb57d --- /dev/null +++ b/tests/src/Core/Lock/MemcacheCacheLockDriverTest.php @@ -0,0 +1,40 @@ +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(); + } +}