Skip to content

ClientFake does not support testing startChat() + sendMessage() flow #172

@saskia78-byte

Description

@saskia78-byte

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions