Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix PropelModelPager::getLastPage() return type.

Turns out that PHP's `ceil()` converts a float to an integer but still returns... a float.
The patch forces the return type of `getLastPage()` by casting to integer after calling `ceil()`.

Closes #316.
  • Loading branch information...
commit 45f2924b668ae8a27990d19bd8b4961563e35ba1 1 parent b7669e3
@fzaninotto fzaninotto authored
View
2  runtime/lib/util/PropelModelPager.php
@@ -71,7 +71,7 @@ public function init($con = null)
if (($this->getPage() == 0 || $this->getMaxPerPage() == 0)) {
$this->setLastPage(0);
} else {
- $this->setLastPage(ceil($this->getNbResults() / $this->getMaxPerPage()));
+ $this->setLastPage((int)ceil($this->getNbResults() / $this->getMaxPerPage()));
$offset = ($this->getPage() - 1) * $this->getMaxPerPage();
$q->offset($offset);
View
8 test/testsuite/runtime/util/PropelModelPagerTest.php
@@ -158,6 +158,14 @@ public function testIsLastPage()
$this->assertTrue($pager->isLastPage(), 'isLastPage() returns true on the last page');
}
+ public function testGetLastPage()
+ {
+ $this->createBooks(5);
+ $pager = $this->getPager(4, 1);
+ $this->assertEquals(2, $pager->getLastPage(), 'getLastPage() returns the last page number');
+ $this->assertInternalType('integer', $pager->getLastPage(), 'getLastPage() returns an integer');
+ }
+
public function testIsFirstOnFirstPage()
{
$this->createBooks(5);
Please sign in to comment.
Something went wrong with that request. Please try again.