/**
  * Creates new QueryEntitiesResult instance.
  * 
  * @param array $headers  The HTTP response headers.
  * @param array $entities The entities.
  * 
  * @return QueryEntitiesResult
  */
 public static function create($headers, $entities)
 {
     $result = new QueryEntitiesResult();
     $headers = array_change_key_case($headers);
     $nextPK = Utilities::tryGetValue($headers, Resources::X_MS_CONTINUATION_NEXTPARTITIONKEY);
     $nextRK = Utilities::tryGetValue($headers, Resources::X_MS_CONTINUATION_NEXTROWKEY);
     $result->setEntities($entities);
     $result->setNextPartitionKey($nextPK);
     $result->setNextRowKey($nextRK);
     return $result;
 }
 /**
  * @covers WindowsAzure\Table\Models\QueryEntitiesResult::setEntities
  * @covers WindowsAzure\Table\Models\QueryEntitiesResult::getEntities
  */
 public function testSetEntities()
 {
     // Setup
     $result = new QueryEntitiesResult();
     $expected = array();
     // Test
     $result->setEntities($expected);
     // Assert
     $this->assertEquals($expected, $result->getEntities());
 }
 public function testGc()
 {
     $client = $this->getMockClient();
     $client->shouldReceive('queryEntities')->andThrow(new ServiceException('404'));
     $sessionHandler = new SessionHandler($client);
     $this->assertFalse($sessionHandler->gc(0));
     $client = $this->getMockClient();
     $queryEntitiesResult = new QueryEntitiesResult();
     $entity = new Entity();
     $entity->setRowKey('id');
     $entity->addProperty('data', null, base64_encode('data'));
     $queryEntitiesResult->setEntities(array($entity));
     $client->shouldReceive('queryEntities')->andReturn($queryEntitiesResult);
     $client->shouldReceive('deleteEntity');
     $sessionHandler = new SessionHandler($client);
     $this->assertTrue($sessionHandler->gc(0));
 }
 /**
  * Quries entities for the given table name
  * 
  * @param string                                           $table   The name of
  * the table.
  * @param Models\QueryEntitiesOptions|string|Models\Filter $options Coule be
  * optional parameters, query string or filter to apply.
  * 
  * @return Models\QueryEntitiesResult
  * 
  * @see http://msdn.microsoft.com/en-us/library/windowsazure/dd179421.aspx
  */
 public function queryEntities($table, $options = null)
 {
     Validate::isString($table, 'table');
     Validate::notNullOrEmpty($table, 'table');
     $method = Resources::HTTP_GET;
     $headers = array();
     $postParams = array();
     $queryParams = array();
     $statusCode = Resources::STATUS_OK;
     $path = $table;
     if (is_null($options)) {
         $options = new QueryEntitiesOptions();
     } else {
         if (is_string($options)) {
             $queryString = $options;
             $options = new QueryEntitiesOptions();
             $options->setFilter(Filter::applyQueryString($queryString));
         } else {
             if ($options instanceof Filter) {
                 $filter = $options;
                 $options = new QueryEntitiesOptions();
                 $options->setFilter($filter);
             }
         }
     }
     $queryParams = $this->_addOptionalQuery($queryParams, $options->getQuery());
     $this->addOptionalQueryParam($queryParams, Resources::QP_TIMEOUT, $options->getTimeout());
     $this->addOptionalQueryParam($queryParams, Resources::QP_NEXT_PK, $options->getNextPartitionKey());
     $this->addOptionalQueryParam($queryParams, Resources::QP_NEXT_RK, $options->getNextRowKey());
     $this->addOptionalHeader($headers, Resources::CONTENT_TYPE, Resources::XML_ATOM_CONTENT_TYPE);
     if (!is_null($options->getQuery())) {
         $dsHeader = Resources::DATA_SERVICE_VERSION;
         $maxdsValue = Resources::MAX_DATA_SERVICE_VERSION_VALUE;
         $fields = $options->getQuery()->getSelectFields();
         $hasSelect = !empty($fields);
         if ($hasSelect) {
             $this->addOptionalHeader($headers, $dsHeader, $maxdsValue);
         }
     }
     $response = $this->send($method, $headers, $queryParams, $postParams, $path, $statusCode);
     $entities = $this->_atomSerializer->parseEntities($response->getBody());
     return QueryEntitiesResult::create($response->getHeader(), $entities);
 }