From 1aa74ce8eefd01262f49e3889b9f36996e50df2e Mon Sep 17 00:00:00 2001 From: Connor Tumbleson Date: Mon, 2 Jun 2025 16:35:53 -0400 Subject: [PATCH] test(OpenAI): augment testing for fake() on Responses API --- src/Testing/Responses/Concerns/Fakeable.php | 6 ++--- tests/Fixtures/Responses.php | 26 +++++++++++++++++--- tests/Responses/Responses/CreateResponse.php | 10 +++++++- 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/src/Testing/Responses/Concerns/Fakeable.php b/src/Testing/Responses/Concerns/Fakeable.php index ca55e3ef..1ea2f53b 100644 --- a/src/Testing/Responses/Concerns/Fakeable.php +++ b/src/Testing/Responses/Concerns/Fakeable.php @@ -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]); } diff --git a/tests/Fixtures/Responses.php b/tests/Fixtures/Responses.php index 8a904ae9..74bfa8f5 100644 --- a/tests/Fixtures/Responses.php +++ b/tests/Fixtures/Responses.php @@ -17,7 +17,7 @@ function createResponseResource(): array 'metadata' => [], 'model' => 'gpt-4o-2024-08-06', 'output' => [ - outputMessage(), + outputAnnotationMessage(), outputWebSearchToolCall(), outputFileSearchToolCall(), outputComputerToolCall(), @@ -76,7 +76,7 @@ function retrieveResponseResource(): array 'model' => 'gpt-4o-2024-08-06', 'output' => [ outputWebSearchToolCall(), - outputMessage(), + outputAnnotationMessage(), ], 'parallel_tool_calls' => true, 'previous_response_id' => null, @@ -247,7 +247,27 @@ function outputReasoning(): array /** * @return array */ -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 + */ +function outputAnnotationMessage(): array { return [ 'content' => [ diff --git a/tests/Responses/Responses/CreateResponse.php b/tests/Responses/Responses/CreateResponse.php index 121696f2..4e52f82a 100644 --- a/tests/Responses/Responses/CreateResponse.php +++ b/tests/Responses/Responses/CreateResponse.php @@ -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.'); });