diff --git a/src/ResultSet.php b/src/ResultSet.php index 780333f..05117a5 100644 --- a/src/ResultSet.php +++ b/src/ResultSet.php @@ -81,6 +81,8 @@ public function next(): void if ($this->isCacheDisabled || ! $this->cache->valid()) { $this->generator->next(); $this->advance(); + } else { + $this->position += 1; } } diff --git a/tests/ResultSetTest.php b/tests/ResultSetTest.php index b28c601..c0c1413 100644 --- a/tests/ResultSetTest.php +++ b/tests/ResultSetTest.php @@ -62,4 +62,23 @@ public function testResultWithCacheEnabled() ['a', 'b', 'c', 'a', 'b', 'c'] ); } + + public function testResultWithCacheEnabledWithLimit() + { + $set = (new ResultSet(new ArrayIterator(['a', 'b', 'c']), 2)); + + $items = []; + foreach ($set as $item) { + $items[] = $item; + } + + foreach ($set as $item) { + $items[] = $item; + } + + $this->assertEquals( + $items, + ['a', 'b', 'a', 'b'] + ); + } }