|
29 | 29 | use WordPress\AiClient\Providers\DTO\ProviderMetadata; |
30 | 30 | use WordPress\AiClient\Providers\DTO\ProviderModelsMetadata; |
31 | 31 | use WordPress\AiClient\Providers\Enums\ProviderTypeEnum; |
| 32 | +use WordPress\AiClient\Providers\Http\DTO\RequestOptions; |
32 | 33 | use WordPress\AiClient\Providers\Models\Contracts\ModelInterface; |
33 | 34 | use WordPress\AiClient\Providers\Models\DTO\ModelConfig; |
34 | 35 | use WordPress\AiClient\Providers\Models\DTO\ModelMetadata; |
@@ -139,6 +140,39 @@ public function test_instantiation_with_prompt(): void { |
139 | 140 | $this->assertInstanceOf( Prompt_Builder::class, $prompt_builder ); |
140 | 141 | } |
141 | 142 |
|
| 143 | + /** |
| 144 | + * Test that the constructor sets the default request timeout. |
| 145 | + */ |
| 146 | + public function test_constructor_sets_default_request_timeout(): void { |
| 147 | + $builder = new Prompt_Builder( AiClient::defaultRegistry() ); |
| 148 | + |
| 149 | + /** @var RequestOptions $request_options */ |
| 150 | + $request_options = $this->get_wrapped_prompt_builder_property_value( $builder, 'requestOptions' ); |
| 151 | + |
| 152 | + $this->assertInstanceOf( RequestOptions::class, $request_options ); |
| 153 | + $this->assertEquals( 30, $request_options->getTimeout() ); |
| 154 | + } |
| 155 | + |
| 156 | + /** |
| 157 | + * Test that the constructor allows overriding the default request timeout. |
| 158 | + */ |
| 159 | + public function test_constructor_allows_overriding_request_timeout(): void { |
| 160 | + add_filter( |
| 161 | + 'wp_ai_client_default_request_timeout', |
| 162 | + static function () { |
| 163 | + return 45; |
| 164 | + } |
| 165 | + ); |
| 166 | + |
| 167 | + $builder = new Prompt_Builder( AiClient::defaultRegistry() ); |
| 168 | + |
| 169 | + /** @var RequestOptions $request_options */ |
| 170 | + $request_options = $this->get_wrapped_prompt_builder_property_value( $builder, 'requestOptions' ); |
| 171 | + |
| 172 | + $this->assertInstanceOf( RequestOptions::class, $request_options ); |
| 173 | + $this->assertEquals( 45, $request_options->getTimeout() ); |
| 174 | + } |
| 175 | + |
142 | 176 | /** |
143 | 177 | * Test method chaining with fluent methods. |
144 | 178 | * |
|
0 commit comments