Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zaxbux committed Jul 9, 2021
1 parent 7533921 commit fd32cf5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
16 changes: 9 additions & 7 deletions tests/ClientFileOperationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,19 @@ public function testDeleteFileVersion()

$fileId = $this->client->getFileByName('Test file.bin', 'bucketId')->id();

static::assertInstanceOf(File::class, $this->client->deleteFileVersion('Test file.bin', $fileId));
static::assertInstanceOf(File::class, $this->client->deleteFileVersion($fileId, 'Test file.bin'));
}


public function testDeleteFileWithoutName()
{
$this->guzzler->queueResponse(
MockResponse::fromFile('list_file_versions.json'),
MockResponse::fromFile('get_file_info.json'),
MockResponse::fromFile('delete_file.json'),
);

$this->guzzler->expects($this->once())
->post(static::getEndpointUri(Endpoint::LIST_FILE_VERSIONS))
->post(static::getEndpointUri(Endpoint::GET_FILE_INFO))
->post(static::getEndpointUri(Endpoint::DELETE_FILE_VERSION));

$file = $this->client->deleteFileVersion('fileId');
Expand Down Expand Up @@ -144,11 +144,12 @@ public function testUpdateLegalFileHold()
public function testUpdateLegalFileHoldWithoutFileName()
{
$this->guzzler->queueResponse(
MockResponse::fromFile('list_file_versions.json'),
MockResponse::fromFile('get_file_info.json'),
MockResponse::fromFile('update_file_legal_hold.json'),
);

$this->guzzler->expects($this->once())
->post(static::getEndpointUri(Endpoint::GET_FILE_INFO))
->post(static::getEndpointUri(Endpoint::UPDATE_FILE_LEGAL_HOLD));

$file = $this->client->updateFileLegalHold('file_id', null, FileLock::LEGAL_HOLD_ENABLED);
Expand Down Expand Up @@ -176,11 +177,12 @@ public function testUpdateFileRetention()
public function testUpdateFileRetentionWithoutFileName()
{
$this->guzzler->queueResponse(
MockResponse::fromFile('list_file_versions.json'),
MockResponse::fromFile('get_file_info.json'),
MockResponse::fromFile('update_file_retention.json'),
);

$this->guzzler->expects($this->once())
->post(static::getEndpointUri(Endpoint::GET_FILE_INFO))
->post(static::getEndpointUri(Endpoint::UPDATE_FILE_RETENTION));

$file = $this->client->updateFileRetention('file_id', null, [
Expand Down Expand Up @@ -229,7 +231,7 @@ public function testGetFileById()
MockResponse::fromFile('get_file.json'),
);

$file = $this->client->getFileById('fileId', 'bucketId');
$file = $this->client->getFileInfo('fileId');

static::assertInstanceOf(File::class, $file);
}
Expand All @@ -242,7 +244,7 @@ public function testGettingNonExistentFileThrowsException()
MockResponse::fromFile('get_file_non_existent.json', 400),
);

$this->client->getFileById('fileId', 'bucketId');
$this->client->getFileInfo('fileId');
}

public function testDeleteAllFileVersions()
Expand Down
16 changes: 9 additions & 7 deletions tests/ClientUploadTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace tests;

use BlastCloud\Guzzler\Expectation;
use Zaxbux\BackblazeB2\Utils as ClientUtils;
use Zaxbux\BackblazeB2\Helpers\UploadHelper;
use Zaxbux\BackblazeB2\Http\Endpoint;
Expand All @@ -19,20 +20,21 @@ public function testUploadingFile() {
$filePath = ClientUtils::joinFilePaths(__DIR__, 'responses', 'download_content');

$file = UploadHelper::instance($this->client)->uploadFile(
'/file/name.txt',
'bucketId',
'/file/name.txt',
$filePath,
'text/plain'
);

static::assertInstanceOf(File::class, $file);

$this->guzzler->expects($this->once())
->post('https://pod-000-1005-03.backblaze.com/b2api/v2/b2_upload_file?cvt=c001_v0001005_t0027&bucket=4a48fe8875c6214145260818')
->withHeader('Content-Length', 43)
->withHeader(File::HEADER_X_BZ_FILE_NAME, '/file/name.txt')
->withHeader(File::HEADER_X_BZ_CONTENT_SHA1, sha1_file($filePath))
->withBody(file_get_contents($filePath));
$this->guzzler->assertLast(function (Expectation $expectation) use ($filePath) {
$expectation->post('https://pod-000-1005-03.backblaze.com/b2api/v2/b2_upload_file')
->withHeader('Content-Length', 43)
->withHeader(File::HEADER_X_BZ_FILE_NAME, urlencode('/file/name.txt'))
->withHeader(File::HEADER_X_BZ_CONTENT_SHA1, sha1_file($filePath))
->withBody(file_get_contents($filePath));
});
}

public function testUploadingResource()
Expand Down

0 comments on commit fd32cf5

Please sign in to comment.