From 78da978ec26d6b2f64f4ed6b40c638028a62c457 Mon Sep 17 00:00:00 2001 From: Oleg Andreyev Date: Fri, 22 Jun 2018 15:28:35 +0300 Subject: [PATCH] fixing negative result getNbResults, if there are not results --- src/Datagrid/SimplePager.php | 2 +- tests/Datagrid/SimplePagerTest.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Datagrid/SimplePager.php b/src/Datagrid/SimplePager.php index 890d6626a09..8eeb0464ebc 100644 --- a/src/Datagrid/SimplePager.php +++ b/src/Datagrid/SimplePager.php @@ -119,7 +119,7 @@ public function init() $this->initializeIterator(); $t = (int) ceil($this->thresholdCount / $this->getMaxPerPage()) + $this->getPage() - 1; - $this->setLastPage($t); + $this->setLastPage(\max(1, $t)); } } diff --git a/tests/Datagrid/SimplePagerTest.php b/tests/Datagrid/SimplePagerTest.php index 708ed17da03..95efb60cb41 100644 --- a/tests/Datagrid/SimplePagerTest.php +++ b/tests/Datagrid/SimplePagerTest.php @@ -112,7 +112,8 @@ public function testNoPagesForNoResults() $this->pager->setQuery($this->proxyQuery); $this->pager->init(); - $this->AssertEquals(0, $this->pager->getLastPage()); + $this->assertEquals(1, $this->pager->getLastPage()); + $this->assertEquals(0, $this->pager->getNbResults()); } public function testInitNoQuery()