Skip to content

Commit

Permalink
make getCount compatible with new Traversable return type of getIterator
Browse files Browse the repository at this point in the history
  • Loading branch information
kohlerdominik committed Dec 13, 2024
1 parent 7f16489 commit 2240019
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/Pagination/DoctrinePaginatorAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
6 changes: 2 additions & 4 deletions test/Pagination/DoctrinePaginatorAdapterTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace League\Fractal\Test\Pagination;

use Doctrine\ORM\Query;
use ArrayIterator;
use League\Fractal\Pagination\DoctrinePaginatorAdapter;
use Mockery;
use PHPUnit\Framework\TestCase;
Expand All @@ -28,11 +28,9 @@ public function testPaginationAdapter()
$paginator->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;
});
Expand Down

0 comments on commit 2240019

Please sign in to comment.