private static function getNewEntity() { if (is_null(self::$curPartition) || self::$curPartition == count(self::$Partitions) - 1) { self::$curPartition = 0; self::$curRowKey = TableServiceFunctionalTestData::getNewKey(); } else { self::$curPartition++; } $entity = new Entity(); $entity->setPartitionKey(self::$Partitions[self::$curPartition]); $entity->setRowKey(self::$curRowKey); return $entity; }
/** * @covers MicrosoftAzure\Storage\Table\TableRestProxy::deleteEntity */ public function testDeleteEntityTableNull() { $table = TableServiceFunctionalTestData::$testTableNames[0]; try { $this->restProxy->deleteEntity(null, TableServiceFunctionalTestData::getNewKey(), TableServiceFunctionalTestData::getNewKey()); $this->fail('Expect null table name to throw'); } catch (\InvalidArgumentException $e) { $this->assertEquals(sprintf(Resources::NULL_OR_EMPTY_MSG, 'table'), $e->getMessage(), 'Expect error message'); $this->assertEquals(0, $e->getCode(), 'Expected error code'); } $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); } } } } } }
/** * @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; }