Skip to content

test(OpenAI): augment testing for fake() on Responses API #593

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 3, 2025
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
6 changes: 3 additions & 3 deletions src/Testing/Responses/Concerns/Fakeable.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ private static function buildAttributes(array $original, array $override): array
$new = [];

foreach ($original as $key => $entry) {
$new[$key] = is_array($entry) ?
self::buildAttributes($entry, $override[$key] ?? []) :
$override[$key] ?? $entry;
$new[$key] = is_array($entry)
? self::buildAttributes($entry, $override[$key] ?? [])
: $override[$key] ?? $entry;
unset($override[$key]);
}

Expand Down
26 changes: 23 additions & 3 deletions tests/Fixtures/Responses.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function createResponseResource(): array
'metadata' => [],
'model' => 'gpt-4o-2024-08-06',
'output' => [
outputMessage(),
outputAnnotationMessage(),
outputWebSearchToolCall(),
outputFileSearchToolCall(),
outputComputerToolCall(),
Expand Down Expand Up @@ -77,7 +77,7 @@ function retrieveResponseResource(): array
'model' => 'gpt-4o-2024-08-06',
'output' => [
outputWebSearchToolCall(),
outputMessage(),
outputAnnotationMessage(),
],
'parallel_tool_calls' => true,
'previous_response_id' => null,
Expand Down Expand Up @@ -249,7 +249,27 @@ function outputReasoning(): array
/**
* @return array<string, mixed>
*/
function outputMessage(): array
function outputBasicMessage(): array
{
return [
'content' => [
[
'annotations' => [],
'text' => 'This is a basic message.',
'type' => 'output_text',
],
],
'id' => 'msg_67ccf190ca3881909d433c50b1f6357e087bb177ab789d5c',
'role' => 'assistant',
'status' => 'completed',
'type' => 'message',
];
}

/**
* @return array<string, mixed>
*/
function outputAnnotationMessage(): array
{
return [
'content' => [
Expand Down
10 changes: 9 additions & 1 deletion tests/Responses/Responses/CreateResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,18 @@
'id' => 'resp_1234',
'object' => 'custom_response',
'status' => 'failed',
'output' => [
outputBasicMessage(),
],
]);

expect($response)
->id->toBe('resp_1234')
->object->toBe('custom_response')
->status->toBe('failed');
->status->toBe('failed')
->output->toBeArray();

expect($response->output[0]['content'][0])
->type->toBe('output_text')
->text->toBe('This is a basic message.');
});