示例#1
0
 public function testIndexAction_WithUnsupportedTypeException()
 {
     $this->filterResultsServiceMock->expects($this->once())->method('getFilteredResults')->will($this->throwException(new UnsupportedTypeException(sprintf('Unsupported condition type: %s', '$inarray'))));
     $result = $this->controller->dispatch(new Request());
     $this->assertResponseStatusCode(Response::STATUS_CODE_200);
     $this->assertSame(['books' => []], $result);
     $messages = $this->controller->flashMessenger()->getCurrentErrorMessages();
     $this->assertSame(['Unsupported condition type: $inarray'], $messages);
 }
 public function testGetFilteredResult()
 {
     $bookEntity1 = $this->bookEntityProvider->getBookEntityWithRandomData();
     $bookEntity2 = $this->bookEntityProvider->getBookEntityWithRandomData();
     $books = [$bookEntity1, $bookEntity2];
     $this->bookRepositoryMock->expects($this->once())->method('findByQueryFilter')->will($this->returnValue($books));
     $result = $this->testedObj->getFilteredResults(new QueryFilter([], []));
     $this->assertSame($books, $result);
 }
示例#3
0
 public function indexAction()
 {
     try {
         $filterParams = $this->paginatorInfoFactory->prepareFilterParams($this->params()->fromQuery());
         $this->queryFilter->setQueryParameters($filterParams);
         /** @var PaginatorAdapter $paginator */
         $paginator = $this->service->getFilteredResults($this->queryFilter);
         $paginatorInfo = $this->paginatorInfoFactory->create($paginator->count());
         $paginatorInfo->preparePagesToShow();
         return ['books' => $paginator->getIterator(), 'paginator' => $paginatorInfo, 'route' => 'library/books/*', 'query' => $filterParams];
     } catch (QueryFilterException $e) {
         $this->flashMessenger()->addErrorMessage($e->getMessage());
     } catch (PaginationException $e) {
         $this->flashMessenger()->addErrorMessage($e->getMessage());
     }
     return array('books' => array());
 }
示例#4
0
 public function indexAction()
 {
     try {
         $this->queryFilter->setQueryParameters($this->paginatorInfoFactory->prepareFilterParams($this->params()->fromQuery()));
         /** @var PaginatorAdapter $paginator */
         $paginator = $this->service->getFilteredResults($this->queryFilter, $hydrationMode = Query::HYDRATE_ARRAY);
         $paginatorInfo = $this->paginatorInfoFactory->create($paginator->count());
         $data = array('data' => $paginator->getIterator());
         if ($paginatorInfo->shouldDisplay()) {
             $data['pagination'] = $paginatorInfo->toArray();
         }
         return new JsonModel($data);
     } catch (QueryFilterException $e) {
         throw new Exception\BadRequestException($e->getMessage(), Response::STATUS_CODE_400, $e);
     } catch (PaginationException $e) {
         throw new Exception\BadRequestException($e->getMessage(), Response::STATUS_CODE_400, $e);
     } catch (\PDOException $e) {
         throw new Exception\PDOServiceUnavailableException();
     }
 }