Merge branch 'develop' into phpstan-level-3

This commit is contained in:
Art4 2025-05-09 06:29:29 +00:00
commit 63558f92eb
50 changed files with 1362 additions and 611 deletions

View file

@ -35,4 +35,18 @@ class APCuCacheTest extends MemoryCacheTestCase
$this->cache->clear(false);
parent::tearDown();
}
/**
* @small
*/
public function testStats()
{
$stats = $this->instance->getStats();
self::assertNotNull($stats['entries']);
self::assertNotNull($stats['used_memory']);
self::assertNotNull($stats['hits']);
self::assertNotNull($stats['misses']);
self::assertNotNull($stats['avail_mem']);
}
}

View file

@ -33,4 +33,12 @@ class ArrayCacheTest extends MemoryCacheTestCase
self::markTestSkipped("Array Cache doesn't support TTL");
return true;
}
/**
* @small
*/
public function testGetStats()
{
self::assertEmpty($this->cache->getStats());
}
}

View file

@ -59,4 +59,21 @@ class MemcacheCacheTest extends MemoryCacheTestCase
{
static::markTestIncomplete('Race condition because of too fast getAllKeys() which uses a workaround');
}
/**
* @small
*/
public function testStats()
{
$stats = $this->instance->getStats();
self::assertNotNull($stats['version']);
self::assertIsNumeric($stats['hits']);
self::assertIsNumeric($stats['misses']);
self::assertIsNumeric($stats['evictions']);
self::assertIsNumeric($stats['entries']);
self::assertIsNumeric($stats['used_memory']);
self::assertGreaterThan(0, $stats['connected_clients']);
self::assertGreaterThan(0, $stats['uptime']);
}
}

View file

@ -58,4 +58,21 @@ class MemcachedCacheTest extends MemoryCacheTestCase
{
static::markTestIncomplete('Race condition because of too fast getAllKeys() which uses a workaround');
}
/**
* @small
*/
public function testStats()
{
$stats = $this->instance->getStats();
self::assertNotNull($stats['version']);
self::assertIsNumeric($stats['hits']);
self::assertIsNumeric($stats['misses']);
self::assertIsNumeric($stats['evictions']);
self::assertIsNumeric($stats['entries']);
self::assertIsNumeric($stats['used_memory']);
self::assertGreaterThan(0, $stats['connected_clients']);
self::assertGreaterThan(0, $stats['uptime']);
}
}

View file

@ -0,0 +1,56 @@
<?php
// Copyright (C) 2010-2024, the Friendica project
// SPDX-FileCopyrightText: 2010-2024 the Friendica project
//
// SPDX-License-Identifier: AGPL-3.0-or-later
namespace Core\Cache;
use Friendica\Core\Cache\Type\ArrayCache;
use Friendica\Core\Cache\Type\ProfilerCacheDecorator;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Test\MemoryCacheTestCase;
use Friendica\Util\Profiler;
class ProfilerCacheDecoratorTest extends MemoryCacheTestCase
{
protected function getInstance()
{
$config = \Mockery::mock(IManageConfigValues::class);
$config->shouldReceive('get')->with('system', 'profiler')->once()->andReturn(false);
$config->shouldReceive('get')->with('rendertime', 'callstack')->once()->andReturn(false);
$this->cache = new ProfilerCacheDecorator(new ArrayCache('localhost'), new Profiler($config));
return $this->cache;
}
protected function tearDown(): void
{
$this->cache->clear(false);
parent::tearDown();
}
/**
* @doesNotPerformAssertions
*/
public function testTTL()
{
// Array Cache doesn't support TTL
self::markTestSkipped("Array Cache doesn't support TTL");
return true;
}
/**
* @small
*/
public function testGetStats()
{
self::assertEmpty($this->cache->getStats());
}
public function testGetName()
{
self::assertStringEndsWith(' (with profiler)', $this->instance->getName());
}
}

View file

