From fdef71cb86899a9995cc07861696abd86f251dcc Mon Sep 17 00:00:00 2001 From: gehrisandro Date: Fri, 26 Jan 2024 08:33:51 +0100 Subject: [PATCH] add test, update doc blocks, lint --- src/Resources/Files.php | 4 ++-- src/Responses/Files/ListResponse.php | 6 +++--- src/Responses/Files/RetrieveResponse.php | 8 ++++---- tests/Responses/Files/RetrieveResponse.php | 17 +++++++++++++++++ 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/Resources/Files.php b/src/Resources/Files.php index b5c53cce..6f5490e1 100644 --- a/src/Resources/Files.php +++ b/src/Resources/Files.php @@ -25,7 +25,7 @@ public function list(): ListResponse { $payload = Payload::list('files'); - /** @var Response|string|null}>}> $response */ + /** @var Response|string|null}>}> $response */ $response = $this->transporter->requestObject($payload); return ListResponse::from($response->data(), $response->meta()); @@ -40,7 +40,7 @@ public function retrieve(string $file): RetrieveResponse { $payload = Payload::retrieve('files', $file); - /** @var Response|string|null}> $response */ + /** @var Response|string|null}> $response */ $response = $this->transporter->requestObject($payload); return RetrieveResponse::from($response->data(), $response->meta()); diff --git a/src/Responses/Files/ListResponse.php b/src/Responses/Files/ListResponse.php index e23a735c..8efe084b 100644 --- a/src/Responses/Files/ListResponse.php +++ b/src/Responses/Files/ListResponse.php @@ -12,12 +12,12 @@ use OpenAI\Testing\Responses\Concerns\Fakeable; /** - * @implements ResponseContract|string|null}>}> + * @implements ResponseContract|string|null}>}> */ final class ListResponse implements ResponseContract, ResponseHasMetaInformationContract { /** - * @use ArrayAccessible|string|null}>}> + * @use ArrayAccessible|string|null}>}> */ use ArrayAccessible; @@ -37,7 +37,7 @@ private function __construct( /** * Acts as static factory, and returns a new Response instance. * - * @param array{object: string, data: array|string|null}>} $attributes + * @param array{object: string, data: array|string|null}>} $attributes */ public static function from(array $attributes, MetaInformation $meta): self { diff --git a/src/Responses/Files/RetrieveResponse.php b/src/Responses/Files/RetrieveResponse.php index 7636ca2d..66ab865d 100644 --- a/src/Responses/Files/RetrieveResponse.php +++ b/src/Responses/Files/RetrieveResponse.php @@ -12,12 +12,12 @@ use OpenAI\Testing\Responses\Concerns\Fakeable; /** - * @implements ResponseContract|string|null}> + * @implements ResponseContract|string|null}> */ final class RetrieveResponse implements ResponseContract, ResponseHasMetaInformationContract { /** - * @use ArrayAccessible|string|null}> + * @use ArrayAccessible|string|null}> */ use ArrayAccessible; @@ -30,7 +30,7 @@ final class RetrieveResponse implements ResponseContract, ResponseHasMetaInforma private function __construct( public readonly string $id, public readonly string $object, - public readonly int|null $bytes, + public readonly ?int $bytes, public readonly int $createdAt, public readonly string $filename, public readonly string $purpose, @@ -43,7 +43,7 @@ private function __construct( /** * Acts as static factory, and returns a new Response instance. * - * @param array{id: string, object: string, created_at: int, bytes: int, filename: string, purpose: string, status: string, status_details: array|string|null} $attributes + * @param array{id: string, object: string, created_at: int, bytes: ?int, filename: string, purpose: string, status: string, status_details: array|string|null} $attributes */ public static function from(array $attributes, MetaInformation $meta): self { diff --git a/tests/Responses/Files/RetrieveResponse.php b/tests/Responses/Files/RetrieveResponse.php index 3ca32c03..e678e9f1 100644 --- a/tests/Responses/Files/RetrieveResponse.php +++ b/tests/Responses/Files/RetrieveResponse.php @@ -33,6 +33,23 @@ ->meta()->toBeInstanceOf(MetaInformation::class); }); +test('from with byte is null', function () { + $data = fileResource(); + $data['bytes'] = null; + + $result = RetrieveResponse::from($data, meta()); + + expect($result) + ->toBeInstanceOf(RetrieveResponse::class) + ->id->toBe('file-XjGxS3KTG0uNmNOK362iJua3') + ->object->toBe('file') + ->bytes->toBeNull() + ->createdAt->toBe(1613779121) + ->filename->toBe('mydata.jsonl') + ->purpose->toBe('fine-tune') + ->meta()->toBeInstanceOf(MetaInformation::class); +}); + test('as array accessible', function () { $result = RetrieveResponse::from(fileResource(), meta());