|
14 | 14 | use PHPUnit\Framework\TestCase;
|
15 | 15 | use Symfony\AI\Platform\Bridge\OpenAi\Gpt\ResultConverter;
|
16 | 16 | use Symfony\AI\Platform\Exception\AuthenticationException;
|
| 17 | +use Symfony\AI\Platform\Exception\BadRequestException; |
17 | 18 | use Symfony\AI\Platform\Exception\ContentFilterException;
|
18 | 19 | use Symfony\AI\Platform\Exception\RuntimeException;
|
19 | 20 | use Symfony\AI\Platform\Result\ChoiceResult;
|
@@ -196,4 +197,33 @@ public function testThrowsExceptionForUnsupportedFinishReason()
|
196 | 197 |
|
197 | 198 | $converter->convert(new RawHttpResult($httpResponse));
|
198 | 199 | }
|
| 200 | + |
| 201 | + public function testThrowsBadRequestExceptionOnBadRequestResponse() |
| 202 | + { |
| 203 | + $converter = new ResultConverter(); |
| 204 | + $httpResponse = self::createMock(ResponseInterface::class); |
| 205 | + $httpResponse->method('getStatusCode')->willReturn(400); |
| 206 | + $httpResponse->method('getContent')->willReturn(json_encode([ |
| 207 | + 'error' => [ |
| 208 | + 'message' => 'Bad Request: invalid parameters', |
| 209 | + ], |
| 210 | + ])); |
| 211 | + |
| 212 | + $this->expectException(BadRequestException::class); |
| 213 | + $this->expectExceptionMessage('Bad Request: invalid parameters'); |
| 214 | + |
| 215 | + $converter->convert(new RawHttpResult($httpResponse)); |
| 216 | + } |
| 217 | + |
| 218 | + public function testThrowsBadRequestExceptionOnBadRequestResponseWithNoResponseBody() |
| 219 | + { |
| 220 | + $converter = new ResultConverter(); |
| 221 | + $httpResponse = self::createMock(ResponseInterface::class); |
| 222 | + $httpResponse->method('getStatusCode')->willReturn(400); |
| 223 | + |
| 224 | + $this->expectException(BadRequestException::class); |
| 225 | + $this->expectExceptionMessage('Bad Request'); |
| 226 | + |
| 227 | + $converter->convert(new RawHttpResult($httpResponse)); |
| 228 | + } |
199 | 229 | }
|
0 commit comments