Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/26'
Browse files Browse the repository at this point in the history
Close #26
Fixes #22
  • Loading branch information
weierophinney committed Nov 1, 2017
2 parents f4b160f + 5f1f5ff commit 730e6de
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ All notable changes to this project will be documented in this file, in reverse

### Fixed

- Nothing.
- [#26](https://github.com/zendframework/zend-paginator/pull/26) fixes an issue
in `Paginator::count()` whereby it would re-count when zero pages had been
previously detected.

## 2.7.0 - 2016-04-11

Expand Down
2 changes: 1 addition & 1 deletion src/Paginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ public function setCacheEnabled($enable)
*/
public function count()
{
if (! $this->pageCount) {
if ($this->pageCount === null) {
$this->pageCount = $this->_calculatePageCount();
}

Expand Down
17 changes: 17 additions & 0 deletions test/PaginatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,23 @@ public function testHasCorrectCountOfAllItemsAfterInit()
$this->assertEquals(101, $paginator->getTotalItemCount());
}

public function testRepetitiveCallOfCountResultsOfZero()
{
$count = 0;

$paginator = $this->getMockBuilder(Paginator\Paginator::class)
->setConstructorArgs([new Adapter\ArrayAdapter([])])
->setMethods(['_calculatePageCount'])
->getMock();

$paginator->expects($this->once())
->method('_calculatePageCount')
->willReturn($count);

$this->assertEquals($count, $paginator->count());
$this->assertEquals($count, $paginator->count());
}

public function testLoadsFromConfig()
{
Paginator\Paginator::setGlobalConfig($this->config->testing);
Expand Down

0 comments on commit 730e6de

Please sign in to comment.