createMock(Connection::class); $conn->method('executeQuery'); // SELECT 1 → موفق $em = $this->createMock(EntityManagerInterface::class); $em->method('getConnection')->willReturn($conn); return $em; } public function testSilencesLoggerOnPool(): void { $pool = new class implements CacheItemPoolInterface, LoggerAwareInterface { public ?LoggerInterface $logger = null; public function setLogger(LoggerInterface $logger): void { $this->logger = $logger; } public function getItem($key): CacheItemInterface { throw new \RuntimeException('redis down'); } public function getItems(array $keys = []): iterable { return []; } public function hasItem($key): bool { return false; } public function clear(): bool { return true; } public function deleteItem($key): bool { return true; } public function deleteItems(array $keys): bool { return true; } public function save(CacheItemInterface $item): bool { return true; } public function saveDeferred(CacheItemInterface $item): bool { return true; } public function commit(): bool { return true; } }; $controller = new HealthController($this->em(), $pool); // logger فوراً در constructor خنثی می‌شود $this->assertInstanceOf(NullLogger::class, $pool->logger); // redis افتاده → degraded + 503، بدون throw $response = $controller(); $this->assertSame(503, $response->getStatusCode()); $body = json_decode($response->getContent(), true); $this->assertSame('degraded', $body['status']); $this->assertSame('error', $body['checks']['redis']); $this->assertSame('ok', $body['checks']['database']); } }