/**
  * @param array $criteria
  */
 protected function setupPaginator(array $criteria)
 {
     if (isset($criteria['page_size'])) {
         $this->paginator->setMaxPerPage($criteria['page_size']);
     }
     $page = isset($criteria['page']) ? $criteria['page'] : 1;
     if ($page > $this->paginator->getNbPages()) {
         throw new PageOutOfRangeException("Page {$page} does not exists.");
     }
     $this->paginator->setCurrentPage($page);
 }
 public function testCanPaginate()
 {
     $paginator = new PagerfantaPaginator(2);
     $expectedUsers = [['username' => 'luis', 'password' => 'changeme'], ['username' => 'misraim', 'password' => 'letmein']];
     $adapter = $this->getMockBuilder('\\Pagerfanta\\Adapter\\FixedAdapter')->disableOriginalConstructor()->getMock();
     $adapter->expects($this->once())->method('getNbResults')->will($this->returnValue(4));
     $adapter->expects($this->once())->method('getSlice')->will($this->returnValue($expectedUsers));
     $paginator->init($adapter);
     $paginator->setCurrentPage(1);
     $this->assertEquals(2, $paginator->getNbPages());
     $this->assertEquals($expectedUsers, $paginator->getCurrentPageResults());
 }