-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into enhancement/blob-storage-usage
- Loading branch information
Showing
10 changed files
with
424 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
vendor/ | ||
.env | ||
.DS_Store | ||
.DS_Store | ||
index.php |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 135 additions & 0 deletions
135
tests/Feature/BlobStorage/Managers/Blob/BlobLeaseManagerTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
<?php | ||
|
||
use Xray\AzureStoragePhpSdk\BlobStorage\Entities\Blob\BlobLease; | ||
use Xray\AzureStoragePhpSdk\BlobStorage\Managers\Blob\BlobLeaseManager; | ||
use Xray\AzureStoragePhpSdk\Exceptions\RequiredFieldException; | ||
use Xray\AzureStoragePhpSdk\Tests\Http\{RequestFake, ResponseFake}; | ||
|
||
uses()->group('blob-storage', 'managers', 'blob'); | ||
|
||
const REQUEST_URL = 'container/blob?comp=lease&resttype=blob'; | ||
const VERSION = '2020-06-12'; | ||
|
||
it('should acquire a lease', function () { | ||
['request' => $request, 'manager' => $manager] = prepareForBlobLeaseManagerTest(); | ||
|
||
$response = $manager->acquire(); | ||
|
||
expect($response) | ||
->lastModified->toBeInstanceOf(DateTimeImmutable::class) | ||
->etag->toBe('KCSNSAKDMA') | ||
->server->toBe('MS-AZURE') | ||
->requestId->toBe('osjdnw-29389dksd-dwwdwd') | ||
->version->toBe(VERSION) | ||
->leaseId->toBe('lalsncjwej-29389dksd-dwwdwd') | ||
->date->toBeInstanceOf(DateTimeImmutable::class); | ||
|
||
$request->assertPut(REQUEST_URL); | ||
}); | ||
|
||
it('should renew a lease', function () { | ||
['request' => $request, 'blobLease' => $blobLease] = prepareForBlobLeaseManagerTest(); | ||
|
||
$response = $blobLease->renew(); | ||
|
||
expect($response) | ||
->lastModified->toBeInstanceOf(DateTimeImmutable::class) | ||
->etag->toBe('KCSNSAKDMA') | ||
->server->toBe('MS-AZURE') | ||
->requestId->toBe('osjdnw-29389dksd-dwwdwd') | ||
->version->toBe(VERSION) | ||
->leaseId->toBe('lalsncjwej-29389dksd-dwwdwd') | ||
->date->toBeInstanceOf(DateTimeImmutable::class); | ||
|
||
$request->assertPut(REQUEST_URL); | ||
}); | ||
|
||
it('should change a lease', function () { | ||
['request' => $request, 'blobLease' => $blobLease] = prepareForBlobLeaseManagerTest(); | ||
|
||
$response = $blobLease->change('lalsncjwej-29389dksd-dwwdwd'); | ||
|
||
expect($response) | ||
->lastModified->toBeInstanceOf(DateTimeImmutable::class) | ||
->etag->toBe('KCSNSAKDMA') | ||
->server->toBe('MS-AZURE') | ||
->requestId->toBe('osjdnw-29389dksd-dwwdwd') | ||
->version->toBe(VERSION) | ||
->leaseId->toBe('lalsncjwej-29389dksd-dwwdwd') | ||
->date->toBeInstanceOf(DateTimeImmutable::class); | ||
|
||
$request->assertPut(REQUEST_URL); | ||
}); | ||
|
||
it('should release a lease', function () { | ||
['request' => $request, 'blobLease' => $blobLease] = prepareForBlobLeaseManagerTest(); | ||
|
||
$response = $blobLease->release('lalsncjwej-29389dksd-dwwdwd'); | ||
|
||
expect($response) | ||
->lastModified->toBeInstanceOf(DateTimeImmutable::class) | ||
->etag->toBe('KCSNSAKDMA') | ||
->server->toBe('MS-AZURE') | ||
->requestId->toBe('osjdnw-29389dksd-dwwdwd') | ||
->version->toBe(VERSION) | ||
->leaseId->toBe('lalsncjwej-29389dksd-dwwdwd') | ||
->date->toBeInstanceOf(DateTimeImmutable::class); | ||
|
||
$request->assertPut(REQUEST_URL); | ||
}); | ||
|
||
it('should break a lease', function () { | ||
['request' => $request, 'blobLease' => $blobLease] = prepareForBlobLeaseManagerTest(); | ||
|
||
$response = $blobLease->break('lalsncjwej-29389dksd-dwwdwd'); | ||
|
||
expect($response) | ||
->lastModified->toBeInstanceOf(DateTimeImmutable::class) | ||
->etag->toBe('KCSNSAKDMA') | ||
->server->toBe('MS-AZURE') | ||
->requestId->toBe('osjdnw-29389dksd-dwwdwd') | ||
->version->toBe(VERSION) | ||
->leaseId->toBe('lalsncjwej-29389dksd-dwwdwd') | ||
->date->toBeInstanceOf(DateTimeImmutable::class); | ||
|
||
$request->assertPut(REQUEST_URL); | ||
}); | ||
|
||
it('should throw an exception when trying to renew a lease without a lease id', function () { | ||
['blobLease' => $blobLease] = prepareForBlobLeaseManagerTest(['x-ms-lease-id' => '']); | ||
|
||
$blobLease->renew(); | ||
})->throws(RequiredFieldException::class, 'Field [leaseId] is required'); | ||
|
||
/** | ||
* @param array<string, scalar> $blobLeaseHeaders | ||
* @return array{request: RequestFake, blobLease: BlobLease, manager: BlobLeaseManager} | ||
*/ | ||
function prepareForBlobLeaseManagerTest(array $blobLeaseHeaders = []): array | ||
{ | ||
$blobLeaseHeaders = array_merge([ | ||
'Last-Modified' => 'Wed, 15 Sep 2021 15:02:29 GMT', | ||
'ETag' => 'KCSNSAKDMA', | ||
'Server' => 'MS-AZURE', | ||
'Date' => 'Wed, 15 Sep 2021 15:02:29 GMT', | ||
'x-ms-request-id' => 'osjdnw-29389dksd-dwwdwd', | ||
'x-ms-version' => VERSION, | ||
'x-ms-lease-id' => 'lalsncjwej-29389dksd-dwwdwd', | ||
], $blobLeaseHeaders); | ||
|
||
$request = (new RequestFake()) | ||
->withFakeResponse(new ResponseFake(headers: $blobLeaseHeaders)); | ||
|
||
// @phpstan-ignore-next-line | ||
$blobLease = new BlobLease($blobLeaseHeaders); | ||
|
||
$manager = (new BlobLeaseManager($request, 'container', 'blob')); | ||
|
||
$blobLease->setManager($manager); | ||
|
||
return [ | ||
'request' => $request, | ||
'blobLease' => $blobLease, | ||
'manager' => $manager, | ||
]; | ||
} |
Oops, something went wrong.