@ -57,4 +57,21 @@ class RedisCacheTest extends MemoryCacheTestCase
$this->cache->clear(false);
parent::tearDown();
}
/**
* @small
*/
public function testStats()
{
$stats = $this->instance->getStats();
self::assertNotNull($stats['version']);
self::assertIsNumeric($stats['hits']);
self::assertIsNumeric($stats['misses']);
self::assertIsNumeric($stats['evictions']);
self::assertIsNumeric($stats['entries']);
self::assertIsNumeric($stats['used_memory']);
self::assertGreaterThan(0, $stats['connected_clients']);
self::assertGreaterThan(0, $stats['uptime']);
}
}

View file

@ -7,26 +7,39 @@
namespace Friendica\Test\src\Core\Lock;
use Friendica\Core\Cache\Capability\ICanCacheInMemory;
use Friendica\Core\Cache\Type\APCuCache;
use Friendica\Core\Lock\Capability\ICanLock;
use Friendica\Core\Lock\Type\CacheLock;
use Friendica\Test\LockTestCase;
use Friendica\Test\CacheLockTestCase;
/**
* @group APCU
*/
class APCuCacheLockTest extends LockTestCase
class APCuCacheLockTest extends CacheLockTestCase
{
private APCuCache $cache;
private ICanLock $lock;
protected function setUp(): void
{
if (!APCuCache::isAvailable()) {
static::markTestSkipped('APCu is not available');
}
$this->cache = new APCuCache('localhost');
$this->lock = new CacheLock($this->cache);
parent::setUp();
}
protected function getInstance()
protected function getInstance(): CacheLock
{
return new CacheLock(new APCuCache('localhost'));
return $this->lock;
}
protected function getCache(): ICanCacheInMemory
{
return $this->cache;
}
}

View file

