private function ValidateQueryResult($queryResult, QueryType $queryType, $methodName) { if (!$queryResult instanceof QueryResult) { throw ODataException::createInternalServerError(Messages::queryProviderReturnsNonQueryResult($methodName)); } if ($queryType == QueryType::COUNT() || $queryType == QueryType::ENTITIES_WITH_COUNT()) { //and the provider is supposed to handle the ordered paging they must return a count! if ($this->queryProvider->handlesOrderedPaging() && !is_numeric($queryResult->count)) { throw ODataException::createInternalServerError(Messages::queryProviderResultCountMissing($methodName, $queryType)); } //If POData is supposed to handle the ordered aging they must return results! (possibly empty) if (!$this->queryProvider->handlesOrderedPaging() && !is_array($queryResult->results)) { throw ODataException::createInternalServerError(Messages::queryProviderResultsMissing($methodName, $queryType)); } } if (($queryType == QueryType::ENTITIES() || $queryType == QueryType::ENTITIES_WITH_COUNT()) && !is_array($queryResult->results)) { throw ODataException::createInternalServerError(Messages::queryProviderResultsMissing($methodName, $queryType)); } }
public function testGetRelatedResourceSetReturnsCountWhenQueryTypeIsEntitiesWithCountProviderDoesNotHandlePaging() { $orderBy = null; $top = 10; $skip = 10; $fakeQueryResult = new QueryResult(); $fakeQueryResult->count = 444; //irrelevant $fakeQueryResult->results = null; //Because the provider does NOT handle paging and this request needs a count, the result must have results collection to calculate count from Phockito::when($this->mockQueryProvider->handlesOrderedPaging())->return(false); $fakeSourceEntity = new \stdClass(); Phockito::when($this->mockQueryProvider->getRelatedResourceSet(QueryType::ENTITIES_WITH_COUNT(), $this->mockResourceSet, $fakeSourceEntity, $this->mockResourceSet2, $this->mockResourceProperty, $this->mockFilterInfo, $orderBy, $top, $skip))->return($fakeQueryResult); $wrapper = $this->getMockedWrapper(); try { $wrapper->getRelatedResourceSet(QueryType::ENTITIES_WITH_COUNT(), $this->mockResourceSet, $fakeSourceEntity, $this->mockResourceSet2, $this->mockResourceProperty, $this->mockFilterInfo, $orderBy, $top, $skip); $this->fail("expected exception not thrown"); } catch (ODataException $ex) { $this->assertEquals(Messages::queryProviderResultsMissing("IQueryProvider::getRelatedResourceSet", QueryType::ENTITIES_WITH_COUNT()), $ex->getMessage()); $this->assertEquals(500, $ex->getStatusCode()); } }