Skip to content

Commit

Permalink
added \Countable interface to pagerfanta
Browse files Browse the repository at this point in the history
  • Loading branch information
pablodip committed Nov 28, 2011
1 parent bbbf256 commit 931bebe
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/Pagerfanta/Pagerfanta.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
*
* @api
*/
class Pagerfanta implements PagerfantaInterface, \IteratorAggregate
class Pagerfanta implements PagerfantaInterface, \Countable, \IteratorAggregate
{
private $adapter;
private $maxPerPage;
Expand Down Expand Up @@ -230,6 +230,18 @@ public function getNextPage()
return $this->currentPage + 1;
}

/**
* Implements the \Countable interface.
*
* Return integer The number of results.
*
* @api
*/
public function count()
{
return $this->getNbResults();
}

/**
* Implements the \IteratorAggregate interface.
*
Expand Down
11 changes: 11 additions & 0 deletions tests/Pagerfanta/Tests/PagerfantaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -258,4 +258,15 @@ public function testHasGetPreviousNextPage()
$this->assertInstanceOf('Pagerfanta\Exception\LogicException', $e);
}
}

public function testCountableInterface()
{
$this->adapter
->expects($this->any())
->method('getNbResults')
->will($this->returnValue(100))
;

$this->assertSame(100, count($this->pagerfanta));
}
}

0 comments on commit 931bebe

Please sign in to comment.