@@ -449,4 +449,94 @@ public function testHealthCheckFailure(): void
449449 $ this ->assertIsFloat ($ health ['response_time ' ]);
450450 }
451451 }
452+
453+ /**
454+ * Test setTimeout() method with valid timeout
455+ */
456+ public function testSetTimeoutValid (): void
457+ {
458+ $ host = getenv ('CLICKHOUSE_HOST ' ) ?: 'clickhouse ' ;
459+ $ username = getenv ('CLICKHOUSE_USER ' ) ?: 'default ' ;
460+ $ password = getenv ('CLICKHOUSE_PASSWORD ' ) ?: 'clickhouse ' ;
461+ $ port = (int ) (getenv ('CLICKHOUSE_PORT ' ) ?: 8123 );
462+ $ secure = (bool ) (getenv ('CLICKHOUSE_SECURE ' ) ?: false );
463+
464+ $ adapter = new ClickHouseAdapter ($ host , $ username , $ password , $ port , $ secure );
465+
466+ // Test setting valid timeout
467+ $ result = $ adapter ->setTimeout (5000 ); // 5 seconds
468+
469+ // Should return self for chaining
470+ $ this ->assertInstanceOf (ClickHouseAdapter::class, $ result );
471+
472+ // Test that it still works after setting timeout
473+ $ health = $ adapter ->healthCheck ();
474+ $ this ->assertTrue ($ health ['healthy ' ]);
475+ }
476+
477+ /**
478+ * Test setTimeout() with minimum timeout (1 second)
479+ */
480+ public function testSetTimeoutMinimum (): void
481+ {
482+ $ host = getenv ('CLICKHOUSE_HOST ' ) ?: 'clickhouse ' ;
483+ $ username = getenv ('CLICKHOUSE_USER ' ) ?: 'default ' ;
484+ $ password = getenv ('CLICKHOUSE_PASSWORD ' ) ?: 'clickhouse ' ;
485+ $ port = (int ) (getenv ('CLICKHOUSE_PORT ' ) ?: 8123 );
486+
487+ $ adapter = new ClickHouseAdapter ($ host , $ username , $ password , $ port );
488+ $ adapter ->setTimeout (1000 ); // 1 second minimum
489+
490+ $ this ->assertTrue (true ); // If we reach here, no exception was thrown
491+ }
492+
493+ /**
494+ * Test setTimeout() with maximum timeout (10 minutes)
495+ */
496+ public function testSetTimeoutMaximum (): void
497+ {
498+ $ host = getenv ('CLICKHOUSE_HOST ' ) ?: 'clickhouse ' ;
499+ $ username = getenv ('CLICKHOUSE_USER ' ) ?: 'default ' ;
500+ $ password = getenv ('CLICKHOUSE_PASSWORD ' ) ?: 'clickhouse ' ;
501+ $ port = (int ) (getenv ('CLICKHOUSE_PORT ' ) ?: 8123 );
502+
503+ $ adapter = new ClickHouseAdapter ($ host , $ username , $ password , $ port );
504+ $ adapter ->setTimeout (600000 ); // 10 minutes maximum
505+
506+ $ this ->assertTrue (true ); // If we reach here, no exception was thrown
507+ }
508+
509+ /**
510+ * Test setTimeout() with timeout below minimum
511+ */
512+ public function testSetTimeoutBelowMinimum (): void
513+ {
514+ $ this ->expectException (\Exception::class);
515+ $ this ->expectExceptionMessage ('Timeout must be at least 1000 milliseconds ' );
516+
517+ $ host = getenv ('CLICKHOUSE_HOST ' ) ?: 'clickhouse ' ;
518+ $ username = getenv ('CLICKHOUSE_USER ' ) ?: 'default ' ;
519+ $ password = getenv ('CLICKHOUSE_PASSWORD ' ) ?: 'clickhouse ' ;
520+ $ port = (int ) (getenv ('CLICKHOUSE_PORT ' ) ?: 8123 );
521+
522+ $ adapter = new ClickHouseAdapter ($ host , $ username , $ password , $ port );
523+ $ adapter ->setTimeout (999 ); // Below minimum
524+ }
525+
526+ /**
527+ * Test setTimeout() with timeout above maximum
528+ */
529+ public function testSetTimeoutAboveMaximum (): void
530+ {
531+ $ this ->expectException (\Exception::class);
532+ $ this ->expectExceptionMessage ('Timeout cannot exceed 600000 milliseconds ' );
533+
534+ $ host = getenv ('CLICKHOUSE_HOST ' ) ?: 'clickhouse ' ;
535+ $ username = getenv ('CLICKHOUSE_USER ' ) ?: 'default ' ;
536+ $ password = getenv ('CLICKHOUSE_PASSWORD ' ) ?: 'clickhouse ' ;
537+ $ port = (int ) (getenv ('CLICKHOUSE_PORT ' ) ?: 8123 );
538+
539+ $ adapter = new ClickHouseAdapter ($ host , $ username , $ password , $ port );
540+ $ adapter ->setTimeout (600001 ); // Above maximum
541+ }
452542}
0 commit comments