Skip to content

Commit aea6ee0

Browse files
Added test "Picks up where it left off"
1 parent 0998599 commit aea6ee0

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

tests/CachingGeneratorTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,25 @@ public function testWorksTwice()
4646
$this->assertEquals(range(0, 2), $results);
4747
}
4848

49+
public function testPicksUpWhereItLeftOff()
50+
{
51+
$generator = function () {
52+
foreach (range(0, 2) as $value) {
53+
yield $value;
54+
}
55+
};
56+
$cachingGenerator = new CachingGenerator($generator());
57+
58+
foreach ($cachingGenerator as $value) {
59+
if ($value === 1) {
60+
break;
61+
}
62+
}
63+
64+
$results = iterator_to_array($cachingGenerator);
65+
$this->assertEquals(range(0, 2), $results);
66+
}
67+
4968
public function testExposesInnerGenerator()
5069
{
5170
$generator = function () {

0 commit comments

Comments
 (0)