Description
When using ClientFake to test code that uses startChat() followed by sendMessage(),
a TypeError is thrown because GenerativeModelTestResource::startChat() has a return
type of ChatSession (a final class), but ClientFake tries to return a
GenerateContentResponse from its response queue instead of a ChatSession.
Steps to reproduce
$fakeGeminiClient = new ClientFake([
GenerateContentResponse::fake(),
]);
$chat = $fakeGeminiClient
->generativeModel('gemini-2.5-flash')
->startChat();
$response = $chat->sendMessage('Hello');
Error
Gemini\Testing\Resources\GenerativeModelTestResource::startChat():
Return value must be of type Gemini\Resources\ChatSession,
Gemini\Responses\GenerativeModel\GenerateContentResponse returned
Expected behavior
ClientFake should support testing the full startChat() + sendMessage() flow,
not only generateContent().
Environment
- PHP 8.3.28
- google-gemini-php/client (latest)
- PHPUnit 12.5.8
- Symfony 6.4
Description
When using
ClientFaketo test code that usesstartChat()followed bysendMessage(),a
TypeErroris thrown becauseGenerativeModelTestResource::startChat()has a returntype of
ChatSession(afinalclass), butClientFaketries to return aGenerateContentResponsefrom its response queue instead of aChatSession.Steps to reproduce
Error
Gemini\Testing\Resources\GenerativeModelTestResource::startChat():
Return value must be of type Gemini\Resources\ChatSession,
Gemini\Responses\GenerativeModel\GenerateContentResponse returned
Expected behavior
ClientFakeshould support testing the fullstartChat()+sendMessage()flow,not only
generateContent().Environment