File tree Expand file tree Collapse file tree 2 files changed +62
-0
lines changed
src/platform/tests/Bridge Expand file tree Collapse file tree 2 files changed +62
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ /*
4
+ * This file is part of the Symfony package.
5
+ *
6
+ * (c) Fabien Potencier <[email protected] >
7
+ *
8
+ * For the full copyright and license information, please view the LICENSE
9
+ * file that was distributed with this source code.
10
+ */
11
+
12
+ namespace Symfony \AI \Platform \Tests \Bridge \Gemini \Gemini ;
13
+
14
+ use PHPUnit \Framework \TestCase ;
15
+ use Symfony \AI \Platform \Bridge \Gemini \Gemini \ResultConverter ;
16
+ use Symfony \AI \Platform \Exception \RuntimeException ;
17
+ use Symfony \AI \Platform \Result \RawHttpResult ;
18
+ use Symfony \Contracts \HttpClient \ResponseInterface ;
19
+
20
+ /**
21
+ * @author Oskar Stark <[email protected] >
22
+ */
23
+ final class ResultConverterTest extends TestCase
24
+ {
25
+ public function testConvertThrowsExceptionWithDetailedErrorInformation ()
26
+ {
27
+ $ converter = new ResultConverter ();
28
+ $ httpResponse = self ::createMock (ResponseInterface::class);
29
+ $ httpResponse ->method ('getStatusCode ' )->willReturn (400 );
30
+ $ httpResponse ->method ('toArray ' )->willReturn ([
31
+ 'error ' => [
32
+ 'code ' => 400 ,
33
+ 'status ' => 'INVALID_ARGUMENT ' ,
34
+ 'message ' => 'Invalid request: The model does not support this feature. ' ,
35
+ ],
36
+ ]);
37
+
38
+ $ this ->expectException (RuntimeException::class);
39
+ $ this ->expectExceptionMessage ('Error "400" - "INVALID_ARGUMENT": "Invalid request: The model does not support this feature.". ' );
40
+
41
+ $ converter ->convert (new RawHttpResult ($ httpResponse ));
42
+ }
43
+ }
Original file line number Diff line number Diff line change @@ -226,4 +226,23 @@ public function testThrowsBadRequestExceptionOnBadRequestResponseWithNoResponseB
226
226
227
227
$ converter ->convert (new RawHttpResult ($ httpResponse ));
228
228
}
229
+
230
+ public function testThrowsDetailedErrorException ()
231
+ {
232
+ $ converter = new ResultConverter ();
233
+ $ httpResponse = self ::createMock (ResponseInterface::class);
234
+ $ httpResponse ->method ('toArray ' )->willReturn ([
235
+ 'error ' => [
236
+ 'code ' => 'invalid_request_error ' ,
237
+ 'type ' => 'invalid_request ' ,
238
+ 'param ' => 'model ' ,
239
+ 'message ' => 'The model `gpt-5` does not exist ' ,
240
+ ],
241
+ ]);
242
+
243
+ $ this ->expectException (RuntimeException::class);
244
+ $ this ->expectExceptionMessage ('Error "invalid_request_error"-invalid_request (model): "The model `gpt-5` does not exist". ' );
245
+
246
+ $ converter ->convert (new RawHttpResult ($ httpResponse ));
247
+ }
229
248
}
You can’t perform that action at this time.
0 commit comments