Skip to content

Commit 80baa0c

Browse files
committed
fixes and tests
1 parent a0e7a97 commit 80baa0c

File tree

3 files changed

+197
-2
lines changed

3 files changed

+197
-2
lines changed

src/Client.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ public function list(?ListCommandOptions $options = null): ListBlobResult|ListFo
236236
}
237237

238238
if ($options?->mode) {
239-
$queryParams['mode'] = $options->mode;
239+
$queryParams['mode'] = $options->mode->value;
240240
}
241241

242242
if ($options?->prefix) {

src/ListBlobResultBlob.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public function __construct(
1010
public readonly string $url,
1111
public readonly string $downloadUrl,
1212
public readonly string $pathname,
13-
public readonly int $number,
13+
public readonly int $size,
1414
public readonly DateTime $uploadedAt,
1515
) {
1616
}

tests/ClientTest.php

+195
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
use VercelBlobPhp\Exception\BlobStoreSuspendedException;
2323
use VercelBlobPhp\Exception\BlobUnknownException;
2424
use VercelBlobPhp\HeadBlobResult;
25+
use VercelBlobPhp\ListBlobResult;
26+
use VercelBlobPhp\ListBlobResultBlob;
27+
use VercelBlobPhp\ListCommandMode;
28+
use VercelBlobPhp\ListCommandOptions;
29+
use VercelBlobPhp\ListFoldedBlobResult;
2530
use VercelBlobPhp\PutBlobResult;
2631

2732
class ClientTest extends TestCase
@@ -322,6 +327,196 @@ public function testHead(): void
322327
);
323328
}
324329

330+
public static function listDataProvider(): Generator
331+
{
332+
yield [
333+
null,
334+
[
335+
'blobs' => [
336+
[
337+
'url' => 'url',
338+
'downloadUrl' => 'downloadUrl',
339+
'pathname' => 'pathname',
340+
'size' => 1,
341+
'uploadedAt' => '2024-01-01 10:00:00',
342+
],
343+
],
344+
'cursor' => 'cursor',
345+
'hasMore' => true,
346+
],
347+
'blob?',
348+
new ListBlobResult(
349+
[
350+
new ListBlobResultBlob(
351+
'url',
352+
'downloadUrl',
353+
'pathname',
354+
1,
355+
new DateTime('2024-01-01 10:00:00')
356+
)
357+
],
358+
'cursor',
359+
true
360+
)
361+
];
362+
363+
yield [
364+
new ListCommandOptions(mode: ListCommandMode::FOLDED),
365+
[
366+
'blobs' => [
367+
[
368+
'url' => 'url',
369+
'downloadUrl' => 'downloadUrl',
370+
'pathname' => 'pathname',
371+
'size' => 1,
372+
'uploadedAt' => '2024-01-01 10:00:00',
373+
],
374+
],
375+
'cursor' => 'cursor',
376+
'hasMore' => true,
377+
'folders' => [
378+
'folder1',
379+
'folder2'
380+
]
381+
],
382+
'blob?mode=folded',
383+
new ListFoldedBlobResult(
384+
[
385+
new ListBlobResultBlob(
386+
'url',
387+
'downloadUrl',
388+
'pathname',
389+
1,
390+
new DateTime('2024-01-01 10:00:00')
391+
)
392+
],
393+
'cursor',
394+
true,
395+
[
396+
'folder1',
397+
'folder2'
398+
]
399+
)
400+
];
401+
402+
yield [
403+
new ListCommandOptions(cursor: 'cursor'),
404+
[
405+
'blobs' => [
406+
[
407+
'url' => 'url',
408+
'downloadUrl' => 'downloadUrl',
409+
'pathname' => 'pathname',
410+
'size' => 1,
411+
'uploadedAt' => '2024-01-01 10:00:00',
412+
],
413+
],
414+
'cursor' => 'cursor',
415+
'hasMore' => true,
416+
],
417+
'blob?cursor=cursor',
418+
new ListBlobResult(
419+
[
420+
new ListBlobResultBlob(
421+
'url',
422+
'downloadUrl',
423+
'pathname',
424+
1,
425+
new DateTime('2024-01-01 10:00:00')
426+
)
427+
],
428+
'cursor',
429+
true
430+
)
431+
];
432+
433+
yield [
434+
new ListCommandOptions(limit: 100),
435+
[
436+
'blobs' => [
437+
[
438+
'url' => 'url',
439+
'downloadUrl' => 'downloadUrl',
440+
'pathname' => 'pathname',
441+
'size' => 1,
442+
'uploadedAt' => '2024-01-01 10:00:00',
443+
],
444+
],
445+
'cursor' => 'cursor',
446+
'hasMore' => true,
447+
],
448+
'blob?limit=100',
449+
new ListBlobResult(
450+
[
451+
new ListBlobResultBlob(
452+
'url',
453+
'downloadUrl',
454+
'pathname',
455+
1,
456+
new DateTime('2024-01-01 10:00:00')
457+
)
458+
],
459+
'cursor',
460+
true
461+
)
462+
];
463+
464+
yield [
465+
new ListCommandOptions(prefix: 'test'),
466+
[
467+
'blobs' => [
468+
[
469+
'url' => 'url',
470+
'downloadUrl' => 'downloadUrl',
471+
'pathname' => 'pathname',
472+
'size' => 1,
473+
'uploadedAt' => '2024-01-01 10:00:00',
474+
],
475+
],
476+
'cursor' => 'cursor',
477+
'hasMore' => true,
478+
],
479+
'blob?prefix=test',
480+
new ListBlobResult(
481+
[
482+
new ListBlobResultBlob(
483+
'url',
484+
'downloadUrl',
485+
'pathname',
486+
1,
487+
new DateTime('2024-01-01 10:00:00')
488+
)
489+
],
490+
'cursor',
491+
true
492+
)
493+
];
494+
}
495+
496+
#[DataProvider('listDataProvider')]
497+
public function testList(
498+
?ListCommandOptions $options,
499+
array $response,
500+
string $expectedUrl,
501+
ListBlobResult|ListFoldedBlobResult $expectedResult
502+
): void {
503+
$sut = new Client('my-token');
504+
505+
$sut->setClient(
506+
$this->mockClient(
507+
$expectedUrl,
508+
'GET',
509+
[],
510+
$response
511+
)
512+
);
513+
514+
$this->assertEquals(
515+
$expectedResult,
516+
$sut->list($options)
517+
);
518+
}
519+
325520
private function mockClient(
326521
string $url,
327522
string $method,

0 commit comments

Comments
 (0)