diff --git a/src/Pagination/DoctrinePaginatorAdapter.php b/src/Pagination/DoctrinePaginatorAdapter.php index c2e8f71f..9046a792 100644 --- a/src/Pagination/DoctrinePaginatorAdapter.php +++ b/src/Pagination/DoctrinePaginatorAdapter.php @@ -73,7 +73,11 @@ public function getTotal(): int */ public function getCount(): int { - return $this->paginator->count(); + $iterator = $this->paginator->getIterator(); + + return (is_countable($iterator)) + ? count($iterator) + : iterator_count($iterator); } /** diff --git a/test/Pagination/DoctrinePaginatorAdapterTest.php b/test/Pagination/DoctrinePaginatorAdapterTest.php index 26ba291e..701b449f 100644 --- a/test/Pagination/DoctrinePaginatorAdapterTest.php +++ b/test/Pagination/DoctrinePaginatorAdapterTest.php @@ -1,7 +1,7 @@ shouldReceive('getQuery')->andReturn($query); //Mock the iterator of the paginator - $iterator = Mockery::mock('IteratorAggregate'); - $iterator->shouldReceive('count')->andReturn($count); + $iterator = new ArrayIterator(range(1, $count)); $paginator->shouldReceive('getIterator')->andReturn($iterator); - $adapter = new DoctrinePaginatorAdapter($paginator, function ($page) { return 'http://example.com/foo?page='.$page; });