Files
shopPRO/tests/Unit/Domain/Cache/CacheRepositoryTest.php
Jacek Pyziak 1c88f8adfa Add new settings and cache repository files, update admin settings controller and templates
- Introduced new `SettingsRepository` and `CacheRepository` classes in the `autoload\Domain` namespace.
- Updated `SettingsController` in the `admin\Controllers` namespace to enhance settings management.
- Added new templates for settings in `admin\templates\settings` and `admin\templates\site`.
- Improved overall structure and organization of settings-related files.
2026-02-05 23:32:48 +01:00

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(\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(\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']);
}
}