aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/Memcache
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/Memcache')
-rw-r--r--tests/lib/Memcache/APCuTest.php10
-rw-r--r--tests/lib/Memcache/ArrayCacheTest.php4
-rw-r--r--tests/lib/Memcache/Cache.php59
-rw-r--r--tests/lib/Memcache/CasTraitTest.php8
-rw-r--r--tests/lib/Memcache/FactoryTest.php37
-rw-r--r--tests/lib/Memcache/MemcachedTest.php10
-rw-r--r--tests/lib/Memcache/RedisTest.php20
7 files changed, 91 insertions, 57 deletions
diff --git a/tests/lib/Memcache/APCuTest.php b/tests/lib/Memcache/APCuTest.php
index c13d30da136..199bdf298f6 100644
--- a/tests/lib/Memcache/APCuTest.php
+++ b/tests/lib/Memcache/APCuTest.php
@@ -8,6 +8,8 @@
namespace Test\Memcache;
+use OC\Memcache\APCu;
+
/**
* @group Memcache
* @group APCu
@@ -16,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 42b548355eb..e71c821729c 100644
--- a/tests/lib/Memcache/ArrayCacheTest.php
+++ b/tests/lib/Memcache/ArrayCacheTest.php
@@ -8,12 +8,14 @@
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 efdaffc94eb..b48f5557faa 100644
--- a/tests/lib/Memcache/Cache.php
+++ b/tests/lib/Memcache/Cache.php
@@ -8,71 +8,73 @@
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'));
@@ -85,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'));
@@ -97,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 1c09a0e08f8..9de04fa2726 100644
--- a/tests/lib/Memcache/CasTraitTest.php
+++ b/tests/lib/Memcache/CasTraitTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -7,6 +8,7 @@
namespace Test\Memcache;
+use OC\Memcache\ArrayCache;
use Test\TestCase;
/**
@@ -17,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())
@@ -46,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 5a1509eb3d9..e16e079349f 100644
--- a/tests/lib/Memcache/FactoryTest.php
+++ b/tests/lib/Memcache/FactoryTest.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
@@ -7,7 +8,9 @@
namespace Test\Memcache;
+use OC\Memcache\Factory;
use OC\Memcache\NullCache;
+use OCP\HintException;
use OCP\Profiler\IProfiler;
use Psr\Log\LoggerInterface;
@@ -56,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
@@ -103,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 48f93a45ed9..61e2f42e3d6 100644
--- a/tests/lib/Memcache/MemcachedTest.php
+++ b/tests/lib/Memcache/MemcachedTest.php
@@ -8,6 +8,8 @@
namespace Test\Memcache;
+use OC\Memcache\Memcached;
+
/**
* @group Memcache
* @group Memcached
@@ -16,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.');
}
@@ -27,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 8df286b2f93..c1dcc954925 100644
--- a/tests/lib/Memcache/RedisTest.php
+++ b/tests/lib/Memcache/RedisTest.php
@@ -9,6 +9,8 @@
namespace Test\Memcache;
use OC\Memcache\Redis;
+use OCP\IConfig;
+use OCP\Server;
/**
* @group Memcache
@@ -23,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;
}
@@ -60,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