From 1eb86cf102cc6e7a55848cb910a734bfe5049002 Mon Sep 17 00:00:00 2001 From: Meritoo Date: Sun, 11 Apr 2021 21:45:29 +0200 Subject: [PATCH] [BaseCollection] Fix incorrectly working limit() method --- CHANGELOG.md | 4 ++++ VERSION | 2 +- src/Collection/BaseCollection.php | 2 +- tests/Collection/BaseCollectionTest.php | 21 ++++++--------------- 4 files changed, 12 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index be146a5..c9ddf64 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ Common and useful classes, methods, exceptions etc. +# 1.1.4 + +1. [BaseCollection] Fix incorrectly working limit() method + # 1.1.3 1. Move `Renderable` class: `Meritoo\Common` -> `Meritoo\Common\Contract` diff --git a/VERSION b/VERSION index 781dcb0..65087b4 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.1.3 +1.1.4 diff --git a/src/Collection/BaseCollection.php b/src/Collection/BaseCollection.php index fc9b141..0b1f3dd 100644 --- a/src/Collection/BaseCollection.php +++ b/src/Collection/BaseCollection.php @@ -248,7 +248,7 @@ abstract class BaseCollection implements CollectionInterface foreach ($result as $index => $element) { $iteration++; - if ($iteration < $offset || ($iteration >= $offset && $iteration < $max)) { + if ($iteration >= $offset && $iteration < $offset + $max) { continue; } diff --git a/tests/Collection/BaseCollectionTest.php b/tests/Collection/BaseCollectionTest.php index 5cb8259..cdb5c01 100644 --- a/tests/Collection/BaseCollectionTest.php +++ b/tests/Collection/BaseCollectionTest.php @@ -724,33 +724,24 @@ class BaseCollectionTest extends BaseTestCase 2, ]; - yield 'Maximum set to 1 & offset smaller than size of collection' => [ + yield 'Maximum set to 1 & offset set to 2' => [ [ - 'lorem', - 'ipsum', + 123 => 'dolor', ], 1, 2, ]; - yield 'Maximum set to 1 & offset equal size of collection' => [ + yield 'Maximum set to 1 & offset set to 3' => [ [ - 'lorem', - 'ipsum', - 123 => 'dolor', 345 => 'sit', ], 1, - 4, + 3, ]; - yield 'Maximum set to 1 & offset greater than size of collection' => [ - [ - 'lorem', - 'ipsum', - 123 => 'dolor', - 345 => 'sit', - ], + yield 'Maximum set to 1 & offset set to 10' => [ + [], 1, 10, ];