/** * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::createBlobSnapshot * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::createPageBlob * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::deleteBlob * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::getBlob * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::listBlobs */ private function deleteBlobWorker($options, $container) { $blob = BlobServiceFunctionalTestData::getInterestingBlobName($container); // Make sure there is something to test $dataSize = 512; $this->restProxy->createPageBlob($container, $blob, $dataSize); $snapshot = $this->restProxy->createBlobSnapshot($container, $blob); $this->restProxy->createBlobSnapshot($container, $blob); $blobinfo = $this->restProxy->getBlob($container, $blob); if (!is_null($options)) { BlobServiceFunctionalTestData::fixETagAccessCondition($options->getAccessCondition(), $blobinfo->getProperties()->getETag()); $options->setSnapshot(is_null($options->getSnapshot()) ? null : $snapshot->getSnapshot()); } $deleted = false; try { if (is_null($options)) { $this->restProxy->deleteBlob($container, $blob); } else { $this->restProxy->deleteBlob($container, $blob, $options); } $deleted = true; if (is_null($options)) { $options = new DeleteBlobOptions(); } if (!is_null($options->getTimeout()) && $options->getTimeout() < 1) { $this->assertTrue(false, 'Expect negative timeouts in $options to throw'); } if (!BlobServiceFunctionalTestData::passTemporalAccessCondition($options->getAccessCondition())) { $this->assertTrue(false, 'Expect failing temporal access condition should throw'); } if (!BlobServiceFunctionalTestData::passTemporalAccessCondition($options->getAccessCondition())) { $this->assertTrue(false, 'Expect failing etag access condition to throw'); } $listOptions = new ListBlobsOptions(); $listOptions->setIncludeSnapshots(true); $listOptions->setPrefix($blob); $listBlobsResult = $this->restProxy->listBlobs($container == '' ? '$root' : $container, $listOptions); $blobs = $listBlobsResult->getBlobs(); $this->verifyDeleteBlobWorker($options, $blobs); } catch (ServiceException $e) { if (!is_null($options->getTimeout()) && $options->getTimeout() < 1) { $this->assertEquals(TestResources::STATUS_INTERNAL_SERVER_ERROR, $e->getCode(), 'bad timeout: deleteHttpStatusCode'); } else { if (!BlobServiceFunctionalTestData::passTemporalAccessCondition($options->getAccessCondition())) { $this->assertEquals(TestResources::STATUS_PRECONDITION_FAILED, $e->getCode(), 'bad temporal access condition IF_UNMODIFIED_SINCE: deleteHttpStatusCode'); } else { if (!BlobServiceFunctionalTestData::passETagAccessCondition($options->getAccessCondition())) { $this->assertEquals(TestResources::STATUS_PRECONDITION_FAILED, $e->getCode(), 'bad etag access condition: deleteHttpStatusCode'); } else { throw $e; } } } } // Clean up. if (!$deleted) { $this->restProxy->deleteBlob($container, $blob); } }
/** * Deletes a blob or blob snapshot. * * Note that if the snapshot entry is specified in the $options then only this * blob snapshot is deleted. To delete all blob snapshots, do not set Snapshot * and just set getDeleteSnaphotsOnly to true. * * @param string $container name of the container * @param string $blob name of the blob * @param Models\DeleteBlobOptions $options optional parameters * * @return none * * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179413.aspx */ public function deleteBlob($container, $blob, $options = null) { Validate::isString($container, 'container'); Validate::isString($blob, 'blob'); Validate::notNullOrEmpty($blob, 'blob'); $method = Resources::HTTP_DELETE; $headers = array(); $postParams = array(); $queryParams = array(); $path = $this->_createPath($container, $blob); $statusCode = Resources::STATUS_ACCEPTED; if (is_null($options)) { $options = new DeleteBlobOptions(); } if (is_null($options->getSnapshot())) { $delSnapshots = $options->getDeleteSnaphotsOnly() ? 'only' : 'include'; $this->addOptionalHeader($headers, Resources::X_MS_DELETE_SNAPSHOTS, $delSnapshots); } else { $this->addOptionalQueryParam($queryParams, Resources::QP_SNAPSHOT, $options->getSnapshot()); } $headers = $this->addOptionalAccessConditionHeader($headers, $options->getAccessCondition()); $this->addOptionalHeader($headers, Resources::X_MS_LEASE_ID, $options->getLeaseId()); $this->addOptionalQueryParam($queryParams, Resources::QP_TIMEOUT, $options->getTimeout()); $this->send($method, $headers, $queryParams, $postParams, $path, $statusCode); }