Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions src/platform/tests/Bridge/Gemini/Gemini/ResultConverterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\AI\Platform\Tests\Bridge\Gemini\Gemini;

use PHPUnit\Framework\TestCase;
use Symfony\AI\Platform\Bridge\Gemini\Gemini\ResultConverter;
use Symfony\AI\Platform\Exception\RuntimeException;
use Symfony\AI\Platform\Result\RawHttpResult;
use Symfony\Contracts\HttpClient\ResponseInterface;

/**
* @author Oskar Stark <oskar@php.com>
*/
final class ResultConverterTest extends TestCase
{
public function testConvertThrowsExceptionWithDetailedErrorInformation()
{
$converter = new ResultConverter();
$httpResponse = self::createMock(ResponseInterface::class);
$httpResponse->method('getStatusCode')->willReturn(400);
$httpResponse->method('toArray')->willReturn([
'error' => [
'code' => 400,
'status' => 'INVALID_ARGUMENT',
'message' => 'Invalid request: The model does not support this feature.',
],
]);

$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('Error "400" - "INVALID_ARGUMENT": "Invalid request: The model does not support this feature.".');

$converter->convert(new RawHttpResult($httpResponse));
}
}
19 changes: 19 additions & 0 deletions src/platform/tests/Bridge/OpenAi/Gpt/ResultConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,4 +226,23 @@ public function testThrowsBadRequestExceptionOnBadRequestResponseWithNoResponseB

$converter->convert(new RawHttpResult($httpResponse));
}

public function testThrowsDetailedErrorException()
{
$converter = new ResultConverter();
$httpResponse = self::createMock(ResponseInterface::class);
$httpResponse->method('toArray')->willReturn([
'error' => [
'code' => 'invalid_request_error',
'type' => 'invalid_request',
'param' => 'model',
'message' => 'The model `gpt-5` does not exist',
],
]);

$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('Error "invalid_request_error"-invalid_request (model): "The model `gpt-5` does not exist".');

$converter->convert(new RawHttpResult($httpResponse));
}
}