- Timestamp:
- 04/22/2026 06:13:47 PM (3 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/ai-client/wpAiClientPromptBuilder.php
r62248 r62255 193 193 194 194 /** 195 * Test that the constructor allows overriding the default request timeout. 196 * 197 * @ticket 64591 198 */ 199 public function test_constructor_allows_overriding_request_timeout() { 195 * Test that the constructor allows overriding the default request timeout with a valid value. 196 * 197 * @ticket 64591 198 * @ticket 65094 199 * 200 * @dataProvider data_valid_request_timeout_overrides 201 * 202 * @param mixed $input The timeout value returned by the filter. 203 * @param float $expected The expected timeout stored on the request options. 204 */ 205 public function test_constructor_allows_overriding_request_timeout_with_valid_timeout( $input, float $expected ) { 200 206 add_filter( 201 207 'wp_ai_client_default_request_timeout', 202 static function () {203 return 45;208 static function () use ( $input ) { 209 return $input; 204 210 } 205 211 ); … … 211 217 212 218 $this->assertInstanceOf( RequestOptions::class, $request_options ); 213 $this->assertSame( 45.0, $request_options->getTimeout() ); 219 $this->assertSame( $expected, $request_options->getTimeout() ); 220 } 221 222 /** 223 * Data provider for {@see self::test_constructor_allows_overriding_request_timeout_with_valid_timeout()}. 224 * 225 * @return array<string, array{0: mixed, 1: float}> 226 */ 227 public function data_valid_request_timeout_overrides(): array { 228 return array( 229 'float' => array( 45.5, 45.5 ), 230 'integer' => array( 67, 67.0 ), 231 'string' => array( '20', 20.0 ), 232 'infinity' => array( INF, INF ), 233 'zero' => array( 0.0, 0.0 ), 234 ); 235 } 236 237 /** 238 * Test that the constructor disallows overriding the default request timeout with an invalid value. 239 * 240 * @ticket 65094 241 * 242 * @dataProvider data_invalid_request_timeouts 243 * 244 * @expectedIncorrectUsage WP_AI_Client_Prompt_Builder::__construct 245 * 246 * @param mixed $timeout The invalid timeout value returned by the filter. 247 */ 248 public function test_constructor_disallows_overriding_with_invalid_request_timeout( $timeout ) { 249 add_filter( 250 'wp_ai_client_default_request_timeout', 251 static function () use ( $timeout ) { 252 return $timeout; 253 } 254 ); 255 256 $builder = new WP_AI_Client_Prompt_Builder( AiClient::defaultRegistry() ); 257 258 /** @var RequestOptions $request_options */ 259 $request_options = $this->get_wrapped_prompt_builder_property_value( $builder, 'requestOptions' ); 260 261 $this->assertInstanceOf( RequestOptions::class, $request_options ); 262 $this->assertSame( 30.0, $request_options->getTimeout() ); 263 } 264 265 /** 266 * Data provider for {@see self::test_constructor_disallows_overriding_with_invalid_request_timeout()}. 267 * 268 * @return array<string, array{0: mixed}> 269 */ 270 public function data_invalid_request_timeouts(): array { 271 return array( 272 'negative number' => array( -1 ), 273 'array' => array( array() ), 274 'null' => array( null ), 275 ); 214 276 } 215 277
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)