@@ -387,4 +387,66 @@ public function testFind(): void
387387 // First should be A (10), Second B (20)
388388 $ this ->assertTrue ($ results [0 ]->getValue () <= $ results [1 ]->getValue ());
389389 }
390+
391+ /**
392+ * Test healthCheck() method
393+ */
394+ public function testHealthCheck (): void
395+ {
396+ $ adapter = $ this ->usage ->getAdapter ();
397+
398+ $ health = $ adapter ->healthCheck ();
399+
400+ // Assert basic structure
401+ $ this ->assertIsArray ($ health );
402+ $ this ->assertArrayHasKey ('healthy ' , $ health );
403+ $ this ->assertArrayHasKey ('host ' , $ health );
404+ $ this ->assertArrayHasKey ('port ' , $ health );
405+ $ this ->assertArrayHasKey ('database ' , $ health );
406+ $ this ->assertArrayHasKey ('secure ' , $ health );
407+
408+ // Assert connection is healthy
409+ $ this ->assertTrue ($ health ['healthy ' ], 'ClickHouse should be healthy ' );
410+
411+ // Assert additional fields are present when healthy
412+ $ this ->assertArrayHasKey ('version ' , $ health );
413+ $ this ->assertArrayHasKey ('uptime ' , $ health );
414+ $ this ->assertArrayHasKey ('response_time ' , $ health );
415+ $ this ->assertIsString ($ health ['version ' ]);
416+ $ this ->assertIsInt ($ health ['uptime ' ]);
417+ $ this ->assertIsFloat ($ health ['response_time ' ]);
418+ $ this ->assertGreaterThan (0 , $ health ['response_time ' ]);
419+ }
420+
421+ /**
422+ * Test healthCheck() with invalid connection
423+ */
424+ public function testHealthCheckFailure (): void
425+ {
426+ // Create adapter with invalid host
427+ $ adapter = new ClickHouseAdapter ('invalid-host-that-does-not-exist ' , 'default ' , '' , 8123 , false );
428+
429+ $ health = $ adapter ->healthCheck ();
430+
431+ // Assert basic structure
432+ $ this ->assertIsArray ($ health );
433+ $ this ->assertArrayHasKey ('healthy ' , $ health );
434+ $ this ->assertArrayHasKey ('host ' , $ health );
435+
436+ // Assert connection failed
437+ $ this ->assertFalse ($ health ['healthy ' ], 'ClickHouse should be unhealthy with invalid host ' );
438+
439+ // Assert error message is present
440+ $ this ->assertArrayHasKey ('error ' , $ health );
441+ if (isset ($ health ['error ' ])) {
442+ $ this ->assertIsString ($ health ['error ' ]);
443+ $ this ->assertNotEmpty ($ health ['error ' ]);
444+ }
445+
446+ // Assert response time is still recorded
447+ $ this ->assertArrayHasKey ('response_time ' , $ health );
448+ if (isset ($ health ['response_time ' ])) {
449+ $ this ->assertIsFloat ($ health ['response_time ' ]);
450+ }
451+ }
390452}
0 commit comments