diff --git a/tests/ClientFileOperationsTest.php b/tests/ClientFileOperationsTest.php index 929d8af..35f1e34 100644 --- a/tests/ClientFileOperationsTest.php +++ b/tests/ClientFileOperationsTest.php @@ -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'); @@ -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); @@ -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, [ @@ -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); } @@ -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() diff --git a/tests/ClientUploadTest.php b/tests/ClientUploadTest.php index d886c9c..c5e3d2b 100644 --- a/tests/ClientUploadTest.php +++ b/tests/ClientUploadTest.php @@ -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; @@ -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()