public function testQueryRange() { $rangeQuery = new RangeQuery($this->createManager(), 'test', 'sdktest'); $rangeQuery->rangeLessThan(time()); $data = $this->storage->executeRangeQuery($rangeQuery, 'test', array('dist', 'range'), function ($row) { return $row; }); $this->assertTrue(count($data) > 0); }
public function executeRangeQuery(RangeQuery $query, $storageName, $key, \Closure $hydrateRow = null) { $headers = ['Content-Type' => 'application/atom+xml', 'x-ms-date' => $this->now(), 'Content-Length' => 0]; $filters = ["PartitionKey eq " . $this->quoteFilterValue($query->getPartitionKey())]; foreach ($query->getConditions() as $condition) { if (!in_array($condition[0], ['eq', 'neq', 'le', 'lt', 'ge', 'gt'])) { throw new \InvalidArgumentException("Windows Azure Table only supports eq, neq, le, lt, ge, gt as conditions."); } $filters[] = $key[1] . " " . $condition[0] . " " . $this->quoteFilterValue($condition[1]); } // TODO: This sucks $tableName = $storageName; $url = $this->baseUrl . '/' . $tableName . '()?$filter=' . rawurlencode(implode(' ', $filters)); if ($query->getLimit()) { $url .= '&$top=' . $query->getLimit(); } $response = $this->request('GET', $url, '', $headers); if ($response->getStatusCode() >= 400) { $this->convertResponseToException($response); } $dom = new \DomDocument('1.0', 'UTF-8'); $dom->loadXML($response->getBody()); $xpath = new \DOMXpath($dom); $xpath->registerNamespace('d', 'http://schemas.microsoft.com/ado/2007/08/dataservices'); $xpath->registerNamespace('m', 'http://schemas.microsoft.com/ado/2007/08/dataservices/metadata'); $xpath->registerNamespace('atom', "http://www.w3.org/2005/Atom"); $entries = $xpath->evaluate('/atom:feed/atom:entry'); $results = []; foreach ($entries as $entry) { $data = $this->createRow($key, $xpath, $entry); $results[] = $hydrateRow ? $hydrateRow($data) : $data; } return $results; }
/** * {@inheritDoc} */ public function executeRangeQuery(RangeQuery $query, $storageName, $key, \Closure $hydrateRow = null) { $filters = array("PartitionKey eq " . $this->quoteFilterValue($query->getPartitionKey())); foreach ($query->getConditions() as $condition) { if (!in_array($condition[0], array('eq', 'neq', 'le', 'lt', 'ge', 'gt'))) { throw new \InvalidArgumentException("Windows Azure Table only supports eq, neq, le, lt, ge, gt as conditions."); } $filters[] = "RowKey " . $condition[0] . " " . $this->quoteFilterValue($condition[1]); } $filter = '(' . implode(" and ", $filters) . ')'; $result = $this->client->queryEntities($storageName, $filter); $rows = array(); foreach ($result->getEntities() as $entity) { $row = $this->getProperties($entity); $rows[] = $hydrateRow ? $hydrateRow($row) : $row; } return $rows; }
/** * @covers ::execute */ public function testWrongExecute() { $this->entityManager->method('unwrap')->willReturn(new DoctrineCacheStorage(new ArrayCache())); $this->setExpectedException(RuntimeException::class); $this->object->execute(); }