Skip to content

Commit

Permalink
fixes and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dam-bal committed Apr 19, 2024
1 parent a0e7a97 commit 80baa0c
Show file tree
Hide file tree
Showing 3 changed files with 197 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public function list(?ListCommandOptions $options = null): ListBlobResult|ListFo
}

if ($options?->mode) {
$queryParams['mode'] = $options->mode;
$queryParams['mode'] = $options->mode->value;
}

if ($options?->prefix) {
Expand Down
2 changes: 1 addition & 1 deletion src/ListBlobResultBlob.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public function __construct(
public readonly string $url,
public readonly string $downloadUrl,
public readonly string $pathname,
public readonly int $number,
public readonly int $size,
public readonly DateTime $uploadedAt,
) {
}
Expand Down
195 changes: 195 additions & 0 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
use VercelBlobPhp\Exception\BlobStoreSuspendedException;
use VercelBlobPhp\Exception\BlobUnknownException;
use VercelBlobPhp\HeadBlobResult;
use VercelBlobPhp\ListBlobResult;
use VercelBlobPhp\ListBlobResultBlob;
use VercelBlobPhp\ListCommandMode;
use VercelBlobPhp\ListCommandOptions;
use VercelBlobPhp\ListFoldedBlobResult;
use VercelBlobPhp\PutBlobResult;

class ClientTest extends TestCase
Expand Down Expand Up @@ -322,6 +327,196 @@ public function testHead(): void
);
}

public static function listDataProvider(): Generator
{
yield [
null,
[
'blobs' => [
[
'url' => 'url',
'downloadUrl' => 'downloadUrl',
'pathname' => 'pathname',
'size' => 1,
'uploadedAt' => '2024-01-01 10:00:00',
],
],
'cursor' => 'cursor',
'hasMore' => true,
],
'blob?',
new ListBlobResult(
[
new ListBlobResultBlob(
'url',
'downloadUrl',
'pathname',
1,
new DateTime('2024-01-01 10:00:00')
)
],
'cursor',
true
)
];

yield [
new ListCommandOptions(mode: ListCommandMode::FOLDED),
[
'blobs' => [
[
'url' => 'url',
'downloadUrl' => 'downloadUrl',
'pathname' => 'pathname',
'size' => 1,
'uploadedAt' => '2024-01-01 10:00:00',
],
],
'cursor' => 'cursor',
'hasMore' => true,
'folders' => [
'folder1',
'folder2'
]
],
'blob?mode=folded',
new ListFoldedBlobResult(
[
new ListBlobResultBlob(
'url',
'downloadUrl',
'pathname',
1,
new DateTime('2024-01-01 10:00:00')
)
],
'cursor',
true,
[
'folder1',
'folder2'
]
)
];

yield [
new ListCommandOptions(cursor: 'cursor'),
[
'blobs' => [
[
'url' => 'url',
'downloadUrl' => 'downloadUrl',
'pathname' => 'pathname',
'size' => 1,
'uploadedAt' => '2024-01-01 10:00:00',
],
],
'cursor' => 'cursor',
'hasMore' => true,
],
'blob?cursor=cursor',
new ListBlobResult(
[
new ListBlobResultBlob(
'url',
'downloadUrl',
'pathname',
1,
new DateTime('2024-01-01 10:00:00')
)
],
'cursor',
true
)
];

yield [
new ListCommandOptions(limit: 100),
[
'blobs' => [
[
'url' => 'url',
'downloadUrl' => 'downloadUrl',
'pathname' => 'pathname',
'size' => 1,
'uploadedAt' => '2024-01-01 10:00:00',
],
],
'cursor' => 'cursor',
'hasMore' => true,
],
'blob?limit=100',
new ListBlobResult(
[
new ListBlobResultBlob(
'url',
'downloadUrl',
'pathname',
1,
new DateTime('2024-01-01 10:00:00')
)
],
'cursor',
true
)
];

yield [
new ListCommandOptions(prefix: 'test'),
[
'blobs' => [
[
'url' => 'url',
'downloadUrl' => 'downloadUrl',
'pathname' => 'pathname',
'size' => 1,
'uploadedAt' => '2024-01-01 10:00:00',
],
],
'cursor' => 'cursor',
'hasMore' => true,
],
'blob?prefix=test',
new ListBlobResult(
[
new ListBlobResultBlob(
'url',
'downloadUrl',
'pathname',
1,
new DateTime('2024-01-01 10:00:00')
)
],
'cursor',
true
)
];
}

#[DataProvider('listDataProvider')]
public function testList(
?ListCommandOptions $options,
array $response,
string $expectedUrl,
ListBlobResult|ListFoldedBlobResult $expectedResult
): void {
$sut = new Client('my-token');

$sut->setClient(
$this->mockClient(
$expectedUrl,
'GET',
[],
$response
)
);

$this->assertEquals(
$expectedResult,
$sut->list($options)
);
}

private function mockClient(
string $url,
string $method,
Expand Down

0 comments on commit 80baa0c

Please sign in to comment.