/**
  * @covers MicrosoftAzure\Storage\ServiceBus\ServiceBusRestProxy::createTable
  * @covers MicrosoftAzure\Storage\ServiceBus\ServiceBusRestProxy::deleteTable
  */
 protected function clearTable($table)
 {
     $index = array_search($table, TableServiceFunctionalTestData::$testTableNames);
     if ($index !== false) {
         // This is a well-known table, so need to create a new one to replace it.
         TableServiceFunctionalTestData::$testTableNames[$index] = TableServiceFunctionalTestData::getInterestingTableName();
         $this->restProxy->createTable(TableServiceFunctionalTestData::$testTableNames[$index]);
     }
     $this->restProxy->deleteTable($table);
 }
 public static function tearDownAfterClass()
 {
     if (self::$isOneTimeSetup) {
         $integrationTestBase = new IntegrationTestBase();
         $integrationTestBase->setUp();
         if (!$integrationTestBase->isEmulated()) {
             $serviceProperties = TableServiceFunctionalTestData::getDefaultServiceProperties();
             $integrationTestBase->restProxy->setServiceProperties($serviceProperties);
         }
         self::$isOneTimeSetup = false;
     }
     parent::tearDownAfterClass();
 }
 /**
  * @covers MicrosoftAzure\Storage\Table\TableRestProxy::insertOrReplaceEntity
  */
 public function testInsertOrReplaceEntityOptionsNull()
 {
     $table = TableServiceFunctionalTestData::$testTableNames[0];
     try {
         $this->restProxy->insertOrReplaceEntity($table, TableServiceFunctionalTestData::getSimpleEntity(), null);
         $this->assertFalse($this->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 ($this->isEmulated()) {
             $this->assertEquals(TestResources::STATUS_NOT_FOUND, $e->getCode(), 'getCode');
         }
     }
     $this->clearTable($table);
 }
 static function mutateEntity($ent, $pivot)
 {
     if ($pivot == MutatePivot::CHANGE_VALUES) {
         self::mutateEntityChangeValues($ent);
     } else {
         if ($pivot == MutatePivot::ADD_PROPERTY) {
             $ent->addProperty('BOOLEAN' . TableServiceFunctionalTestData::getNewKey(), EdmType::BOOLEAN, true);
             $ent->addProperty('DATETIME' . TableServiceFunctionalTestData::getNewKey(), EdmType::DATETIME, Utilities::convertToDateTime('2012-01-26T18:26:19.0000473Z'));
             $ent->addProperty('DOUBLE' . TableServiceFunctionalTestData::getNewKey(), EdmType::DOUBLE, 12345678901);
             $ent->addProperty('GUID' . TableServiceFunctionalTestData::getNewKey(), EdmType::GUID, '90ab64d6-d3f8-49ec-b837-b8b5b6367b74');
             $ent->addProperty('INT32' . TableServiceFunctionalTestData::getNewKey(), EdmType::INT32, 23);
             $ent->addProperty('INT64' . TableServiceFunctionalTestData::getNewKey(), EdmType::INT64, '-1');
             $ent->addProperty('STRING' . TableServiceFunctionalTestData::getNewKey(), EdmType::STRING, 'this is a test!');
         } else {
             if ($pivot == MutatePivot::REMOVE_PROPERTY) {
                 $propToRemove = null;
                 foreach ($ent->getProperties() as $propName => $propValue) {
                     // Don't mess with the keys.
                     if ($propName == 'PartitionKey' || $propName == 'RowKey' || $propName == 'Timestamp') {
                         continue;
                     }
                     $propToRemove = $propName;
                     break;
                 }
                 $props = $ent->getProperties();
                 unset($props[$propToRemove]);
             } else {
                 if ($pivot == MutatePivot::NULL_PROPERTY) {
                     foreach ($ent->getProperties() as $propName => $propValue) {
                         // Don't mess with the keys.
                         if ($propName == 'PartitionKey' || $propName == 'RowKey' || $propName == 'Timestamp') {
                             continue;
                         }
                         $propValue->setValue(null);
                     }
                 }
             }
         }
     }
 }
 public function testCheckEntity()
 {
     $entity = new Entity();
     $etag = 'custom $etag';
     $partitionKey = 'custom partiton key';
     $rowKey = 'custom rowkey';
     $dates = TableServiceFunctionalTestData::getInterestingGoodDates();
     $timestamp = $dates[1];
     $property = new Property();
     $property->setEdmType(EdmType::INT32);
     $property->setValue(1234);
     $name = 'my name';
     $edmType = EdmType::STRING;
     $value = 'my value';
     $properties = array();
     $properties['goo'] = new Property();
     $properties['moo'] = new Property();
     $this->assertNotNull($entity, 'Default Entity');
     $this->assertNull($entity->getProperties(), 'Default Entity->getProperties');
     $this->assertNull($entity->getETag(), 'Default Entity->getETag');
     $this->assertNull($entity->getPartitionKey(), 'Default Entity->getPartitionKey');
     $this->assertNull($entity->getRowKey(), 'Default Entity->getRowKey');
     $this->assertNull($entity->getTimestamp(), 'Default Entity->getTimestamp');
     $this->assertNull($entity->getProperty('foo'), 'Default Entity->getProperty(\'foo\')');
     $this->assertNull($entity->getPropertyValue('foo'), 'Default Entity->tryGtPropertyValue(\'foo\')');
     // Now set some things.
     $entity->setETag($etag);
     $entity->setPartitionKey($partitionKey);
     $entity->setRowKey($rowKey);
     $entity->setTimestamp($timestamp);
     $this->assertEquals($etag, $entity->getETag(), 'Default Entity->getETag');
     $this->assertEquals($partitionKey, $entity->getPartitionKey(), 'Default Entity->getPartitionKey');
     $this->assertEquals($rowKey, $entity->getRowKey(), 'Default Entity->getRowKey');
     $this->assertEquals($timestamp, $entity->getTimestamp(), 'Default Entity->getTimestamp');
     $entity->setProperty($name, $property);
     $this->assertEquals($property, $entity->getProperty($name), 'Default Entity->getProperty(\'' . $name . '\')');
     $entity->addProperty($name, $edmType, $value);
     $this->assertEquals($value, $entity->getPropertyValue($name), 'Default Entity->getPropertyValue(\'' . $name . '\')');
     $this->assertEquals($edmType, $entity->getProperty($name)->getEdmType(), 'Default Entity->getProperty(\'' . $name . '\')->getEdmType');
     $this->assertEquals($value, $entity->getProperty($name)->getValue(), 'Default Entity->getProperty(\'' . $name . '\')->getValue');
     $this->assertTrue($property != $entity->getProperty($name), 'Default Entity->getProperty(\'' . $name . '\') changed');
     $entity->setProperties($properties);
     $this->assertNotNull($entity->getProperties(), 'Default Entity->getProperties');
     $this->assertEquals($properties, $entity->getProperties(), 'Default Entity->getProperties');
 }
 /**
  * @covers MicrosoftAzure\Storage\Table\TableRestProxy::queryEntities
  */
 public function testQueryEntitiesBinaryLevel1()
 {
     // The emulator has problems with non-standard queries tested here.
     $this->skipIfEmulated();
     $interestingqueryEntitiesOptions = self::addBinaryFilter('BINARY', EdmType::BINARY, TableServiceFunctionalTestData::getInterestingGoodBinaries());
     foreach ($interestingqueryEntitiesOptions as $options) {
         $this->queryEntitiesWorker($options);
     }
 }
 /**
  * @covers MicrosoftAzure\Storage\Table\TableRestProxy::updateEntity
  */
 private function createTargetEntity($table, $initialEnt, $concurType, $mutatePivot)
 {
     $targetEnt = TableServiceFunctionalTestUtils::cloneEntity($initialEnt);
     // Update the entity/table state to get the requested concurrency type error.
     switch ($concurType) {
         case ConcurType::NO_KEY_MATCH:
             // Mutate the keys to not match.
             $targetEnt->setRowKey(TableServiceFunctionalTestData::getNewKey());
             break;
         case ConcurType::KEY_MATCH_NO_ETAG:
             $targetEnt->setETag(null);
             break;
         case ConcurType::KEY_MATCH_ETAG_MISMATCH:
             $newETag = $this->restProxy->updateEntity($table, $initialEnt)->getETag();
             $initialEnt->setETag($newETag);
             // Now the $targetEnt ETag will not match.
             $this->assertTrue($targetEnt->getETag() != $initialEnt->getETag(), 'targetEnt->ETag(\'' . $targetEnt->getETag() . '\') !=  updated->ETag(\'' . $initialEnt->getETag() . '\')');
             break;
         case ConcurType::KEY_MATCH_ETAG_MATCH:
             // Don't worry here.
             break;
     }
     // Mutate the properties.
     TableServiceFunctionalTestUtils::mutateEntity($targetEnt, $mutatePivot);
     return $targetEnt;
 }