Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dam-bal committed Apr 16, 2024
1 parent fdf947a commit b16372e
Showing 1 changed file with 31 additions and 5 deletions.
36 changes: 31 additions & 5 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use VercelBlobPhp\Exception\BlobException;
use VercelBlobPhp\Exception\BlobNotFoundException;
use VercelBlobPhp\Exception\BlobServiceNotAvailableException;
use VercelBlobPhp\Exception\BlobServiceRateLimitedException;
use VercelBlobPhp\Exception\BlobStoreNotFoundException;
use VercelBlobPhp\Exception\BlobStoreSuspendedException;
use VercelBlobPhp\Exception\BlobUnknownException;
Expand Down Expand Up @@ -52,10 +53,10 @@ public static function requestThrowsCorrectExceptionBasedOnErrorCode(): Generato
BlobServiceNotAvailableException::class,
];

// yield [
// 'rate_limited',
// BlobServiceRateLimitedException::class,
// ];
yield [
'rate_limited',
BlobServiceRateLimitedException::class,
];

yield [
'unknown',
Expand All @@ -76,6 +77,13 @@ public function testRequestThrowsCorrectExceptionBasedOnErrorCode(

$response = $this->createMock(ResponseInterface::class);

if ($expectedException === BlobServiceRateLimitedException::class) {
$response
->method('getHeaderLine')
->with('retry-after')
->willReturn('60');
}

$responseBody = $this->createMock(StreamInterface::class);

$responseBody
Expand All @@ -97,5 +105,23 @@ public function testRequestThrowsCorrectExceptionBasedOnErrorCode(
$sut->request('/test', 'GET', []);
}

// testRequest
public function testRequest(): void
{
$sut = new Client('my-token');

$clientMock = $this->createMock(\GuzzleHttp\Client::class);

$sut->setClient($clientMock);

$responseMock = $this->createMock(ResponseInterface::class);

$clientMock
->method('request')
->with('GET', '/test', ['json' => ['test']])
->willReturn($responseMock);

$response = $sut->request('/test', 'GET', ['json' => ['test']]);

$this->assertEquals($responseMock, $response);
}
}

0 comments on commit b16372e

Please sign in to comment.