/**
  * @covers WindowsAzure\Table\Models\BatchResult::setEntries
  * @covers WindowsAzure\Table\Models\BatchResult::getEntries
  */
 public function testSetEntries()
 {
     // Setup
     $batchResult = new BatchResult();
     $entries = array();
     // Test
     $batchResult->setEntries($entries);
     // Assert
     $this->assertEquals($entries, $batchResult->getEntries());
 }
Example #2
0
 /**
  * Creates BatchResult object.
  * 
  * @param string            $body           The HTTP response body.
  * @param array             $operations     The batch operations.
  * @param array             $contexts       The batch operations context.
  * @param IAtomReaderWriter $atomSerializer The Atom reader and writer.
  * @param IMimeReaderWriter $mimeSerializer The MIME reader and writer.
  * 
  * @return \WindowsAzure\Table\Models\BatchResult
  * 
  * @throws \InvalidArgumentException 
  */
 public static function create($body, $operations, $contexts, $atomSerializer, $mimeSerializer)
 {
     $result = new BatchResult();
     $responses = self::_constructResponses($body, $mimeSerializer);
     $callbackName = __CLASS__ . '::_compareUsingContentId';
     $count = count($responses);
     $entries = array();
     // Sort $responses based on Content-ID so they match order of $operations.
     uasort($responses, $callbackName);
     for ($i = 0; $i < $count; $i++) {
         $context = $contexts[$i];
         $response = $responses[$i];
         $operation = $operations[$i];
         $type = $operation->getType();
         $body = $response->getBody();
         $headers = $response->getHeader();
         try {
             HttpClient::throwIfError($response->getStatus(), $response->getReasonPhrase(), $response->getBody(), $context->getStatusCodes());
             switch ($type) {
                 case BatchOperationType::INSERT_ENTITY_OPERATION:
                     $entries[] = InsertEntityResult::create($body, $headers, $atomSerializer);
                     break;
                 case BatchOperationType::UPDATE_ENTITY_OPERATION:
                 case BatchOperationType::MERGE_ENTITY_OPERATION:
                 case BatchOperationType::INSERT_REPLACE_ENTITY_OPERATION:
                 case BatchOperationType::INSERT_MERGE_ENTITY_OPERATION:
                     $entries[] = UpdateEntityResult::create($headers);
                     break;
                 case BatchOperationType::DELETE_ENTITY_OPERATION:
                     $entries[] = Resources::BATCH_ENTITY_DEL_MSG;
                     break;
                 default:
                     throw new \InvalidArgumentException();
             }
         } catch (ServiceException $e) {
             $entries[] = BatchError::create($e, $response->getHeader());
         }
     }
     $result->setEntries($entries);
     return $result;
 }
 /**
  * Does batch of operations on the table service.
  * 
  * @param Models\BatchOperations     $batchOperations The operations to apply.
  * @param Models\TableServiceOptions $options         The optional parameters.
  * 
  * @return Models\BatchResult
  */
 public function batch($batchOperations, $options = null)
 {
     Validate::notNullOrEmpty($batchOperations, 'batchOperations');
     $method = Resources::HTTP_POST;
     $operations = $batchOperations->getOperations();
     $contexts = $this->_createOperationsContexts($operations);
     $mime = $this->_createBatchRequestBody($operations, $contexts);
     $body = $mime['body'];
     $headers = $mime['headers'];
     $postParams = array();
     $queryParams = array();
     $statusCode = Resources::STATUS_ACCEPTED;
     $path = '$batch';
     if (is_null($options)) {
         $options = new TableServiceOptions();
     }
     $this->addOptionalQueryParam($queryParams, Resources::QP_TIMEOUT, $options->getTimeout());
     $response = $this->send($method, $headers, $queryParams, $postParams, $path, $statusCode, $body);
     return BatchResult::create($response->getBody(), $operations, $contexts, $this->_atomSerializer, $this->_mimeSerializer);
 }