/** * Filter the result based on supplied price range * @return ViewModel */ public function filterAction() { $response = ['success' => true, 'hotels' => []]; try { $minPrice = (int) $this->params()->fromQuery('minPrice', $this->_config->minPriceDefault); $maxPrice = (int) $this->params()->fromQuery('maxPrice', $this->_config->maxPriceDefault); $_zendRest = $this->getServiceLocator()->get('ZendRestClient'); $_hotel = new HotelRestClient($this->_config, $_zendRest); $response['hotels'] = $_hotel->findBy(['min' => $minPrice, 'max' => $maxPrice]); } catch (\Exception $exception) { error_log($exception->getMessage()); $response['success'] = false; } $viewModel = new ViewModel($response); /** * ensure no layout is used. We are in AJAX call */ $viewModel->setTerminal(true); return $viewModel; }
public function testFilterByPrice() { $hotels = $this->model->findBy(['min' => 140, 'max' => 150]); $this->assertTrue(is_array($hotels)); $this->assertTrue(count($hotels) == 3); }