public static function tearDownAfterClass()
 {
     parent::tearDownAfterClass();
     $service = self::createService();
     if (!Configuration::isEmulated()) {
         $serviceProperties = QueueServiceFunctionalTestData::getDefaultServiceProperties();
         $service->setServiceProperties($serviceProperties);
     }
     foreach (QueueServiceFunctionalTestData::$TEST_QUEUE_NAMES as $name) {
         self::staticSafeDeleteQueue($service, $name);
     }
 }
 public static function setUpBeforeClass()
 {
     if (Configuration::isEmulated()) {
         throw new \Exception(self::NOT_SUPPORTED);
     }
     $subscriptionId = TestResources::serviceManagementSubscriptionId();
     $certificatePath = TestResources::serviceManagementCertificatePath();
     if (empty($subscriptionId)) {
         throw new \Exception('SERVICE_MANAGEMENT_SUBSCRIPTION_ID envionment variable is missing');
     }
     if (empty($certificatePath)) {
         throw new \Exception('SERVICE_MANAGEMENT_CERTIFICATE_PATH envionment variable is missing');
     }
 }
 public static function tearDownAfterClass()
 {
     parent::tearDownAfterClass();
     $service = self::createService();
     if (!Configuration::isEmulated()) {
         $serviceProperties = TableServiceFunctionalTestData::getDefaultServiceProperties();
         $service->setServiceProperties($serviceProperties);
     }
     foreach (TableServiceFunctionalTestData::$TEST_TABLE_NAMES as $name) {
         try {
             $service->deleteTable($name);
         } catch (\Exception $e) {
             // Ignore exception and continue.
             error_log($e->getMessage());
         }
     }
 }
 /**
  * @covers WindowsAzure\Table\TableRestProxy::insertOrReplaceEntity
  */
 public function testInsertOrReplaceEntityOptionsNull()
 {
     $table = TableServiceFunctionalTestData::$TEST_TABLE_NAMES[0];
     try {
         $this->restProxy->insertOrReplaceEntity($table, TableServiceFunctionalTestData::getSimpleEntity(), null);
         $this->assertFalse(Configuration::isEmulated(), 'Should fail if and only if in emulator');
     } catch (ServiceException $e) {
         // Expect failure when run this test with emulator, as v1.6 doesn't support this method
         if (Configuration::isEmulated()) {
             $this->assertEquals(404, $e->getCode(), 'getCode');
         }
     }
     $this->clearTable($table);
 }
 protected function skipIfEmulated()
 {
     if (Configuration::isEmulated()) {
         $this->markTestSkipped(self::NOT_SUPPORTED);
     }
 }
 private function setServicePropertiesWorker($serviceProperties, $options)
 {
     try {
         if (is_null($options)) {
             $this->restProxy->setServiceProperties($serviceProperties);
         } else {
             $this->restProxy->setServiceProperties($serviceProperties, $options);
         }
         if (is_null($options)) {
             $options = new QueueServiceOptions();
         }
         if (!is_null($options->getTimeout()) && $options->getTimeout() < 1) {
             $this->assertTrue(false, 'Expect negative timeouts in $options to throw');
         } else {
             $this->assertFalse(Configuration::isEmulated(), 'Should succeed when not running in emulator');
         }
         $ret = is_null($options) ? $this->restProxy->getServiceProperties() : $this->restProxy->getServiceProperties($options);
         $this->verifyServicePropertiesWorker($ret, $serviceProperties);
     } catch (ServiceException $e) {
         if (is_null($options)) {
             $options = new QueueServiceOptions();
         }
         if (Configuration::isEmulated()) {
             if (!is_null($options->getTimeout()) && $options->getTimeout() < 1) {
                 $this->assertEquals(500, $e->getCode(), 'getCode');
             } else {
                 $this->assertEquals(400, $e->getCode(), 'getCode');
             }
         } else {
             if (!is_null($options->getTimeout()) && $options->getTimeout() < 1) {
                 $this->assertEquals(500, $e->getCode(), 'getCode');
             } else {
                 $this->assertNull($e, 'Expect positive timeouts in $options to be fine');
             }
         }
     }
 }
 private function verifySetContainerACLWorker($ret, $container, $acl, $blobContent)
 {
     $this->assertNotNull($ret->getContainerACL(), '$ret->getContainerACL');
     $this->assertNotNull($ret->getEtag(), '$ret->getContainerACL->getEtag');
     $now = new \DateTime();
     $this->assertTrue(BlobServiceFunctionalTestData::diffInTotalSeconds($ret->getLastModified(), $now) < 10000, 'Last modified date (' . $ret->getLastModified()->format(\DateTime::RFC1123) . ') ' . 'should be within 10 seconds of $now (' . $now->format(\DateTime::RFC1123) . ')');
     $this->assertNotNull($ret->getContainerACL()->getSignedIdentifiers(), '$ret->getContainerACL->getSignedIdentifiers');
     $this->assertEquals(is_null($acl->getPublicAccess()) ? '' : $acl->getPublicAccess(), $ret->getContainerACL()->getPublicAccess(), '$ret->getContainerACL->getPublicAccess');
     $expIds = $acl->getSignedIdentifiers();
     $actIds = $ret->getContainerACL()->getSignedIdentifiers();
     $this->assertEquals(count($expIds), count($actIds), '$ret->getContainerACL->getSignedIdentifiers');
     for ($i = 0; $i < count($expIds); $i++) {
         $expId = $expIds[$i];
         $actId = $actIds[$i];
         $this->assertEquals($expId->getId(), $actId->getId(), 'SignedIdentifiers[' + $i + ']->getId');
         $this->assertEquals($expId->getAccessPolicy()->getPermission(), $actId->getAccessPolicy()->getPermission(), 'SignedIdentifiers[' + $i + ']->getAccessPolicy->getPermission');
         $this->assertTrue(BlobServiceFunctionalTestData::diffInTotalSeconds($expId->getAccessPolicy()->getStart(), $actId->getAccessPolicy()->getStart()) < 1, 'SignedIdentifiers[' + $i + ']->getAccessPolicy->getStart should match within 1 second, ' . 'exp=' . $expId->getAccessPolicy()->getStart()->format(\DateTime::RFC1123) . ', ' . 'act=' . $actId->getAccessPolicy()->getStart()->format(\DateTime::RFC1123));
         $this->assertTrue(BlobServiceFunctionalTestData::diffInTotalSeconds($expId->getAccessPolicy()->getExpiry(), $actId->getAccessPolicy()->getExpiry()) < 1, 'SignedIdentifiers[' + $i + ']->getAccessPolicy->getExpiry should match within 1 second, ' . 'exp=' . $expId->getAccessPolicy()->getExpiry()->format(\DateTime::RFC1123) . ', ' . 'act=' . $actId->getAccessPolicy()->getExpiry()->format(\DateTime::RFC1123));
     }
     if (!Configuration::isEmulated()) {
         $containerAddress = $this->config->getProperty(BlobSettings::URI) . '/' . $container;
         $blobListAddress = $containerAddress . '?restype=container&comp=list';
         $blobAddress = $containerAddress . '/test';
         $canDownloadBlobList = $this->canDownloadFromUrl($blobListAddress, "<?xml version=\"1.0\" encoding=\"utf-8\"?" . "><EnumerationResults");
         $canDownloadBlob = $this->canDownloadFromUrl($blobAddress, $blobContent);
         if (!is_null($acl->getPublicAccess()) && $acl->getPublicAccess() == PublicAccessType::CONTAINER_AND_BLOBS) {
             // Full public read access: Container and blob data can be read via anonymous request.
             // Clients can enumerate blobs within the $container via anonymous request,
             // but cannot enumerate containers within the storage account.
             $this->assertTrue($canDownloadBlobList, '$canDownloadBlobList when ' . $acl->getPublicAccess());
             $this->assertTrue($canDownloadBlob, '$canDownloadBlob when ' . $acl->getPublicAccess());
         } else {
             if (!is_null($acl->getPublicAccess()) && $acl->getPublicAccess() == PublicAccessType::BLOBS_ONLY) {
                 // Public read access for blobs only: Blob data within this container
                 // can be read via anonymous request, but $container data is not available.
                 // Clients cannot enumerate blobs within the $container via anonymous request.
                 $this->assertFalse($canDownloadBlobList, '$canDownloadBlobList when ' . $acl->getPublicAccess());
                 $this->assertTrue($canDownloadBlob, '$canDownloadBlob when ' . $acl->getPublicAccess());
             } else {
                 // No public read access: Container and blob data can be read by the account owner only.
                 $this->assertFalse($canDownloadBlobList, '$canDownloadBlobList when ' . $acl->getPublicAccess());
                 $this->assertFalse($canDownloadBlob, '$canDownloadBlob when ' . $acl->getPublicAccess());
             }
         }
     }
 }
 /**
  * @covers WindowsAzure\Table\TableRestProxy::batch
  * @covers WindowsAzure\Table\TableRestProxy::insertEntity
  */
 private function batchPositiveOuter($firstConcurType, $seed)
 {
     // The random here is not to generate random values, but to
     // get a good mix of values in the table entities.
     mt_srand($seed);
     $concurTypes = ConcurType::values();
     $mutatePivots = MutatePivot::values();
     $opTypes = OpType::values();
     // Main loop.
     foreach ($opTypes as $firstOpType) {
         if (!is_null($this->expectConcurrencyFailure($firstOpType, $firstConcurType))) {
             // Want to know there is at least one part that does not fail.
             continue;
         }
         if (Configuration::isEmulated() && ($firstOpType == OpType::insertOrMergeEntity || $firstOpType == OpType::insertOrReplaceEntity)) {
             // Emulator does not support these operations.
             continue;
         }
         $simpleEntities = TableServiceFunctionalTestData::getSimpleEntities(6);
         $configs = array();
         $firstConfig = new BatchWorkerConfig();
         $firstConfig->concurType = $firstConcurType;
         $firstConfig->opType = $firstOpType;
         $firstConfig->ent = $simpleEntities[0];
         $firstConfig->mutatePivot = $mutatePivots[mt_rand(0, count($mutatePivots))];
         array_push($configs, $firstConfig);
         for ($i = 1; $i < count($simpleEntities); $i++) {
             $config = new BatchWorkerConfig();
             while (!is_null($this->expectConcurrencyFailure($config->opType, $config->concurType))) {
                 $config->concurType = $concurTypes[mt_rand(0, count($concurTypes))];
                 $config->opType = $opTypes[mt_rand(0, count($opTypes))];
                 if (Configuration::isEmulated()) {
                     if ($config->opType == OpType::insertOrMergeEntity) {
                         $config->opType = OpType::mergeEntity;
                     }
                     if ($config->opType == OpType::insertOrReplaceEntity) {
                         $config->opType = OpType::updateEntity;
                     }
                 }
             }
             $config->mutatePivot = $mutatePivots[mt_rand(0, count($mutatePivots) - 1)];
             $config->ent = $simpleEntities[$i];
             array_push($configs, $config);
         }
         for ($i = 0; $i <= 1; $i++) {
             $options = $i == 0 ? null : new TableServiceOptions();
             if (Configuration::isEmulated()) {
                 // The emulator has trouble with some batches.
                 for ($j = 0; $j < count($configs); $j++) {
                     $tmpconfigs = array();
                     $tmpconfigs[] = $configs[$j];
                     $this->batchWorker($tmpconfigs, $options);
                 }
             } else {
                 $this->batchWorker($configs, $options);
             }
         }
     }
 }
 static function getInterestingQueryTablesOptions()
 {
     $ret = array();
     $options = new QueryTablesOptions();
     array_push($ret, $options);
     $options = new QueryTablesOptions();
     $options->setTop(2);
     $options->setPrefix(self::$nonExistTablePrefix);
     array_push($ret, $options);
     $options = new QueryTablesOptions();
     $options->setTop(-2);
     array_push($ret, $options);
     $options = new QueryTablesOptions();
     $filter = Filter::applyEq(Filter::applyConstant(self::$TEST_TABLE_NAMES[1]), Filter::applyPropertyName('TableName'));
     $options->setFilter($filter);
     array_push($ret, $options);
     $options = new QueryTablesOptions();
     $filter = Filter::applyEq(Filter::applyConstant(self::$TEST_TABLE_NAMES[2]), Filter::applyPropertyName('TableName'));
     $options->setFilter($filter);
     array_push($ret, $options);
     $options = new QueryTablesOptions();
     $filter = Filter::applyAnd(Filter::applyEq(Filter::applyConstant(self::$TEST_TABLE_NAMES[1]), Filter::applyPropertyName('TableName')), Filter::applyEq(Filter::applyConstant(self::$TEST_TABLE_NAMES[2]), Filter::applyPropertyName('TableName')));
     $options->setFilter($filter);
     array_push($ret, $options);
     $options = new QueryTablesOptions();
     $filter = Filter::applyAnd(Filter::applyGe(Filter::applyPropertyName('TableName'), Filter::applyConstant(self::$TEST_TABLE_NAMES[1])), Filter::applyLe(Filter::applyPropertyName('TableName'), Filter::applyConstant(self::$TEST_TABLE_NAMES[2])));
     $options->setFilter($filter);
     array_push($ret, $options);
     $options = new QueryTablesOptions();
     $filter = Filter::applyOr(Filter::applyGe(Filter::applyPropertyName('TableName'), Filter::applyConstant(self::$TEST_TABLE_NAMES[1])), Filter::applyGe(Filter::applyPropertyName('TableName'), Filter::applyConstant(self::$TEST_TABLE_NAMES[2])));
     $options->setFilter($filter);
     array_push($ret, $options);
     $options = new QueryTablesOptions();
     $filter = Filter::applyAnd(Filter::applyEq(Filter::applyPropertyName('TableName'), Filter::applyConstant(self::$TEST_TABLE_NAMES[1])), Filter::applyGe(Filter::applyPropertyName('TableName'), Filter::applyConstant(self::$TEST_TABLE_NAMES[0])));
     $options->setFilter($filter);
     array_push($ret, $options);
     $options = new QueryTablesOptions();
     $filter = Filter::applyOr(Filter::applyEq(Filter::applyPropertyName('TableName'), Filter::applyConstant(self::$TEST_TABLE_NAMES[1])), Filter::applyGe(Filter::applyPropertyName('TableName'), Filter::applyConstant(self::$TEST_TABLE_NAMES[2])));
     $options->setFilter($filter);
     array_push($ret, $options);
     $options = new QueryTablesOptions();
     $filter = Filter::applyOr(Filter::applyEq(Filter::applyPropertyName('TableName'), Filter::applyConstant(self::$TEST_TABLE_NAMES[1])), Filter::applyEq(Filter::applyPropertyName('TableName'), Filter::applyConstant(self::$TEST_TABLE_NAMES[2])));
     $options->setFilter($filter);
     array_push($ret, $options);
     $options = new QueryTablesOptions();
     $filter = Filter::applyOr(Filter::applyEq(Filter::applyConstant(self::$TEST_TABLE_NAMES[1]), Filter::applyPropertyName('TableName')), Filter::applyEq(Filter::applyConstant(self::$TEST_TABLE_NAMES[2]), Filter::applyPropertyName('TableName')));
     $options->setFilter($filter);
     array_push($ret, $options);
     $options = new QueryTablesOptions();
     $options->setPrefix(self::$nonExistTablePrefix);
     array_push($ret, $options);
     if (!Configuration::isEmulated()) {
         $options = new QueryTablesOptions();
         $options->setPrefix(self::$testUniqueId);
         array_push($ret, $options);
     }
     $options = new QueryTablesOptions();
     $nextTableName = self::$TEST_TABLE_NAMES[1];
     $options->setNextTableName($nextTableName);
     array_push($ret, $options);
     $options = new QueryTablesOptions();
     $nextTableName = self::$nonExistTablePrefix;
     $options->setNextTableName($nextTableName);
     array_push($ret, $options);
     return $ret;
 }
 /**
  * @covers WindowsAzure\Queue\QueueRestProxy::getServiceProperties
  * @covers WindowsAzure\Queue\QueueRestProxy::setServiceProperties
  */
 public function testSetServicePropertiesWorks()
 {
     // Arrange
     // Act
     $shouldReturn = false;
     try {
         $props = $this->restProxy->getServiceProperties()->getValue();
         $this->assertFalse(Configuration::isEmulated(), 'Should succeed when not running in emulator');
     } catch (ServiceException $e) {
         // Expect failure in emulator, as v1.6 doesn't support this method
         if (Configuration::isEmulated()) {
             $this->assertEquals(400, $e->getCode(), 'getCode');
             $shouldReturn = true;
         }
     }
     if ($shouldReturn) {
         return;
     }
     $props->getLogging()->setRead(true);
     $this->restProxy->setServiceProperties($props);
     $props = $this->restProxy->getServiceProperties()->getValue();
     // Assert
     $this->assertNotNull($props, '$props');
     $this->assertNotNull($props->getLogging(), '$props->getLogging');
     $this->assertNotNull($props->getLogging()->getRetentionPolicy(), '$props->getLogging()->getRetentionPolicy');
     $this->assertNotNull($props->getLogging()->getVersion(), '$props->getLogging()->getVersion');
     $this->assertTrue($props->getLogging()->getRead(), '$props->getLogging()->getRead');
     $this->assertNotNull($props->getMetrics()->getRetentionPolicy(), '$props->getMetrics()->getRetentionPolicy');
     $this->assertNotNull($props->getMetrics()->getVersion(), '$props->getMetrics()->getVersion');
 }
 /**
  * @covers WindowsAzure\Common\Configuration::isEmulated
  */
 public function testIsEmulated()
 {
     // Test
     $actual = Configuration::isEmulated();
     // Assert
     $this->assertTrue(isset($actual));
 }
 /**
  * @covers WindowsAzure\Queue\QueueRestProxy::setServiceProperties
  */
 public function testSetServicePropertiesNullOptions4()
 {
     $serviceProperties = QueueServiceFunctionalTestData::getDefaultServiceProperties();
     try {
         $this->restProxy->setServiceProperties($serviceProperties, null);
         $this->assertFalse(Configuration::isEmulated(), 'service properties should throw in emulator');
     } catch (ServiceException $e) {
         if (Configuration::isEmulated()) {
             // Setting is not supported in emulator
             $this->assertEquals(400, $e->getCode(), 'getCode');
         } else {
             throw $e;
         }
     }
 }
 /**
  * @covers WindowsAzure\Table\TableRestProxy::batch
  * @covers WindowsAzure\Table\TableRestProxy::insertEntity
  */
 public function testBatchAllOperationsTogetherWorks()
 {
     // Arrange
     $table = self::$TEST_TABLE_8;
     $partitionKey = '001';
     // Insert a few entities to allow updating them in batch
     $entity1 = new Entity();
     $entity1->setPartitionKey($partitionKey);
     $entity1->setRowKey('batchAllOperationsWorks-' . 1);
     $entity1->addProperty('test', EdmType::BOOLEAN, true);
     $entity1->addProperty('test2', EdmType::STRING, 'value');
     $entity1->addProperty('test3', EdmType::INT32, 3);
     $entity1->addProperty('test4', EdmType::INT64, '12345678901');
     $entity1->addProperty('test5', EdmType::DATETIME, new \DateTime());
     $entity1 = $this->restProxy->insertEntity($table, $entity1)->getEntity();
     $entity2 = new Entity();
     $entity2->setPartitionKey($partitionKey);
     $entity2->setRowKey('batchAllOperationsWorks-' . 2);
     $entity2->addProperty('test', EdmType::BOOLEAN, true);
     $entity2->addProperty('test2', EdmType::STRING, 'value');
     $entity2->addProperty('test3', EdmType::INT32, 3);
     $entity2->addProperty('test4', EdmType::INT64, '12345678901');
     $entity2->addProperty('test5', EdmType::DATETIME, new \DateTime());
     $entity2 = $this->restProxy->insertEntity($table, $entity2)->getEntity();
     $entity3 = new Entity();
     $entity3->setPartitionKey($partitionKey);
     $entity3->setRowKey('batchAllOperationsWorks-' . 3);
     $entity3->addProperty('test', EdmType::BOOLEAN, true);
     $entity3->addProperty('test2', EdmType::STRING, 'value');
     $entity3->addProperty('test3', EdmType::INT32, 3);
     $entity3->addProperty('test4', EdmType::INT64, '12345678901');
     $entity3->addProperty('test5', EdmType::DATETIME, new \DateTime());
     $entity3 = $this->restProxy->insertEntity($table, $entity3)->getEntity();
     $entity4 = new Entity();
     $entity4->setPartitionKey($partitionKey);
     $entity4->setRowKey('batchAllOperationsWorks-' . 4);
     $entity4->addProperty('test', EdmType::BOOLEAN, true);
     $entity4->addProperty('test2', EdmType::STRING, 'value');
     $entity4->addProperty('test3', EdmType::INT32, 3);
     $entity4->addProperty('test4', EdmType::INT64, '12345678901');
     $entity4->addProperty('test5', EdmType::DATETIME, new \DateTime());
     $entity4 = $this->restProxy->insertEntity($table, $entity4)->getEntity();
     // Act
     $batchOperations = new BatchOperations();
     $entity = new Entity();
     $entity->setPartitionKey($partitionKey);
     $entity->setRowKey('batchAllOperationsWorks');
     $entity->addProperty('test', EdmType::BOOLEAN, true);
     $entity->addProperty('test2', EdmType::STRING, 'value');
     $entity->addProperty('test3', EdmType::INT32, 3);
     $entity->addProperty('test4', EdmType::INT64, '12345678901');
     $entity->addProperty('test5', EdmType::DATETIME, new \DateTime());
     $batchOperations->addInsertEntity($table, $entity);
     $batchOperations->addDeleteEntity($table, $entity1->getPartitionKey(), $entity1->getRowKey(), $entity1->getEtag());
     $entity2->addProperty('test3', EdmType::INT32, 5);
     $batchOperations->addUpdateEntity($table, $entity2);
     $entity3->addProperty('test3', EdmType::INT32, 5);
     $batchOperations->addMergeEntity($table, $entity3);
     $entity4->addProperty('test3', EdmType::INT32, 5);
     // Use different behavior in the emulator, as v1.6 does not support this method
     if (!Configuration::isEmulated()) {
         $batchOperations->addInsertOrReplaceEntity($table, $entity4);
     } else {
         $batchOperations->addUpdateEntity($table, $entity4);
     }
     $entity5 = new Entity();
     $entity5->setPartitionKey($partitionKey);
     $entity5->setRowKey('batchAllOperationsWorks-' . 5);
     $entity5->addProperty('test', EdmType::BOOLEAN, true);
     $entity5->addProperty('test2', EdmType::STRING, 'value');
     $entity5->addProperty('test3', EdmType::INT32, 3);
     $entity5->addProperty('test4', EdmType::INT64, '12345678901');
     $entity5->addProperty('test5', EdmType::DATETIME, new \DateTime());
     // Use different behavior in the emulator, as v1.6 does not support this method
     if (Configuration::isEmulated()) {
         $batchOperations->addInsertEntity($table, $entity5);
     } else {
         $batchOperations->addInsertOrMergeEntity($table, $entity5);
     }
     $result = $this->restProxy->batch($batchOperations);
     // Assert
     $this->assertNotNull($result, '$result');
     $this->assertEquals(count($batchOperations->getOperations()), count($result->getEntries()), 'count($result->getEntries())');
     $ents = $result->getEntries();
     $this->assertTrue($ents[0] instanceof InsertEntityResult, '$result->getEntries()->get(0)->getClass()');
     $this->assertTrue(is_string($ents[1]), '$result->getEntries()->get(1)->getClass()');
     $this->assertTrue($ents[2] instanceof UpdateEntityResult, '$result->getEntries()->get(2)->getClass()');
     $this->assertTrue($ents[3] instanceof UpdateEntityResult, '$result->getEntries()->get(3)->getClass()');
     $this->assertTrue($ents[4] instanceof UpdateEntityResult, '$result->getEntries()->get(4)->getClass()');
     if (Configuration::isEmulated()) {
         $this->assertTrue($ents[5] instanceof InsertEntityResult, '$result->getEntries()->get(5)->getClass()');
     } else {
         $this->assertTrue($ents[5] instanceof UpdateEntityResult, '$result->getEntries()->get(5)->getClass()');
     }
 }