@ -7,15 +7,32 @@
namespace Friendica\Test\src\Core\Lock;
use Friendica\Core\Cache\Capability\ICanCacheInMemory;
use Friendica\Core\Cache\Type\ArrayCache;
use Friendica\Core\Lock\Type\CacheLock;
use Friendica\Test\LockTestCase;
use Friendica\Test\CacheLockTestCase;
class ArrayCacheLockTest extends LockTestCase
class ArrayCacheLockTest extends CacheLockTestCase
{
protected function getInstance()
private CacheLock $lock;
private ArrayCache $cache;
protected function setUp(): void
{
return new CacheLock(new ArrayCache('localhost'));
$this->cache = new ArrayCache('localhost');
$this->lock = new CacheLock($this->cache);
parent::setUp();
}
protected function getInstance(): CacheLock
{
return $this->lock;
}
protected function getCache(): ICanCacheInMemory
{
return $this->cache;
}
/**

View file

@ -7,6 +7,7 @@
namespace Friendica\Test\src\Core\Lock;
use Friendica\Core\Lock\Capability\ICanLock;
use Friendica\Core\Lock\Type\DatabaseLock;
use Friendica\Test\LockTestCase;
use Friendica\Test\Util\CreateDatabaseTrait;
@ -26,7 +27,7 @@ class DatabaseLockDriverTest extends LockTestCase
parent::setUp();
}
protected function getInstance()
protected function getInstance(): ICanLock
{
return new DatabaseLock($this->getDbInstance(), $this->pid);
}

View file

@ -8,19 +8,23 @@
namespace Friendica\Test\src\Core\Lock;
use Exception;
use Friendica\Core\Cache\Capability\ICanCacheInMemory;
use Friendica\Core\Cache\Type\MemcacheCache;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\Lock\Type\CacheLock;
use Friendica\Test\LockTestCase;
use Friendica\Test\CacheLockTestCase;
use Mockery;
/**
* @requires extension Memcache
* @group MEMCACHE
*/
class MemcacheCacheLockTest extends LockTestCase
class MemcacheCacheLockTest extends CacheLockTestCase
{
protected function getInstance()
private CacheLock $lock;
private MemcacheCache $cache;
protected function setUp(): void
{
$configMock = Mockery::mock(IManageConfigValues::class);
@ -36,16 +40,24 @@ class MemcacheCacheLockTest extends LockTestCase
->with('system', 'memcache_port')
->andReturn($port);
$lock = null;
try {
$cache = new MemcacheCache($host, $configMock);
$lock = new CacheLock($cache);
$this->cache = new MemcacheCache($host, $configMock);
$this->lock = new CacheLock($this->cache);
} catch (Exception $e) {
static::markTestSkipped('Memcache is not available');
}
return $lock;
parent::setUp();
}
protected function getInstance(): CacheLock
{
return $this->lock;
}
protected function getCache(): ICanCacheInMemory
{
return $this->cache;
}
/**

View file

@ -8,10 +8,11 @@
namespace Friendica\Test\src\Core\Lock;
use Exception;
use Friendica\Core\Cache\Capability\ICanCacheInMemory;
use Friendica\Core\Cache\Type\MemcachedCache;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\Lock\Type\CacheLock;
use Friendica\Test\LockTestCase;
use Friendica\Test\CacheLockTestCase;
use Mockery;
use Psr\Log\NullLogger;
@ -19,9 +20,12 @@ use Psr\Log\NullLogger;
* @requires extension memcached
* @group MEMCACHED
*/
class MemcachedCacheLockTest extends LockTestCase
class MemcachedCacheLockTest extends CacheLockTestCase
{
protected function getInstance()
private MemcachedCache $cache;
private CacheLock $lock;
protected function setUp(): void
{
$configMock = Mockery::mock(IManageConfigValues::class);
@ -35,16 +39,24 @@ class MemcachedCacheLockTest extends LockTestCase
$logger = new NullLogger();
$lock = null;
try {
$cache = new MemcachedCache($host, $configMock, $logger);
$lock = new CacheLock($cache);
$this->cache = new MemcachedCache($host, $configMock, $logger);
$this->lock = new CacheLock($this->cache);
} catch (Exception $e) {
static::markTestSkipped('Memcached is not available');
}
return $lock;
parent::setUp();
}
protected function getInstance(): CacheLock
{
return $this->lock;
}
protected function getCache(): ICanCacheInMemory
{
return $this->cache;
}
/**

View file

@ -8,19 +8,20 @@
namespace Friendica\Test\src\Core\Lock;
use Exception;
use Friendica\Core\Cache\Capability\ICanCacheInMemory;
use Friendica\Core\Cache\Type\RedisCache;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\Lock\Type\CacheLock;
use Friendica\Test\LockTestCase;
use Friendica\Test\CacheLockTestCase;
use Mockery;
/**
* @requires extension redis
* @group REDIS
*/
class RedisCacheLockTest extends LockTestCase
class RedisCacheLockTest extends CacheLockTestCase
{
protected function getInstance()
protected function setUp(): void
{
$configMock = Mockery::mock(IManageConfigValues::class);
@ -45,15 +46,23 @@ class RedisCacheLockTest extends LockTestCase
->with('system', 'redis_password')
->andReturn(null);
$lock = null;
try {
$cache = new RedisCache($host, $configMock);
$lock = new CacheLock($cache);
$this->cache = new RedisCache($host, $configMock);
$this->lock = new CacheLock($this->cache);
} catch (Exception $e) {
static::markTestSkipped('Redis is not available. Error: ' . $e->getMessage());
}
return $lock;
parent::setUp();
}
protected function getInstance(): CAcheLock
{
return $this->lock;
}
protected function getCache(): ICanCacheInMemory
{
return $this->cache;
}
}

View file

@ -12,6 +12,7 @@ use Friendica\App;
use Friendica\Core\Config\Capability\IManageConfigValues;
use Friendica\Core\Config\Model\ReadOnlyFileConfig;
use Friendica\Core\Config\ValueObject\Cache;
use Friendica\Core\Lock\Capability\ICanLock;
use Friendica\Core\Lock\Type\SemaphoreLock;
use Friendica\Core\System;
use Friendica\DI;
@ -31,7 +32,7 @@ class SemaphoreLockTest extends LockTestCase
$dice->shouldReceive('create')->with(App::class)->andReturn($app);
$configCache = new Cache(['system' => ['temppath' => '/tmp']]);
$configMock = new ReadOnlyFileConfig($configCache);
$configMock = new ReadOnlyFileConfig($configCache);
$dice->shouldReceive('create')->with(IManageConfigValues::class)->andReturn($configMock);
// @todo Because "get_temppath()" is using static methods, we have to initialize the BaseObject
@ -40,7 +41,7 @@ class SemaphoreLockTest extends LockTestCase
parent::setUp();
}
protected function getInstance()
protected function getInstance(): ICanLock
{
return new SemaphoreLock();
}