Files
shopPRO/tests/Unit/Domain/Cache/CacheRepositoryTest.php
Jacek Pyziak 431add234c ver. 0.283: Legacy class cleanup — S, Html, Email, Image, Log, Mobile_Detect → Shared namespace
- Migrate class.S → Shared\Helpers\Helpers (140+ files), remove 12 unused methods
- Migrate class.Html → Shared\Html\Html
- Migrate class.Email → Shared\Email\Email
- Migrate class.Image → Shared\Image\ImageManipulator
- Delete class.Log (unused), class.Mobile_Detect (outdated UA detection)
- Remove grid library loading from admin (index.php, ajax.php)
- Replace gridEdit usage in 10 admin templates with grid-edit-replacement.php
- Fix grid-edit-replacement.php AJAX to send values as JSON (grid.js compat)
- Remove mobile layout conditionals (m_html/m_css/m_js) from Site + LayoutsRepository
- Remove \Log::save_log() calls from OrderAdminService, ShopOrder, Order

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-16 23:06:06 +01:00

77 lines
2.5 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 \Shared\Helpers\Helpers::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']);
}
}