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