/** * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::createContainer * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::deleteContainer * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::getContainerMetadata * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::listContainers */ private function createContainerWorker($options) { $container = BlobServiceFunctionalTestData::getInterestingContainerName(); $created = false; try { if (is_null($options)) { $this->restProxy->createContainer($container); } else { $this->restProxy->createContainer($container, $options); } $created = true; if (is_null($options)) { $options = new CreateContainerOptions(); } if (!is_null($options->getTimeout()) && $options->getTimeout() < 1) { $this->assertTrue(false, 'Expect negative timeouts in $options to throw'); } // Now check that the $container was $created correctly. // Make sure that the list of all applicable containers is correctly updated. $opts = new ListContainersOptions(); $opts->setPrefix(BlobServiceFunctionalTestData::$testUniqueId); $qs = $this->restProxy->listContainers($opts); $this->assertEquals(count($qs->getContainers()), count(BlobServiceFunctionalTestData::$testContainerNames) + 1, 'After adding one, with Prefix=(\'' . BlobServiceFunctionalTestData::$testUniqueId . '\'), then Containers length'); // Check the metadata on the container $ret = $this->restProxy->getContainerMetadata($container); $this->verifyCreateContainerWorker($ret, $options); $this->restProxy->deleteContainer($container); } catch (ServiceException $e) { if (is_null($options)) { $options = new CreateContainerOptions(); } if (is_null($options->getTimeout()) || $options->getTimeout() >= 1) { throw $e; } else { $this->assertEquals(TestResources::STATUS_INTERNAL_SERVER_ERROR, $e->getCode(), 'getCode'); } } if ($created) { try { $this->restProxy->deleteContainer($container); } catch (ServiceException $e) { // Ignore. } } }
/** * Creates a new container in the given storage account. * * @param string $container The container name. * @param Models\CreateContainerOptions $options The optional parameters. * * @return none * * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179468.aspx */ public function createContainer($container, $options = null) { Validate::isString($container, 'container'); Validate::notNullOrEmpty($container, 'container'); $method = Resources::HTTP_PUT; $headers = array(); $postParams = array(); $queryParams = array(Resources::QP_REST_TYPE => 'container'); $path = $container; $statusCode = Resources::STATUS_CREATED; if (is_null($options)) { $options = new CreateContainerOptions(); } $this->addOptionalQueryParam($queryParams, Resources::QP_TIMEOUT, $options->getTimeout()); $metadata = $options->getMetadata(); $headers = $this->generateMetadataHeaders($metadata); $this->addOptionalHeader($headers, Resources::X_MS_BLOB_PUBLIC_ACCESS, $options->getPublicAccess()); $this->send($method, $headers, $queryParams, $postParams, $path, $statusCode); }