- Banners frontend: front\Views\Banners (new), BannerRepository +2 frontend methods, front\view\Site przepięty, usunięte front\factory\Banners i front\view\Banners - Cache cleanup: eliminacja legacy class.Cache.php (file-based cache), 13 metod front\factory przepiętych z \Cache::fetch/store na CacheHandler - Shared\Cache namespace: CacheHandler i RedisConnection przeniesione do Shared\Cache\, 60 odwołań CacheHandler i 12 odwołań RedisConnection przepiętych, usunięte backward-compat wrappery class.CacheHandler.php i class.RedisConnection.php - Naprawione rozbieżności kluczy cache (random_products, category_name) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
77 lines
2.4 KiB
PHP
77 lines
2.4 KiB
PHP
<?php
|
|
namespace Tests\Unit\Domain\Cache;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
use Domain\Cache\CacheRepository;
|
|
|
|
/**
|
|
* Testy dla CacheRepository
|
|
*
|
|
* Testujemy logikę Redis (mockowaną) oraz strukturę odpowiedzi.
|
|
* Czyszczenie katalogów delegowane do \S::delete_dir() - nietestowalne unit testami.
|
|
*/
|
|
class CacheRepositoryTest extends TestCase
|
|
{
|
|
/**
|
|
* Test: Czyszczenie cache z Redis
|
|
*/
|
|
public function testClearCacheWithRedis(): void
|
|
{
|
|
$mockRedis = $this->createMock(\Redis::class);
|
|
$mockRedis->expects($this->once())->method('flushAll')->willReturn(true);
|
|
|
|
$mockRedisConnection = $this->createMock(\Shared\Cache\RedisConnection::class);
|
|
$mockRedisConnection->expects($this->once())->method('getConnection')->willReturn($mockRedis);
|
|
|
|
$repository = new CacheRepository($mockRedisConnection);
|
|
$result = $repository->clearCache();
|
|
|
|
$this->assertTrue($result['success']);
|
|
$this->assertTrue($result['redisCleared']);
|
|
$this->assertStringContainsString('wyczyszczony', $result['message']);
|
|
}
|
|
|
|
/**
|
|
* Test: Redis niedostępny (getConnection zwraca null)
|
|
*/
|
|
public function testClearCacheRedisUnavailable(): void
|
|
{
|
|
$mockRedisConnection = $this->createMock(\Shared\Cache\RedisConnection::class);
|
|
$mockRedisConnection->expects($this->once())->method('getConnection')->willReturn(null);
|
|
|
|
$repository = new CacheRepository($mockRedisConnection);
|
|
$result = $repository->clearCache();
|
|
|
|
$this->assertTrue($result['success']);
|
|
$this->assertFalse($result['redisCleared']);
|
|
}
|
|
|
|
/**
|
|
* Test: Bez RedisConnection (null)
|
|
*/
|
|
public function testClearCacheWithoutRedis(): void
|
|
{
|
|
$repository = new CacheRepository(null);
|
|
$result = $repository->clearCache();
|
|
|
|
$this->assertTrue($result['success']);
|
|
$this->assertFalse($result['redisCleared']);
|
|
}
|
|
|
|
/**
|
|
* Test: Struktura odpowiedzi
|
|
*/
|
|
public function testClearCacheReturnStructure(): void
|
|
{
|
|
$repository = new CacheRepository(null);
|
|
$result = $repository->clearCache();
|
|
|
|
$this->assertArrayHasKey('success', $result);
|
|
$this->assertArrayHasKey('message', $result);
|
|
$this->assertArrayHasKey('redisCleared', $result);
|
|
$this->assertIsBool($result['success']);
|
|
$this->assertIsString($result['message']);
|
|
$this->assertIsBool($result['redisCleared']);
|
|
}
|
|
}
|