summaryrefslogtreecommitdiffstats
path: root/tests/lib/memcache
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@gmx.de>2016-05-20 15:38:20 +0200
committerThomas Müller <DeepDiver1975@users.noreply.github.com>2016-05-20 15:38:20 +0200
commit94ad54ec9b96d41a614fbbad4a97b34c41a6901f (patch)
treef3eb7cdda2704aaf0cd59d58efe66bcbd34cb67d /tests/lib/memcache
parent2ef751b1ec28f7b5c7113af60ec8c9fa0ae1cf87 (diff)
downloadnextcloud-server-94ad54ec9b96d41a614fbbad4a97b34c41a6901f.tar.gz
nextcloud-server-94ad54ec9b96d41a614fbbad4a97b34c41a6901f.zip
Move tests/ to PSR-4 (#24731)
* Move a-b to PSR-4 * Move c-d to PSR-4 * Move e+g to PSR-4 * Move h-l to PSR-4 * Move m-r to PSR-4 * Move s-u to PSR-4 * Move files/ to PSR-4 * Move remaining tests to PSR-4 * Remove Test\ from old autoloader
Diffstat (limited to 'tests/lib/memcache')
-rw-r--r--tests/lib/memcache/FactoryTest.php132
-rw-r--r--tests/lib/memcache/apc.php26
-rw-r--r--tests/lib/memcache/apcu.php22
-rw-r--r--tests/lib/memcache/arraycache.php17
-rw-r--r--tests/lib/memcache/cache.php133
-rw-r--r--tests/lib/memcache/castrait.php73
-rw-r--r--tests/lib/memcache/memcached.php52
-rw-r--r--tests/lib/memcache/redis.php39
-rw-r--r--tests/lib/memcache/xcache.php22
9 files changed, 0 insertions, 516 deletions
diff --git a/tests/lib/memcache/FactoryTest.php b/tests/lib/memcache/FactoryTest.php
deleted file mode 100644
index 8607ea7de9b..00000000000
--- a/tests/lib/memcache/FactoryTest.php
+++ /dev/null
@@ -1,132 +0,0 @@
-<?php
-/**
- * @author Robin McCorkell <rmccorkell@karoshi.org.uk>
- *
- * @copyright Copyright (c) 2015, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
- */
-namespace Test\Memcache;
-
-class Test_Factory_Available_Cache1 {
- public function __construct($prefix = '') {
- }
-
- public static function isAvailable() {
- return true;
- }
-}
-
-class Test_Factory_Available_Cache2 {
- public function __construct($prefix = '') {
- }
-
- public static function isAvailable() {
- return true;
- }
-}
-
-class Test_Factory_Unavailable_Cache1 {
- public function __construct($prefix = '') {
- }
-
- public static function isAvailable() {
- return false;
- }
-}
-
-class Test_Factory_Unavailable_Cache2 {
- public function __construct($prefix = '') {
- }
-
- public static function isAvailable() {
- return false;
- }
-}
-
-class FactoryTest extends \Test\TestCase {
- const AVAILABLE1 = '\\Test\\Memcache\\Test_Factory_Available_Cache1';
- const AVAILABLE2 = '\\Test\\Memcache\\Test_Factory_Available_Cache2';
- const UNAVAILABLE1 = '\\Test\\Memcache\\Test_Factory_Unavailable_Cache1';
- const UNAVAILABLE2 = '\\Test\\Memcache\\Test_Factory_Unavailable_Cache2';
-
- public function cacheAvailabilityProvider() {
- return [
- [
- // local and distributed available
- self::AVAILABLE1, self::AVAILABLE2, null,
- self::AVAILABLE1, self::AVAILABLE2, \OC\Memcache\Factory::NULL_CACHE
- ],
- [
- // local and distributed null
- null, null, null,
- \OC\Memcache\Factory::NULL_CACHE, \OC\Memcache\Factory::NULL_CACHE, \OC\Memcache\Factory::NULL_CACHE
- ],
- [
- // local available, distributed null (most common scenario)
- self::AVAILABLE1, null, null,
- self::AVAILABLE1, self::AVAILABLE1, \OC\Memcache\Factory::NULL_CACHE
- ],
- [
- // locking cache available
- null, null, self::AVAILABLE1,
- \OC\Memcache\Factory::NULL_CACHE, \OC\Memcache\Factory::NULL_CACHE, self::AVAILABLE1
- ],
- [
- // locking cache unavailable: no exception here in the factory
- null, null, self::UNAVAILABLE1,
- \OC\Memcache\Factory::NULL_CACHE, \OC\Memcache\Factory::NULL_CACHE, \OC\Memcache\Factory::NULL_CACHE
- ]
- ];
- }
-
- public function cacheUnavailableProvider() {
- return [
- [
- // local available, distributed unavailable
- self::AVAILABLE1, self::UNAVAILABLE1
- ],
- [
- // local unavailable, distributed available
- self::UNAVAILABLE1, self::AVAILABLE1
- ],
- [
- // local and distributed unavailable
- self::UNAVAILABLE1, self::UNAVAILABLE2
- ],
- ];
- }
-
- /**
- * @dataProvider cacheAvailabilityProvider
- */
- public function testCacheAvailability($localCache, $distributedCache, $lockingCache,
- $expectedLocalCache, $expectedDistributedCache, $expectedLockingCache) {
- $logger = $this->getMockBuilder('\OCP\ILogger')->getMock();
- $factory = new \OC\Memcache\Factory('abc', $logger, $localCache, $distributedCache, $lockingCache);
- $this->assertTrue(is_a($factory->createLocal(), $expectedLocalCache));
- $this->assertTrue(is_a($factory->createDistributed(), $expectedDistributedCache));
- $this->assertTrue(is_a($factory->createLocking(), $expectedLockingCache));
- }
-
- /**
- * @dataProvider cacheUnavailableProvider
- * @expectedException \OC\HintException
- */
- public function testCacheNotAvailableException($localCache, $distributedCache) {
- $logger = $this->getMockBuilder('\OCP\ILogger')->getMock();
- new \OC\Memcache\Factory('abc', $logger, $localCache, $distributedCache);
- }
-}
diff --git a/tests/lib/memcache/apc.php b/tests/lib/memcache/apc.php
deleted file mode 100644
index fdb785b9dc5..00000000000
--- a/tests/lib/memcache/apc.php
+++ /dev/null
@@ -1,26 +0,0 @@
-<?php
-
-/**
- * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com>
- * This file is licensed under the Affero General Public License version 3 or
- * later.
- * See the COPYING-README file.
- */
-
-namespace Test\Memcache;
-
-class APC extends Cache {
- protected function setUp() {
- parent::setUp();
-
- if(!\OC\Memcache\APC::isAvailable()) {
- $this->markTestSkipped('The apc extension is not available.');
- return;
- }
- if(\OC\Memcache\APCu::isAvailable()) {
- $this->markTestSkipped('The apc extension is emulated by ACPu.');
- return;
- }
- $this->instance=new \OC\Memcache\APC($this->getUniqueID());
- }
-}
diff --git a/tests/lib/memcache/apcu.php b/tests/lib/memcache/apcu.php
deleted file mode 100644
index afcaa99bfbe..00000000000
--- a/tests/lib/memcache/apcu.php
+++ /dev/null
@@ -1,22 +0,0 @@
-<?php
-
-/**
- * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com>
- * This file is licensed under the Affero General Public License version 3 or
- * later.
- * See the COPYING-README file.
- */
-
-namespace Test\Memcache;
-
-class APCu extends Cache {
- protected function setUp() {
- parent::setUp();
-
- if(!\OC\Memcache\APCu::isAvailable()) {
- $this->markTestSkipped('The APCu extension is not available.');
- return;
- }
- $this->instance=new \OC\Memcache\APCu($this->getUniqueID());
- }
-}
diff --git a/tests/lib/memcache/arraycache.php b/tests/lib/memcache/arraycache.php
deleted file mode 100644
index 1db673da2a8..00000000000
--- a/tests/lib/memcache/arraycache.php
+++ /dev/null
@@ -1,17 +0,0 @@
-<?php
-
-/**
- * Copyright (c) 2015 Joas Schilling <nickvergessen@owncloud.com>
- * This file is licensed under the Affero General Public License version 3 or
- * later.
- * See the COPYING-README file.
- */
-
-namespace Test\Memcache;
-
-class ArrayCache extends Cache {
- protected function setUp() {
- parent::setUp();
- $this->instance = new \OC\Memcache\ArrayCache('');
- }
-}
diff --git a/tests/lib/memcache/cache.php b/tests/lib/memcache/cache.php
deleted file mode 100644
index 8d6a231dd8d..00000000000
--- a/tests/lib/memcache/cache.php
+++ /dev/null
@@ -1,133 +0,0 @@
-<?php
-
-/**
- * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com>
- * This file is licensed under the Affero General Public License version 3 or
- * later.
- * See the COPYING-README file.
- */
-
-namespace Test\Memcache;
-
-abstract class Cache extends \Test\Cache\TestCache {
- /**
- * @var \OCP\IMemcache cache;
- */
- protected $instance;
-
- public function testExistsAfterSet() {
- $this->assertFalse($this->instance->hasKey('foo'));
- $this->instance->set('foo', 'bar');
- $this->assertTrue($this->instance->hasKey('foo'));
- }
-
- public function testGetAfterSet() {
- $this->assertNull($this->instance->get('foo'));
- $this->instance->set('foo', 'bar');
- $this->assertEquals('bar', $this->instance->get('foo'));
- }
-
- public function testGetArrayAfterSet() {
- $this->assertNull($this->instance->get('foo'));
- $this->instance->set('foo', ['bar']);
- $this->assertEquals(['bar'], $this->instance->get('foo'));
- }
-
- public function testDoesNotExistAfterRemove() {
- $this->instance->set('foo', 'bar');
- $this->instance->remove('foo');
- $this->assertFalse($this->instance->hasKey('foo'));
- }
-
- public function testRemoveNonExisting() {
- $this->instance->remove('foo');
- $this->assertFalse($this->instance->hasKey('foo'));
- }
-
- public function testArrayAccessSet() {
- $this->instance['foo'] = 'bar';
- $this->assertEquals('bar', $this->instance->get('foo'));
- }
-
- public function testArrayAccessGet() {
- $this->instance->set('foo', 'bar');
- $this->assertEquals('bar', $this->instance['foo']);
- }
-
- public function testArrayAccessExists() {
- $this->assertFalse(isset($this->instance['foo']));
- $this->instance->set('foo', 'bar');
- $this->assertTrue(isset($this->instance['foo']));
- }
-
- public function testArrayAccessUnset() {
- $this->instance->set('foo', 'bar');
- unset($this->instance['foo']);
- $this->assertFalse($this->instance->hasKey('foo'));
- }
-
- public function testAdd() {
- $this->assertTrue($this->instance->add('foo', 'bar'));
- $this->assertEquals('bar', $this->instance->get('foo'));
- $this->assertFalse($this->instance->add('foo', 'asd'));
- $this->assertEquals('bar', $this->instance->get('foo'));
- }
-
- public function testInc() {
- $this->assertEquals(1, $this->instance->inc('foo'));
- $this->assertEquals(1, $this->instance->get('foo'));
- $this->assertEquals(2, $this->instance->inc('foo'));
- $this->assertEquals(2, $this->instance->get('foo'));
- $this->assertEquals(12, $this->instance->inc('foo', 10));
- $this->assertEquals(12, $this->instance->get('foo'));
-
- $this->instance->set('foo', 'bar');
- $this->assertFalse($this->instance->inc('foo'));
- $this->assertEquals('bar', $this->instance->get('foo'));
- }
-
- public function testDec() {
- $this->assertFalse($this->instance->dec('foo'));
- $this->instance->set('foo', 20);
- $this->assertEquals(19, $this->instance->dec('foo'));
- $this->assertEquals(19, $this->instance->get('foo'));
- $this->assertEquals(9, $this->instance->dec('foo', 10));
-
- $this->instance->set('foo', 'bar');
- $this->assertFalse($this->instance->dec('foo'));
- $this->assertEquals('bar', $this->instance->get('foo'));
- }
-
- public function testCasNotChanged() {
- $this->instance->set('foo', 'bar');
- $this->assertTrue($this->instance->cas('foo', 'bar', 'asd'));
- $this->assertEquals('asd', $this->instance->get('foo'));
- }
-
- public function testCasChanged() {
- $this->instance->set('foo', 'bar1');
- $this->assertFalse($this->instance->cas('foo', 'bar', 'asd'));
- $this->assertEquals('bar1', $this->instance->get('foo'));
- }
-
- public function testCadNotChanged() {
- $this->instance->set('foo', 'bar');
- $this->assertTrue($this->instance->cad('foo', 'bar'));
- $this->assertFalse($this->instance->hasKey('foo'));
- }
-
- public function testCadChanged() {
- $this->instance->set('foo', 'bar1');
- $this->assertFalse($this->instance->cad('foo', 'bar'));
- $this->assertTrue($this->instance->hasKey('foo'));
- }
-
-
- protected function tearDown() {
- if ($this->instance) {
- $this->instance->clear();
- }
-
- parent::tearDown();
- }
-}
diff --git a/tests/lib/memcache/castrait.php b/tests/lib/memcache/castrait.php
deleted file mode 100644
index 17f412bb638..00000000000
--- a/tests/lib/memcache/castrait.php
+++ /dev/null
@@ -1,73 +0,0 @@
-<?php
-/**
- * @author Robin Appelman <icewind@owncloud.com>
- *
- * @copyright Copyright (c) 2015, ownCloud, Inc.
- * @license AGPL-3.0
- *
- * This code is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License, version 3,
- * as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License, version 3,
- * along with this program. If not, see <http://www.gnu.org/licenses/>
- *
- */
-
-namespace Test\Memcache;
-
-use Test\TestCase;
-
-class CasTrait extends TestCase {
- /**
- * @return \OC\Memcache\CasTrait
- */
- private function getCache() {
- $sourceCache = new \OC\Memcache\ArrayCache();
- $mock = $this->getMockForTrait('\OC\Memcache\CasTrait');
-
- $mock->expects($this->any())
- ->method('set')
- ->will($this->returnCallback(function ($key, $value, $ttl) use ($sourceCache) {
- return $sourceCache->set($key, $value, $ttl);
- }));
-
- $mock->expects($this->any())
- ->method('get')
- ->will($this->returnCallback(function ($key) use ($sourceCache) {
- return $sourceCache->get($key);
- }));
-
- $mock->expects($this->any())
- ->method('add')
- ->will($this->returnCallback(function ($key, $value, $ttl) use ($sourceCache) {
- return $sourceCache->add($key, $value, $ttl);
- }));
-
- $mock->expects($this->any())
- ->method('remove')
- ->will($this->returnCallback(function ($key) use ($sourceCache) {
- return $sourceCache->remove($key);
- }));
- return $mock;
- }
-
- public function testCasNotChanged() {
- $cache = $this->getCache();
- $cache->set('foo', 'bar');
- $this->assertTrue($cache->cas('foo', 'bar', 'asd'));
- $this->assertEquals('asd', $cache->get('foo'));
- }
-
- public function testCasChanged() {
- $cache = $this->getCache();
- $cache->set('foo', 'bar1');
- $this->assertFalse($cache->cas('foo', 'bar', 'asd'));
- $this->assertEquals('bar1', $cache->get('foo'));
- }
-}
diff --git a/tests/lib/memcache/memcached.php b/tests/lib/memcache/memcached.php
deleted file mode 100644
index 3ea9216029a..00000000000
--- a/tests/lib/memcache/memcached.php
+++ /dev/null
@@ -1,52 +0,0 @@
-<?php
-
-/**
- * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com>
- * This file is licensed under the Affero General Public License version 3 or
- * later.
- * See the COPYING-README file.
- */
-
-namespace Test\Memcache;
-
-class Memcached extends Cache {
- static public function setUpBeforeClass() {
- parent::setUpBeforeClass();
-
- if (!\OC\Memcache\Memcached::isAvailable()) {
- self::markTestSkipped('The memcached extension is not available.');
- }
- $instance = new \OC\Memcache\Memcached(self::getUniqueID());
- if ($instance->set(self::getUniqueID(), self::getUniqueID()) === false) {
- self::markTestSkipped('memcached server seems to be down.');
- }
- }
-
- protected function setUp() {
- parent::setUp();
- $this->instance = new \OC\Memcache\Memcached($this->getUniqueID());
- }
-
- public function testClear() {
- // Memcached is sometimes broken with clear(), so we don't test it thoroughly
- $value='ipsum lorum';
- $this->instance->set('1_value1', $value);
- $this->instance->set('1_value2', $value);
- $this->instance->set('2_value1', $value);
- $this->instance->set('3_value1', $value);
-
- $this->assertTrue($this->instance->clear('1_'));
-
- $this->assertFalse($this->instance->hasKey('1_value1'));
- $this->assertFalse($this->instance->hasKey('1_value2'));
- //$this->assertTrue($this->instance->hasKey('2_value1'));
- //$this->assertTrue($this->instance->hasKey('3_value1'));
-
- $this->assertTrue($this->instance->clear());
-
- $this->assertFalse($this->instance->hasKey('1_value1'));
- $this->assertFalse($this->instance->hasKey('1_value2'));
- $this->assertFalse($this->instance->hasKey('2_value1'));
- $this->assertFalse($this->instance->hasKey('3_value1'));
- }
-}
diff --git a/tests/lib/memcache/redis.php b/tests/lib/memcache/redis.php
deleted file mode 100644
index 2e3c5d735fe..00000000000
--- a/tests/lib/memcache/redis.php
+++ /dev/null
@@ -1,39 +0,0 @@
-<?php
-
-/**
- * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com>
- * This file is licensed under the Affero General Public License version 3 or
- * later.
- * See the COPYING-README file.
- */
-
-namespace Test\Memcache;
-
-class Redis extends Cache {
- static public function setUpBeforeClass() {
- parent::setUpBeforeClass();
-
- if (!\OC\Memcache\Redis::isAvailable()) {
- self::markTestSkipped('The redis extension is not available.');
- }
-
- set_error_handler(
- function($errno, $errstr) {
- restore_error_handler();
- self::markTestSkipped($errstr);
- },
- E_WARNING
- );
- $instance = new \OC\Memcache\Redis(self::getUniqueID());
- restore_error_handler();
-
- if ($instance->set(self::getUniqueID(), self::getUniqueID()) === false) {
- self::markTestSkipped('redis server seems to be down.');
- }
- }
-
- protected function setUp() {
- parent::setUp();
- $this->instance = new \OC\Memcache\Redis($this->getUniqueID());
- }
-}
diff --git a/tests/lib/memcache/xcache.php b/tests/lib/memcache/xcache.php
deleted file mode 100644
index 36efe0b220a..00000000000
--- a/tests/lib/memcache/xcache.php
+++ /dev/null
@@ -1,22 +0,0 @@
-<?php
-
-/**
- * Copyright (c) 2013 Robin Appelman <icewind@owncloud.com>
- * This file is licensed under the Affero General Public License version 3 or
- * later.
- * See the COPYING-README file.
- */
-
-namespace Test\Memcache;
-
-class XCache extends Cache {
- protected function setUp() {
- parent::setUp();
-
- if (!\OC\Memcache\XCache::isAvailable()) {
- $this->markTestSkipped('The xcache extension is not available.');
- return;
- }
- $this->instance = new \OC\Memcache\XCache($this->getUniqueID());
- }
-}