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 12, 2024
1 parent 7f16489 commit 424a99a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Pagination/DoctrinePaginatorAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function getTotal(): int
*/
public function getCount(): int
{
return $this->paginator->count();
return iterator_count($this->paginator->getIterator());
}

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

use ArrayIterator;
use Doctrine\ORM\Query;
use League\Fractal\Pagination\DoctrinePaginatorAdapter;
use Mockery;
Expand Down Expand Up @@ -28,11 +29,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 424a99a

Please sign in to comment.