Skip to content

Commit

Permalink
add test, update doc blocks, lint
Browse files Browse the repository at this point in the history
  • Loading branch information
gehrisandro committed Jan 26, 2024
1 parent 8db06dc commit fdef71c
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/Resources/Files.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function list(): ListResponse
{
$payload = Payload::list('files');

/** @var Response<array{object: string, data: array<int, array{id: string, object: string, created_at: int, bytes: int, filename: string, purpose: string, status: string, status_details: array<array-key, mixed>|string|null}>}> $response */
/** @var Response<array{object: string, data: array<int, array{id: string, object: string, created_at: int, bytes: ?int, filename: string, purpose: string, status: string, status_details: array<array-key, mixed>|string|null}>}> $response */
$response = $this->transporter->requestObject($payload);

return ListResponse::from($response->data(), $response->meta());
Expand All @@ -40,7 +40,7 @@ public function retrieve(string $file): RetrieveResponse
{
$payload = Payload::retrieve('files', $file);

/** @var Response<array{id: string, object: string, created_at: int, bytes: int, filename: string, purpose: string, status: string, status_details: array<array-key, mixed>|string|null}> $response */
/** @var Response<array{id: string, object: string, created_at: int, bytes: ?int, filename: string, purpose: string, status: string, status_details: array<array-key, mixed>|string|null}> $response */
$response = $this->transporter->requestObject($payload);

return RetrieveResponse::from($response->data(), $response->meta());
Expand Down
6 changes: 3 additions & 3 deletions src/Responses/Files/ListResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
use OpenAI\Testing\Responses\Concerns\Fakeable;

/**
* @implements ResponseContract<array{object: string, data: array<int, array{id: string, object: string, created_at: int, bytes: int, filename: string, purpose: string, status: string, status_details: array<array-key, mixed>|string|null}>}>
* @implements ResponseContract<array{object: string, data: array<int, array{id: string, object: string, created_at: int, bytes: ?int, filename: string, purpose: string, status: string, status_details: array<array-key, mixed>|string|null}>}>
*/
final class ListResponse implements ResponseContract, ResponseHasMetaInformationContract
{
/**
* @use ArrayAccessible<array{object: string, data: array<int, array{id: string, object: string, created_at: int, bytes: int, filename: string, purpose: string, status: string, status_details: array<array-key, mixed>|string|null}>}>
* @use ArrayAccessible<array{object: string, data: array<int, array{id: string, object: string, created_at: int, bytes: ?int, filename: string, purpose: string, status: string, status_details: array<array-key, mixed>|string|null}>}>
*/
use ArrayAccessible;

Expand All @@ -37,7 +37,7 @@ private function __construct(
/**
* Acts as static factory, and returns a new Response instance.
*
* @param array{object: string, data: array<int, array{id: string, object: string, created_at: int, bytes: int, filename: string, purpose: string, status: string, status_details: array<array-key, mixed>|string|null}>} $attributes
* @param array{object: string, data: array<int, array{id: string, object: string, created_at: int, bytes: ?int, filename: string, purpose: string, status: string, status_details: array<array-key, mixed>|string|null}>} $attributes
*/
public static function from(array $attributes, MetaInformation $meta): self
{
Expand Down
8 changes: 4 additions & 4 deletions src/Responses/Files/RetrieveResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
use OpenAI\Testing\Responses\Concerns\Fakeable;

/**
* @implements ResponseContract<array{id: string, object: string, created_at: int, bytes: int, filename: string, purpose: string, status: string, status_details: array<array-key, mixed>|string|null}>
* @implements ResponseContract<array{id: string, object: string, created_at: int, bytes: ?int, filename: string, purpose: string, status: string, status_details: array<array-key, mixed>|string|null}>
*/
final class RetrieveResponse implements ResponseContract, ResponseHasMetaInformationContract
{
/**
* @use ArrayAccessible<array{id: string, object: string, created_at: int, bytes: int, filename: string, purpose: string, status: string, status_details: array<array-key, mixed>|string|null}>
* @use ArrayAccessible<array{id: string, object: string, created_at: int, bytes: ?int, filename: string, purpose: string, status: string, status_details: array<array-key, mixed>|string|null}>
*/
use ArrayAccessible;

Expand All @@ -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,
Expand All @@ -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<array-key, mixed>|string|null} $attributes
* @param array{id: string, object: string, created_at: int, bytes: ?int, filename: string, purpose: string, status: string, status_details: array<array-key, mixed>|string|null} $attributes
*/
public static function from(array $attributes, MetaInformation $meta): self
{
Expand Down
17 changes: 17 additions & 0 deletions tests/Responses/Files/RetrieveResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down

0 comments on commit fdef71c

Please sign in to comment.