diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index f01fdbe3..bc1d5106 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -9,7 +9,7 @@ jobs: fail-fast: true matrix: os: [ubuntu-20.04] - php: [7.4, 8.0, 8.1] + php: [7.4, 8.0, 8.1, 8.2, 8.3, 8.4] name: League - PHP ${{ matrix.php }} on ${{ matrix.os }} diff --git a/src/Manager.php b/src/Manager.php index 0320bb1e..8ccff24a 100644 --- a/src/Manager.php +++ b/src/Manager.php @@ -61,7 +61,7 @@ class Manager */ private ScopeFactoryInterface $scopeFactory; - public function __construct(ScopeFactoryInterface $scopeFactory = null) + public function __construct(?ScopeFactoryInterface $scopeFactory = null) { $this->scopeFactory = $scopeFactory ?: new ScopeFactory(); } @@ -72,7 +72,7 @@ public function __construct(ScopeFactoryInterface $scopeFactory = null) public function createData( ResourceInterface $resource, ?string $scopeIdentifier = null, - Scope $parentScopeInstance = null + ?Scope $parentScopeInstance = null ): Scope { if ($parentScopeInstance !== null) { return $this->scopeFactory->createChildScopeFor($this, $parentScopeInstance, $resource, $scopeIdentifier); diff --git a/src/Pagination/DoctrinePaginatorAdapter.php b/src/Pagination/DoctrinePaginatorAdapter.php index bcab596a..9908ab32 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->getIterator()->count(); + $iterator = $this->paginator->getIterator(); + + return (is_countable($iterator)) + ? count($iterator) + : iterator_count(clone $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; });