Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix PropelModelPager::getLastPage() return type. #317

Merged
merged 1 commit into from

2 participants

@fzaninotto
Collaborator

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.

@fzaninotto fzaninotto 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.
45f2924
@willdurand willdurand merged commit 46c3f86 into propelorm:master
@willdurand
Owner

Thanks, could you port this patch on Propel2?

@fzaninotto
Collaborator

I'll take care of it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 19, 2012
  1. @fzaninotto

    Fix PropelModelPager::getLastPage() return type.

    fzaninotto authored
    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.
This page is out of date. Refresh to see the latest.
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);
Something went wrong with that request. Please try again.