Skip to content

Commit

Permalink
fix: count TraversablePaginator (#6611)
Browse files Browse the repository at this point in the history
  • Loading branch information
nikophil authored Sep 16, 2024
1 parent 9edacab commit 1b9dfcc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/State/Pagination/TraversablePaginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ public function count(): int
return (int) ceil($this->totalItems);
}

if ($this->totalItems === $this->itemsPerPage) {
return (int) ceil($this->totalItems);
}

return $this->totalItems % $this->itemsPerPage;
}

Expand Down
2 changes: 2 additions & 0 deletions tests/State/Pagination/TraversablePaginatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public static function initializeProvider(): array
'Empty results' => [[], 1, 2, 0, 1, 0],
'0 items per page' => [[0, 1, 2, 3], 1, 0, 4, 1, 4],
'Total items less than items per page' => [[0, 1, 2], 1, 4, 3, 1, 3],
'Only one result' => [[0], 1, 1, 1, 1, 1],
'Same result number than total page' => [[0, 2, 3], 1, 3, 3, 1, 3],
];
}
}

0 comments on commit 1b9dfcc

Please sign in to comment.