Skip to content
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
4 changes: 2 additions & 2 deletions src/Responses/Responses/Output/OutputMcpCall.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ public static function from(array $attributes): self
type: $attributes['type'],
arguments: $attributes['arguments'],
name: $attributes['name'],
approvalRequestId: $attributes['approval_request_id'],
approvalRequestId: $attributes['approval_request_id'] ?? null,
error: $errorType,
output: $attributes['output'],
output: $attributes['output'] ?? null,
);
}

Expand Down
6 changes: 3 additions & 3 deletions src/Responses/Responses/Tool/WebSearchUserLocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ public static function from(array $attributes): self
{
return new self(
type: $attributes['type'],
city: $attributes['city'],
city: $attributes['city'] ?? null,
country: $attributes['country'],
region: $attributes['region'],
timezone: $attributes['timezone'],
region: $attributes['region'] ?? null,
timezone: $attributes['timezone'] ?? null,
);
}

Expand Down
19 changes: 19 additions & 0 deletions tests/Responses/Responses/Output/OutputMcpCall.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,25 @@
->output->toBeNull();
});

test('from without optional keys', function () {
$attributes = outputMcpCall();

unset($attributes['approval_request_id'], $attributes['output']);

set_error_handler(static fn (int $errno, string $errstr): bool => throw new ErrorException($errstr), E_WARNING);

try {
$response = OutputMcpCall::from($attributes);
} finally {
restore_error_handler();
}

expect($response)
->toBeInstanceOf(OutputMcpCall::class)
->approvalRequestId->toBeNull()
->output->toBeNull();
});

test('from error as http object', function () {
$response = OutputMcpCall::from(outputMcpErrorCallObject());

Expand Down
42 changes: 42 additions & 0 deletions tests/Responses/Responses/Tool/WebSearchUserLocation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

use OpenAI\Responses\Responses\Tool\WebSearchUserLocation;

test('from', function () {
$response = WebSearchUserLocation::from([
'type' => 'approximate',
'city' => 'San Francisco',
'country' => 'US',
'region' => 'California',
'timezone' => 'America/Los_Angeles',
]);

expect($response)
->toBeInstanceOf(WebSearchUserLocation::class)
->type->toBe('approximate')
->city->toBe('San Francisco')
->country->toBe('US')
->region->toBe('California')
->timezone->toBe('America/Los_Angeles');
});

test('from without optional keys', function () {
set_error_handler(static fn (int $errno, string $errstr): bool => throw new ErrorException($errstr), E_WARNING);

try {
$response = WebSearchUserLocation::from([
'type' => 'approximate',
'country' => 'US',
]);
} finally {
restore_error_handler();
}

expect($response)
->toBeInstanceOf(WebSearchUserLocation::class)
->type->toBe('approximate')
->country->toBe('US')
->city->toBeNull()
->region->toBeNull()
->timezone->toBeNull();
});