Skip to content

Commit ce84f54

Browse files
committed
Add test case for headers with different cases
1 parent ec1dde4 commit ce84f54

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

src/Responses/Meta/MetaInformation.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ private function __construct(
2929
public static function from(array $headers): self
3030
{
3131
$headers = array_change_key_case($headers, CASE_LOWER);
32+
3233
$requestId = $headers['x-request-id'][0] ?? null;
3334

3435
$openai = MetaInformationOpenAI::from([

tests/Fixtures/Meta.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,17 @@ function metaHeadersFromAzure(): array
3030
];
3131
}
3232

33+
function metaHeadersWithDifferentCases(): array
34+
{
35+
return [
36+
'Openai-Model' => ['gpt-3.5-turbo-instruct'],
37+
'OPENAI-ORGANIZATION' => ['org-1234'],
38+
'openai-processing-ms' => [410],
39+
'openai-version' => ['2020-10-01'],
40+
'x-request-id' => ['3813fa4fa3f17bdf0d7654f0f49ebab4'],
41+
];
42+
}
43+
3344
function meta(): MetaInformation
3445
{
3546
return MetaInformation::from(metaHeaders());

tests/Responses/Meta/MetaInformation.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,21 @@
8282
->openai->processingMs->toBeNull();
8383
});
8484

85+
test('from response headers in different cases', function () {
86+
$meta = MetaInformation::from((new \GuzzleHttp\Psr7\Response(headers: metaHeadersWithDifferentCases()))->getHeaders());
87+
88+
expect($meta)
89+
->toBeInstanceOf(MetaInformation::class)
90+
->requestId->toBe('3813fa4fa3f17bdf0d7654f0f49ebab4')
91+
->openai->toBeInstanceOf(MetaInformationOpenAI::class)
92+
->openai->model->toBe('gpt-3.5-turbo-instruct')
93+
->openai->organization->toBe('org-1234')
94+
->openai->version->toBe('2020-10-01')
95+
->openai->processingMs->toBe(410)
96+
->requestLimit->toBeNull()
97+
->tokenLimit->toBeNull();
98+
});
99+
85100
test('as array accessible', function () {
86101
$meta = MetaInformation::from(metaHeaders());
87102

0 commit comments

Comments
 (0)