/** * Displays a list of the most recent feeds, reverse date order, to the user. * * It's intended as a starting off point to the rest of the application. * * @return array|ViewModel */ public function indexAction() { if (!is_null($this->_cache)) { if (!$this->_cache->hasItem(self::KEY_ALL_RESULTS)) { $resultset = $this->_feedTable->fetchMostRecentFeeds(self::DEFAULT_FEED_COUNT); $this->_cache->setItem(self::KEY_ALL_RESULTS, $resultset->toArray()); } else { $resultset = $this->_cache->getItem(self::KEY_ALL_RESULTS); } } else { $resultset = $this->_feedTable->fetchMostRecentFeeds(self::DEFAULT_FEED_COUNT); } $paginator = $this->getPaginator($resultset); $paginator->setCurrentPageNumber($this->params()->fromRoute('page', self::DEFAULT_PAGE)); $paginator->setItemCountPerPage($this->params()->fromRoute('perPage', self::DEFAULT_RECORDS_PER_PAGE)); return new ViewModel(array('paginator' => $paginator, 'feedCount' => self::DEFAULT_FEED_COUNT, 'messages' => array('info' => $this->flashMessenger()->hasInfoMessages(), 'error' => $this->flashMessenger()->hasErrorMessages()))); }
public function testFetchMostRecentFeedsWhenLimitNotSuppliedLimitDefaultsTo5() { $resultSet = new ResultSet(); $record = new FeedModel(); $record->exchangeArray($this->_recordData); $limit = 5; $resultSet->initialize(array($record)); $mockSql = \Mockery::mock('Zend\\Db\\Sql\\Select'); $mockSql->shouldReceive('select')->andReturn($mockSql); $mockSql->shouldReceive('limit')->with($limit)->times(1)->andReturn($mockSql); $mockSql->shouldReceive('order')->times(1)->with("feedDate DESC, feedTime DESC")->andReturn($resultSet); $mockTableGateway = \Mockery::mock('Zend\\Db\\TableGateway\\TableGateway'); $mockTableGateway->shouldReceive('getSql')->andReturn($mockSql); $mockTableGateway->shouldReceive('selectWith')->times(1)->with($mockSql)->andReturn($resultSet); $mockFeedTable = new FeedTable($mockTableGateway); $this->assertEquals($resultSet, $mockFeedTable->fetchMostRecentFeeds()); }