@@ -192,11 +192,11 @@ public function test_constructor_sets_default_request_timeout() {
192192 }
193193
194194 /**
195- * Test that the constructor allows overriding the default request timeout.
195+ * Test that the constructor allows overriding the default request timeout with a higher value .
196196 *
197197 * @ticket 64591
198198 */
199- public function test_constructor_allows_overriding_request_timeout () {
199+ public function test_constructor_allows_overriding_request_timeout_with_higher_value () {
200200 add_filter (
201201 'wp_ai_client_default_request_timeout ' ,
202202 static function () {
@@ -213,6 +213,66 @@ static function () {
213213 $ this ->assertEquals ( 45 , $ request_options ->getTimeout () );
214214 }
215215
216+ /**
217+ * Test that the constructor allows overriding the default request timeout with null.
218+ *
219+ * @ticket 65094
220+ */
221+ public function test_constructor_allows_overriding_request_timeout_with_null () {
222+ add_filter ( 'wp_ai_client_default_request_timeout ' , '__return_null ' );
223+
224+ $ builder = new WP_AI_Client_Prompt_Builder ( AiClient::defaultRegistry () );
225+
226+ /** @var RequestOptions $request_options */
227+ $ request_options = $ this ->get_wrapped_prompt_builder_property_value ( $ builder , 'requestOptions ' );
228+
229+ $ this ->assertInstanceOf ( RequestOptions::class, $ request_options );
230+ $ this ->assertNull ( $ request_options ->getTimeout () );
231+ }
232+
233+ /**
234+ * Test that the constructor disallows overriding the default request timeout with a invalid value.
235+ *
236+ * @ticket 65094
237+ *
238+ * @expectedIncorrectUsage WP_AI_Client_Prompt_Builder::__construct
239+ */
240+ public function test_constructor_disallows_overriding_with_negative_request_timeout () {
241+ add_filter (
242+ 'wp_ai_client_default_request_timeout ' ,
243+ static function () {
244+ return -1 ;
245+ }
246+ );
247+
248+ $ builder = new WP_AI_Client_Prompt_Builder ( AiClient::defaultRegistry () );
249+
250+ /** @var RequestOptions $request_options */
251+ $ request_options = $ this ->get_wrapped_prompt_builder_property_value ( $ builder , 'requestOptions ' );
252+
253+ $ this ->assertInstanceOf ( RequestOptions::class, $ request_options );
254+ $ this ->assertEquals ( 30 , $ request_options ->getTimeout () );
255+ }
256+
257+ /**
258+ * Test that the constructor disallows overriding the default request timeout with a invalid value.
259+ *
260+ * @ticket 65094
261+ *
262+ * @expectedIncorrectUsage WP_AI_Client_Prompt_Builder::__construct
263+ */
264+ public function test_constructor_disallows_overriding_with_bad_request_timeout_type () {
265+ add_filter ( 'wp_ai_client_default_request_timeout ' , '__return_empty_array ' );
266+
267+ $ builder = new WP_AI_Client_Prompt_Builder ( AiClient::defaultRegistry () );
268+
269+ /** @var RequestOptions $request_options */
270+ $ request_options = $ this ->get_wrapped_prompt_builder_property_value ( $ builder , 'requestOptions ' );
271+
272+ $ this ->assertInstanceOf ( RequestOptions::class, $ request_options );
273+ $ this ->assertEquals ( 30 , $ request_options ->getTimeout () );
274+ }
275+
216276 /**
217277 * Test method chaining with fluent methods.
218278 *
0 commit comments