Skip to content

Commit

Permalink
Fix ResultSet::next() to increment ResultSet::position when ResultSet…
Browse files Browse the repository at this point in the history
…::cache is valid

Earlier ResultSet::position was not incremented once the cache is filled and hence ResultSet::valid() was
not functioning as expected. Hence, Icinga\Module\Icingadb\Widget\ShowMore was not working as expected.

This fix resolves the issue.
  • Loading branch information
raviks789 authored and nilmerg committed Jul 1, 2022
1 parent 6fb0edc commit 0b76de0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/ResultSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ public function next(): void
if ($this->isCacheDisabled || ! $this->cache->valid()) {
$this->generator->next();
$this->advance();
} else {
$this->position += 1;
}
}

Expand Down
19 changes: 19 additions & 0 deletions tests/ResultSetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']
);
}
}

0 comments on commit 0b76de0

Please sign in to comment.