Skip to content

Commit 1aa74ce

Browse files
committed
test(OpenAI): augment testing for fake() on Responses API
1 parent 0e66f10 commit 1aa74ce

File tree

3 files changed

+35
-7
lines changed

3 files changed

+35
-7
lines changed

src/Testing/Responses/Concerns/Fakeable.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ private static function buildAttributes(array $original, array $override): array
2929
$new = [];
3030

3131
foreach ($original as $key => $entry) {
32-
$new[$key] = is_array($entry) ?
33-
self::buildAttributes($entry, $override[$key] ?? []) :
34-
$override[$key] ?? $entry;
32+
$new[$key] = is_array($entry)
33+
? self::buildAttributes($entry, $override[$key] ?? [])
34+
: $override[$key] ?? $entry;
3535
unset($override[$key]);
3636
}
3737

tests/Fixtures/Responses.php

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function createResponseResource(): array
1717
'metadata' => [],
1818
'model' => 'gpt-4o-2024-08-06',
1919
'output' => [
20-
outputMessage(),
20+
outputAnnotationMessage(),
2121
outputWebSearchToolCall(),
2222
outputFileSearchToolCall(),
2323
outputComputerToolCall(),
@@ -76,7 +76,7 @@ function retrieveResponseResource(): array
7676
'model' => 'gpt-4o-2024-08-06',
7777
'output' => [
7878
outputWebSearchToolCall(),
79-
outputMessage(),
79+
outputAnnotationMessage(),
8080
],
8181
'parallel_tool_calls' => true,
8282
'previous_response_id' => null,
@@ -247,7 +247,27 @@ function outputReasoning(): array
247247
/**
248248
* @return array<string, mixed>
249249
*/
250-
function outputMessage(): array
250+
function outputBasicMessage(): array
251+
{
252+
return [
253+
'content' => [
254+
[
255+
'annotations' => [],
256+
'text' => 'This is a basic message.',
257+
'type' => 'output_text',
258+
],
259+
],
260+
'id' => 'msg_67ccf190ca3881909d433c50b1f6357e087bb177ab789d5c',
261+
'role' => 'assistant',
262+
'status' => 'completed',
263+
'type' => 'message',
264+
];
265+
}
266+
267+
/**
268+
* @return array<string, mixed>
269+
*/
270+
function outputAnnotationMessage(): array
251271
{
252272
return [
253273
'content' => [

tests/Responses/Responses/CreateResponse.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,18 @@
8181
'id' => 'resp_1234',
8282
'object' => 'custom_response',
8383
'status' => 'failed',
84+
'output' => [
85+
outputBasicMessage(),
86+
],
8487
]);
8588

8689
expect($response)
8790
->id->toBe('resp_1234')
8891
->object->toBe('custom_response')
89-
->status->toBe('failed');
92+
->status->toBe('failed')
93+
->output->toBeArray();
94+
95+
expect($response->output[0]['content'][0])
96+
->type->toBe('output_text')
97+
->text->toBe('This is a basic message.');
9098
});

0 commit comments

Comments
 (0)