/** * @covers MicrosoftAzure\Storage\Blob\Models\CreateContainerOptions::setPublicAccess */ public function testSetPublicAccessInvalidValueFail() { // Setup $properties = new CreateContainerOptions(); $expected = new \DateTime(); $this->setExpectedException(get_class(new InvalidArgumentTypeException(''))); // Test $properties->setPublicAccess($expected); }
public function createContainer($containerName, $options = null) { if (is_null($options)) { $options = new CreateContainerOptions(); $options->setPublicAccess('container'); } $this->restProxy->createContainer($containerName, $options); $this->_createdContainers[] = $containerName; }
function createContainerSample($blobClient) { // OPTIONAL: Set public access policy and metadata. // Create container options object. $createContainerOptions = new CreateContainerOptions(); // Set public access policy. Possible values are // PublicAccessType::CONTAINER_AND_BLOBS and PublicAccessType::BLOBS_ONLY. // CONTAINER_AND_BLOBS: full public read access for container and blob data. // BLOBS_ONLY: public read access for blobs. Container data not available. // If this value is not specified, container data is private to the account owner. $createContainerOptions->setPublicAccess(PublicAccessType::CONTAINER_AND_BLOBS); // Set container metadata $createContainerOptions->addMetaData("key1", "value1"); $createContainerOptions->addMetaData("key2", "value2"); try { // Create container. $blobClient->createContainer("mycontainer", $createContainerOptions); } catch (ServiceException $e) { $code = $e->getCode(); $error_message = $e->getMessage(); echo $code . ": " . $error_message . PHP_EOL; } }
public static function getInterestingCreateContainerOptions() { $ret = array(); $options = new CreateContainerOptions(); array_push($ret, $options); $options = new CreateContainerOptions(); $options->setTimeout(10); array_push($ret, $options); $options = new CreateContainerOptions(); $options->setTimeout(-10); array_push($ret, $options); $options = new CreateContainerOptions(); $options->setPublicAccess('container'); array_push($ret, $options); $options = new CreateContainerOptions(); $options->setPublicAccess('blob'); array_push($ret, $options); $options = new CreateContainerOptions(); $metadata = array('foo' => 'bar', 'boo' => 'baz'); $options->setMetadata($metadata); array_push($ret, $options); return $ret; }
/** * @return void */ protected function createContainer() { $createContainerOptions = new CreateContainerOptions(); $createContainerOptions->setPublicAccess(PublicAccessType::BLOBS_ONLY); try { $this->blobRestProxy->createContainer($this->container, $createContainerOptions); } catch (ServiceException $e) { // Code 409 - "container already exists" is ok in this case if (!($e->getCode() === 409)) { $flashMessage = $this->getFlashMessage($e); $this->getMessageQueueByIdentifier()->enqueue($flashMessage); } } }
/** * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::createContainer * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::deleteContainer * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::getContainerACL * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::getContainerMetadata * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::getContainerProperties * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::listContainers */ public function testCreateContainerWithMetadataWorks() { // Act $opts = new CreateContainerOptions(); $opts->setPublicAccess('blob'); $opts->addMetadata('test', 'bar'); $opts->addMetadata('blah', 'bleah'); $this->restProxy->createContainer(self::$_creatable_container_2, $opts); $prop = $this->restProxy->getContainerMetadata(self::$_creatable_container_2); $prop2 = $this->restProxy->getContainerProperties(self::$_creatable_container_2); $acl = $this->restProxy->getContainerACL(self::$_creatable_container_2)->getContainerACL(); $opts = new ListContainersOptions(); $opts->setPrefix(self::$_creatable_container_2); $opts->setIncludeMetadata(true); $results2 = $this->restProxy->listContainers($opts); $this->restProxy->deleteContainer(self::$_creatable_container_2); // Assert $this->assertNotNull($prop, '$prop'); $this->assertNotNull($prop->getETag(), '$prop->getETag()'); $this->assertNotNull($prop->getLastModified(), '$prop->getLastModified()'); $this->assertNotNull($prop->getMetadata(), '$prop->getMetadata()'); $this->assertEquals(2, count($prop->getMetadata()), 'count($prop->getMetadata())'); $this->assertTrue(Utilities::arrayKeyExistsInsensitive('test', $prop->getMetadata()), 'Utilities::arrayKeyExistsInsensitive(\'test\', $prop->getMetadata())'); $this->assertTrue(!(array_search('bar', $prop->getMetadata()) === FALSE), '!(array_search(\'bar\', $prop->getMetadata()) === FALSE)'); $this->assertTrue(Utilities::arrayKeyExistsInsensitive('blah', $prop->getMetadata()), 'Utilities::arrayKeyExistsInsensitive(\'blah\', $prop->getMetadata())'); $this->assertTrue(!(array_search('bleah', $prop->getMetadata()) === FALSE), '!(array_search(\'bleah\', $prop->getMetadata()) === FALSE)'); $this->assertNotNull($prop2, '$prop2'); $this->assertNotNull($prop2->getETag(), '$prop2->getETag()'); $this->assertNotNull($prop2->getLastModified(), '$prop2->getLastModified()'); $this->assertNotNull($prop2->getMetadata(), '$prop2->getMetadata()'); $this->assertEquals(2, count($prop2->getMetadata()), 'count($prop2->getMetadata())'); $this->assertTrue(Utilities::arrayKeyExistsInsensitive('test', $prop2->getMetadata()), 'Utilities::arrayKeyExistsInsensitive(\'test\', $prop2->getMetadata())'); $this->assertTrue(!(array_search('bar', $prop2->getMetadata()) === FALSE), '!(array_search(\'bar\', $prop2->getMetadata()) === FALSE)'); $this->assertTrue(Utilities::arrayKeyExistsInsensitive('blah', $prop2->getMetadata()), 'Utilities::arrayKeyExistsInsensitive(\'blah\', $prop2->getMetadata())'); $this->assertTrue(!(array_search('bleah', $prop2->getMetadata()) === FALSE), '!(array_search(\'bleah\', $prop2->getMetadata()) === FALSE)'); $this->assertNotNull($results2, '$results2'); $this->assertEquals(1, count($results2->getContainers()), 'count($results2->getContainers())'); $container0 = $results2->getContainers(); $container0 = $container0[0]; // The capitalizaion gets changed. $this->assertTrue(Utilities::arrayKeyExistsInsensitive('test', $container0->getMetadata()), 'Utilities::arrayKeyExistsInsensitive(\'test\', $container0->getMetadata())'); $this->assertTrue(!(array_search('bar', $container0->getMetadata()) === FALSE), '!(array_search(\'bar\', $container0->getMetadata()) === FALSE)'); $this->assertTrue(Utilities::arrayKeyExistsInsensitive('blah', $container0->getMetadata()), 'Utilities::arrayKeyExistsInsensitive(\'blah\', $container0->getMetadata())'); $this->assertTrue(!(array_search('bleah', $container0->getMetadata()) === FALSE), '!(array_search(\'bleah\', $container0->getMetadata()) === FALSE)'); $this->assertNotNull($acl, '$acl'); }
/** * @covers MicrosoftAzure\Storage\Blob\BlobRestProxy::createContainer */ public function testCreateContainerWithMetadata() { $containerName = 'createcontainerwithmetadata' . $this->createSuffix(); $metadataName = 'Name'; $metadataValue = 'MyName'; $options = new CreateContainerOptions(); $options->addMetadata($metadataName, $metadataValue); $options->setPublicAccess('blob'); // Test $this->createContainer($containerName, $options); // Assert $options = new ListContainersOptions(); $options->setIncludeMetadata(true); $result = $this->restProxy->listContainers($options); $containers = $result->getContainers(); $metadata = $containers[0]->getMetadata(); $this->assertEquals($metadataValue, $metadata[$metadataName]); }