```
✨ feat(revervation): [Ajoute la création de session de réservation et le flow] 🐛 fix(PurgeCommandTest): [Utilise addCommand au lieu de add pour les commandes] 📝 chore(deps): [Mise à jour des dépendances Composer et corrections] 🐛 fix(KeycloakAuthenticator): [Corrige le type nullable de l'exception start] ✨ feat(Customer): [Ajoute les sessions de commandes aux entités Customer] ♻️ refactor(AppLogger): [Refactorise l'AppLogger pour obtenir l'UserAgent] ✨ feat(FlowReserve): [Ajoute une action de validation du panier] ```
This commit is contained in:
60
tests/Service/AI/GeminiClientTest.php
Normal file
60
tests/Service/AI/GeminiClientTest.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Tests\Service\AI;
|
||||
|
||||
use App\Service\AI\GeminiClient;
|
||||
use GeminiAPI\Client;
|
||||
use GeminiAPI\GenerativeModel;
|
||||
use GeminiAPI\Resources\Parts\TextPart;
|
||||
use GeminiAPI\Responses\GenerateContentResponse;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class GeminiClientTest extends TestCase
|
||||
{
|
||||
public function testGenerateFriendlyMessageSuccess(): void
|
||||
{
|
||||
// Mock the response
|
||||
$responseMock = $this->createStub(GenerateContentResponse::class);
|
||||
$responseMock->method('text')
|
||||
->willReturn('This is a friendly update.');
|
||||
|
||||
// Mock the model
|
||||
$modelMock = $this->createMock(GenerativeModel::class);
|
||||
$modelMock->expects($this->once())
|
||||
->method('generateContent')
|
||||
->with($this->isInstanceOf(TextPart::class))
|
||||
->willReturn($responseMock);
|
||||
|
||||
// Mock the client
|
||||
$clientMock = $this->createMock(Client::class);
|
||||
$clientMock->expects($this->once())
|
||||
->method('withV1BetaVersion')
|
||||
->willReturnSelf();
|
||||
$clientMock->expects($this->once())
|
||||
->method('generativeModel')
|
||||
->with('gemini-3-pro-preview')
|
||||
->willReturn($modelMock);
|
||||
|
||||
// Instantiate GeminiClient with mocked Client
|
||||
$geminiClient = new GeminiClient('fake-api-key', $clientMock);
|
||||
|
||||
$result = $geminiClient->generateFriendlyMessage('Raw technical message');
|
||||
|
||||
$this->assertEquals('This is a friendly update.', $result);
|
||||
}
|
||||
|
||||
public function testGenerateFriendlyMessageException(): void
|
||||
{
|
||||
// Mock the client to throw an exception
|
||||
$clientMock = $this->createStub(Client::class);
|
||||
$clientMock->method('withV1BetaVersion')
|
||||
->willThrowException(new \Exception('API Error'));
|
||||
|
||||
// Instantiate GeminiClient with mocked Client
|
||||
$geminiClient = new GeminiClient('fake-api-key', $clientMock);
|
||||
|
||||
$result = $geminiClient->generateFriendlyMessage('Raw technical message');
|
||||
|
||||
$this->assertNull($result);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user