fix pagination problems

(cherry picked from commit 43702ded77449ee08b8d2c5c494c220d457373a1)
This commit is contained in:
Julien Fastré 2021-12-03 15:06:06 +01:00
parent ff751b7f30
commit 9244bb2f8d
2 changed files with 16 additions and 0 deletions

View File

@ -109,6 +109,10 @@ class Paginator implements PaginatorInterface
return 1; return 1;
} }
if (0 === $this->totalItems) {
return 1;
}
$nb = floor($this->totalItems / $this->itemPerPage); $nb = floor($this->totalItems / $this->itemPerPage);
if ($this->totalItems % $this->itemPerPage > 0) { if ($this->totalItems % $this->itemPerPage > 0) {
@ -211,6 +215,10 @@ class Paginator implements PaginatorInterface
public function hasPage($number) public function hasPage($number)
{ {
if (0 === $this->totalItems) {
return 1 === $number;
}
return 0 < $number return 0 < $number
&& $this->countPages() >= $number; && $this->countPages() >= $number;
} }

View File

@ -204,6 +204,14 @@ final class PaginatorTest extends KernelTestCase
); );
} }
public function testPagesWithoutResult()
{
$paginator = $this->generatePaginator(0, 10);
$this->assertEquals(0, $paginator->getCurrentPageFirstItemNumber());
$this->assertEquals(10, $paginator->getItemsPerPage());
}
/** /**
* @param int $itemPerPage * @param int $itemPerPage
* @param string $route * @param string $route