aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/Memcache
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/Memcache')
-rw-r--r--tests/lib/Memcache/APCuTest.php17
-rw-r--r--tests/lib/Memcache/ArrayCacheTest.php11
-rw-r--r--tests/lib/Memcache/Cache.php66
-rw-r--r--tests/lib/Memcache/CasTraitTest.php28
-rw-r--r--tests/lib/Memcache/FactoryTest.php57
-rw-r--r--tests/lib/Memcache/MemcachedTest.php17
-rw-r--r--tests/lib/Memcache/RedisTest.php27
7 files changed, 112 insertions, 111 deletions
diff --git a/tests/lib/Memcache/APCuTest.php b/tests/lib/Memcache/APCuTest.php
index 3568b8a4622..199bdf298f6 100644
--- a/tests/lib/Memcache/APCuTest.php
+++ b/tests/lib/Memcache/APCuTest.php
@@ -1,14 +1,15 @@
<?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.
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace Test\Memcache;
+use OC\Memcache\APCu;
+
/**
* @group Memcache
* @group APCu
@@ -17,20 +18,20 @@ class APCuTest extends Cache {
protected function setUp(): void {
parent::setUp();
- if (!\OC\Memcache\APCu::isAvailable()) {
+ if (!APCu::isAvailable()) {
$this->markTestSkipped('The APCu extension is not available.');
return;
}
- $this->instance = new \OC\Memcache\APCu($this->getUniqueID());
+ $this->instance = new APCu($this->getUniqueID());
}
- public function testCasIntChanged() {
+ public function testCasIntChanged(): void {
$this->instance->set('foo', 1);
$this->assertTrue($this->instance->cas('foo', 1, 2));
$this->assertEquals(2, $this->instance->get('foo'));
}
- public function testCasIntNotChanged() {
+ public function testCasIntNotChanged(): void {
$this->instance->set('foo', 1);
$this->assertFalse($this->instance->cas('foo', 2, 3));
$this->assertEquals(1, $this->instance->get('foo'));
diff --git a/tests/lib/Memcache/ArrayCacheTest.php b/tests/lib/Memcache/ArrayCacheTest.php
index 47a39a82d5d..e71c821729c 100644
--- a/tests/lib/Memcache/ArrayCacheTest.php
+++ b/tests/lib/Memcache/ArrayCacheTest.php
@@ -1,20 +1,21 @@
<?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.
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace Test\Memcache;
+use OC\Memcache\ArrayCache;
+
/**
* @group Memcache
*/
class ArrayCacheTest extends Cache {
protected function setUp(): void {
parent::setUp();
- $this->instance = new \OC\Memcache\ArrayCache('');
+ $this->instance = new ArrayCache('');
}
}
diff --git a/tests/lib/Memcache/Cache.php b/tests/lib/Memcache/Cache.php
index ab316738c9c..b48f5557faa 100644
--- a/tests/lib/Memcache/Cache.php
+++ b/tests/lib/Memcache/Cache.php
@@ -1,79 +1,80 @@
<?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.
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace Test\Memcache;
+use OCP\IMemcache;
+
abstract class Cache extends \Test\Cache\TestCache {
/**
- * @var \OCP\IMemcache cache;
+ * @var IMemcache cache;
*/
protected $instance;
- public function testExistsAfterSet() {
+ public function testExistsAfterSet(): void {
$this->assertFalse($this->instance->hasKey('foo'));
$this->instance->set('foo', 'bar');
$this->assertTrue($this->instance->hasKey('foo'));
}
- public function testGetAfterSet() {
+ public function testGetAfterSet(): void {
$this->assertNull($this->instance->get('foo'));
$this->instance->set('foo', 'bar');
$this->assertEquals('bar', $this->instance->get('foo'));
}
- public function testGetArrayAfterSet() {
+ public function testGetArrayAfterSet(): void {
$this->assertNull($this->instance->get('foo'));
$this->instance->set('foo', ['bar']);
$this->assertEquals(['bar'], $this->instance->get('foo'));
}
- public function testDoesNotExistAfterRemove() {
+ public function testDoesNotExistAfterRemove(): void {
$this->instance->set('foo', 'bar');
$this->instance->remove('foo');
$this->assertFalse($this->instance->hasKey('foo'));
}
- public function testRemoveNonExisting() {
+ public function testRemoveNonExisting(): void {
$this->instance->remove('foo');
$this->assertFalse($this->instance->hasKey('foo'));
}
- public function testArrayAccessSet() {
+ public function testArrayAccessSet(): void {
$this->instance['foo'] = 'bar';
$this->assertEquals('bar', $this->instance->get('foo'));
}
- public function testArrayAccessGet() {
+ public function testArrayAccessGet(): void {
$this->instance->set('foo', 'bar');
$this->assertEquals('bar', $this->instance['foo']);
}
- public function testArrayAccessExists() {
+ public function testArrayAccessExists(): void {
$this->assertFalse(isset($this->instance['foo']));
$this->instance->set('foo', 'bar');
$this->assertTrue(isset($this->instance['foo']));
}
- public function testArrayAccessUnset() {
+ public function testArrayAccessUnset(): void {
$this->instance->set('foo', 'bar');
unset($this->instance['foo']);
$this->assertFalse($this->instance->hasKey('foo'));
}
- public function testAdd() {
+ public function testAdd(): void {
$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() {
+ public function testInc(): void {
$this->assertEquals(1, $this->instance->inc('foo'));
$this->assertEquals(1, $this->instance->get('foo'));
$this->assertEquals(2, $this->instance->inc('foo'));
@@ -86,7 +87,7 @@ abstract class Cache extends \Test\Cache\TestCache {
$this->assertEquals('bar', $this->instance->get('foo'));
}
- public function testDec() {
+ public function testDec(): void {
$this->assertFalse($this->instance->dec('foo'));
$this->instance->set('foo', 20);
$this->assertEquals(19, $this->instance->dec('foo'));
@@ -98,30 +99,53 @@ abstract class Cache extends \Test\Cache\TestCache {
$this->assertEquals('bar', $this->instance->get('foo'));
}
- public function testCasNotChanged() {
+ public function testCasNotChanged(): void {
$this->instance->set('foo', 'bar');
$this->assertTrue($this->instance->cas('foo', 'bar', 'asd'));
$this->assertEquals('asd', $this->instance->get('foo'));
}
- public function testCasChanged() {
+ public function testCasChanged(): void {
$this->instance->set('foo', 'bar1');
$this->assertFalse($this->instance->cas('foo', 'bar', 'asd'));
$this->assertEquals('bar1', $this->instance->get('foo'));
}
- public function testCadNotChanged() {
+ public function testCasNotSet(): void {
+ $this->assertFalse($this->instance->cas('foo', 'bar', 'asd'));
+ }
+
+ public function testCadNotChanged(): void {
$this->instance->set('foo', 'bar');
$this->assertTrue($this->instance->cad('foo', 'bar'));
$this->assertFalse($this->instance->hasKey('foo'));
}
- public function testCadChanged() {
+ public function testCadChanged(): void {
$this->instance->set('foo', 'bar1');
$this->assertFalse($this->instance->cad('foo', 'bar'));
$this->assertTrue($this->instance->hasKey('foo'));
}
+ public function testCadNotSet(): void {
+ $this->assertFalse($this->instance->cad('foo', 'bar'));
+ }
+
+ public function testNcadNotChanged(): void {
+ $this->instance->set('foo', 'bar');
+ $this->assertFalse($this->instance->ncad('foo', 'bar'));
+ $this->assertTrue($this->instance->hasKey('foo'));
+ }
+
+ public function testNcadChanged(): void {
+ $this->instance->set('foo', 'bar1');
+ $this->assertTrue($this->instance->ncad('foo', 'bar'));
+ $this->assertFalse($this->instance->hasKey('foo'));
+ }
+
+ public function testNcadNotSet(): void {
+ $this->assertFalse($this->instance->ncad('foo', 'bar'));
+ }
protected function tearDown(): void {
if ($this->instance) {
diff --git a/tests/lib/Memcache/CasTraitTest.php b/tests/lib/Memcache/CasTraitTest.php
index f077cf143b3..9de04fa2726 100644
--- a/tests/lib/Memcache/CasTraitTest.php
+++ b/tests/lib/Memcache/CasTraitTest.php
@@ -1,26 +1,14 @@
<?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/>
- *
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace Test\Memcache;
+use OC\Memcache\ArrayCache;
use Test\TestCase;
/**
@@ -31,7 +19,7 @@ class CasTraitTest extends TestCase {
* @return \OC\Memcache\CasTrait
*/
private function getCache() {
- $sourceCache = new \OC\Memcache\ArrayCache();
+ $sourceCache = new ArrayCache();
$mock = $this->getMockForTrait('\OC\Memcache\CasTrait');
$mock->expects($this->any())
@@ -60,14 +48,14 @@ class CasTraitTest extends TestCase {
return $mock;
}
- public function testCasNotChanged() {
+ public function testCasNotChanged(): void {
$cache = $this->getCache();
$cache->set('foo', 'bar');
$this->assertTrue($cache->cas('foo', 'bar', 'asd'));
$this->assertEquals('asd', $cache->get('foo'));
}
- public function testCasChanged() {
+ public function testCasChanged(): void {
$cache = $this->getCache();
$cache->set('foo', 'bar1');
$this->assertFalse($cache->cas('foo', 'bar', 'asd'));
diff --git a/tests/lib/Memcache/FactoryTest.php b/tests/lib/Memcache/FactoryTest.php
index e8bf519e1a9..e16e079349f 100644
--- a/tests/lib/Memcache/FactoryTest.php
+++ b/tests/lib/Memcache/FactoryTest.php
@@ -1,27 +1,16 @@
<?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/>
- *
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-only
*/
namespace Test\Memcache;
+use OC\Memcache\Factory;
use OC\Memcache\NullCache;
+use OCP\HintException;
use OCP\Profiler\IProfiler;
use Psr\Log\LoggerInterface;
@@ -70,37 +59,37 @@ class FactoryTest extends \Test\TestCase {
public const UNAVAILABLE1 = '\\Test\\Memcache\\Test_Factory_Unavailable_Cache1';
public const UNAVAILABLE2 = '\\Test\\Memcache\\Test_Factory_Unavailable_Cache2';
- public function cacheAvailabilityProvider() {
+ public static function cacheAvailabilityProvider(): array {
return [
[
// local and distributed available
self::AVAILABLE1, self::AVAILABLE2, null,
- self::AVAILABLE1, self::AVAILABLE2, \OC\Memcache\Factory::NULL_CACHE
+ self::AVAILABLE1, self::AVAILABLE2, 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
+ Factory::NULL_CACHE, Factory::NULL_CACHE, Factory::NULL_CACHE
],
[
// local available, distributed null (most common scenario)
self::AVAILABLE1, null, null,
- self::AVAILABLE1, self::AVAILABLE1, \OC\Memcache\Factory::NULL_CACHE
+ self::AVAILABLE1, self::AVAILABLE1, Factory::NULL_CACHE
],
[
// locking cache available
null, null, self::AVAILABLE1,
- \OC\Memcache\Factory::NULL_CACHE, \OC\Memcache\Factory::NULL_CACHE, self::AVAILABLE1
+ Factory::NULL_CACHE, 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
+ Factory::NULL_CACHE, Factory::NULL_CACHE, Factory::NULL_CACHE
]
];
}
- public function cacheUnavailableProvider() {
+ public static function cacheUnavailableProvider(): array {
return [
[
// local available, distributed unavailable
@@ -117,34 +106,30 @@ class FactoryTest extends \Test\TestCase {
];
}
- /**
- * @dataProvider cacheAvailabilityProvider
- */
+ #[\PHPUnit\Framework\Attributes\DataProvider('cacheAvailabilityProvider')]
public function testCacheAvailability($localCache, $distributedCache, $lockingCache,
- $expectedLocalCache, $expectedDistributedCache, $expectedLockingCache) {
+ $expectedLocalCache, $expectedDistributedCache, $expectedLockingCache): void {
$logger = $this->getMockBuilder(LoggerInterface::class)->getMock();
$profiler = $this->getMockBuilder(IProfiler::class)->getMock();
- $factory = new \OC\Memcache\Factory('abc', $logger, $profiler, $localCache, $distributedCache, $lockingCache);
+ $factory = new Factory(fn () => 'abc', $logger, $profiler, $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
- */
- public function testCacheNotAvailableException($localCache, $distributedCache) {
- $this->expectException(\OCP\HintException::class);
+ #[\PHPUnit\Framework\Attributes\DataProvider('cacheUnavailableProvider')]
+ public function testCacheNotAvailableException($localCache, $distributedCache): void {
+ $this->expectException(HintException::class);
$logger = $this->getMockBuilder(LoggerInterface::class)->getMock();
$profiler = $this->getMockBuilder(IProfiler::class)->getMock();
- new \OC\Memcache\Factory('abc', $logger, $profiler, $localCache, $distributedCache);
+ new Factory(fn () => 'abc', $logger, $profiler, $localCache, $distributedCache);
}
public function testCreateInMemory(): void {
$logger = $this->getMockBuilder(LoggerInterface::class)->getMock();
$profiler = $this->getMockBuilder(IProfiler::class)->getMock();
- $factory = new \OC\Memcache\Factory('abc', $logger, $profiler, null, null, null);
+ $factory = new Factory(fn () => 'abc', $logger, $profiler, null, null, null);
$cache = $factory->createInMemory();
$cache->set('test', 48);
diff --git a/tests/lib/Memcache/MemcachedTest.php b/tests/lib/Memcache/MemcachedTest.php
index 24cf0ba7af3..61e2f42e3d6 100644
--- a/tests/lib/Memcache/MemcachedTest.php
+++ b/tests/lib/Memcache/MemcachedTest.php
@@ -1,14 +1,15 @@
<?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.
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace Test\Memcache;
+use OC\Memcache\Memcached;
+
/**
* @group Memcache
* @group Memcached
@@ -17,10 +18,10 @@ class MemcachedTest extends Cache {
public static function setUpBeforeClass(): void {
parent::setUpBeforeClass();
- if (!\OC\Memcache\Memcached::isAvailable()) {
+ if (!Memcached::isAvailable()) {
self::markTestSkipped('The memcached extension is not available.');
}
- $instance = new \OC\Memcache\Memcached(self::getUniqueID());
+ $instance = new Memcached(self::getUniqueID());
if ($instance->set(self::getUniqueID(), self::getUniqueID()) === false) {
self::markTestSkipped('memcached server seems to be down.');
}
@@ -28,10 +29,10 @@ class MemcachedTest extends Cache {
protected function setUp(): void {
parent::setUp();
- $this->instance = new \OC\Memcache\Memcached($this->getUniqueID());
+ $this->instance = new Memcached($this->getUniqueID());
}
- public function testClear() {
+ public function testClear(): void {
// Memcached is sometimes broken with clear(), so we don't test it thoroughly
$value = 'ipsum lorum';
$this->instance->set('1_value1', $value);
diff --git a/tests/lib/Memcache/RedisTest.php b/tests/lib/Memcache/RedisTest.php
index 27c6fc11ee8..c1dcc954925 100644
--- a/tests/lib/Memcache/RedisTest.php
+++ b/tests/lib/Memcache/RedisTest.php
@@ -1,15 +1,16 @@
<?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.
+ * SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-FileCopyrightText: 2016 ownCloud, Inc.
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace Test\Memcache;
use OC\Memcache\Redis;
+use OCP\IConfig;
+use OCP\Server;
/**
* @group Memcache
@@ -24,24 +25,24 @@ class RedisTest extends Cache {
public static function setUpBeforeClass(): void {
parent::setUpBeforeClass();
- if (!\OC\Memcache\Redis::isAvailable()) {
+ if (!Redis::isAvailable()) {
self::markTestSkipped('The redis extension is not available.');
}
- if (\OC::$server->getConfig()->getSystemValue('redis', []) === []) {
+ if (Server::get(IConfig::class)->getSystemValue('redis', []) === []) {
self::markTestSkipped('Redis not configured in config.php');
}
$errorOccurred = false;
set_error_handler(
- function ($errno, $errstr) {
+ function ($errno, $errstr): void {
throw new \RuntimeException($errstr, 123456789);
},
E_WARNING
);
$instance = null;
try {
- $instance = new \OC\Memcache\Redis(self::getUniqueID());
+ $instance = new Redis(self::getUniqueID());
} catch (\RuntimeException $e) {
$errorOccurred = $e->getCode() === 123456789 ? $e->getMessage() : false;
}
@@ -61,23 +62,23 @@ class RedisTest extends Cache {
protected function setUp(): void {
parent::setUp();
- $this->instance = new \OC\Memcache\Redis($this->getUniqueID());
+ $this->instance = new Redis($this->getUniqueID());
}
- public function testScriptHashes() {
- foreach (\OC\Memcache\Redis::LUA_SCRIPTS as $script) {
+ public function testScriptHashes(): void {
+ foreach (Redis::LUA_SCRIPTS as $script) {
$this->assertEquals(sha1($script[0]), $script[1]);
}
}
- public function testCasTtlNotChanged() {
+ public function testCasTtlNotChanged(): void {
$this->instance->set('foo', 'bar', 50);
$this->assertTrue($this->instance->compareSetTTL('foo', 'bar', 100));
// allow for 1s of inaccuracy due to time moving forward
$this->assertLessThan(1, 100 - $this->instance->getTTL('foo'));
}
- public function testCasTtlChanged() {
+ public function testCasTtlChanged(): void {
$this->instance->set('foo', 'bar1', 50);
$this->assertFalse($this->instance->compareSetTTL('foo', 'bar', 100));
// allow for 1s of inaccuracy due to time moving forward