7
7
8
8
class CachedGeneratorTest extends TestCase
9
9
{
10
- public function testGenerates () {
10
+ public function testGenerates ()
11
+ {
11
12
$ generator = function () {
12
13
foreach (range (0 , 2 ) as $ value ) {
13
14
yield $ value ;
@@ -19,7 +20,8 @@ public function testGenerates() {
19
20
$ this ->assertEquals (range (0 , 2 ), $ results );
20
21
}
21
22
22
- public function testWorksWithEmptyGenerator () {
23
+ public function testWorksWithEmptyGenerator ()
24
+ {
23
25
$ generator = function () {
24
26
if (false ) yield 0 ;
25
27
};
@@ -29,7 +31,8 @@ public function testWorksWithEmptyGenerator() {
29
31
$ this ->assertEquals ([], $ results );
30
32
}
31
33
32
- public function testWorksTwice () {
34
+ public function testWorksTwice ()
35
+ {
33
36
$ generator = function () {
34
37
foreach (range (0 , 2 ) as $ value ) {
35
38
yield $ value ;
@@ -42,4 +45,32 @@ public function testWorksTwice() {
42
45
$ results = iterator_to_array ($ cachedGenerator );
43
46
$ this ->assertEquals (range (0 , 2 ), $ results );
44
47
}
48
+
49
+ public function testExposesInnerGenerator ()
50
+ {
51
+ $ generator = function () {
52
+ foreach (range (0 , 2 ) as $ value ) {
53
+ yield $ value ;
54
+ }
55
+ };
56
+
57
+ $ generatorInstance = $ generator ();
58
+ $ cachedGenerator = new CachedGenerator ($ generatorInstance );
59
+
60
+ $ this ->assertEquals ($ generatorInstance , $ cachedGenerator ->getInnerIterator ());
61
+ }
62
+
63
+ public function testExposesCache ()
64
+ {
65
+ $ generator = function () {
66
+ foreach (range (0 , 2 ) as $ value ) {
67
+ yield $ value ;
68
+ }
69
+ };
70
+ $ cachedGenerator = new CachedGenerator ($ generator ());
71
+
72
+ $ results = iterator_to_array ($ cachedGenerator );
73
+
74
+ $ this ->assertEquals ($ results , $ cachedGenerator ->getCache ());
75
+ }
45
76
}
0 commit comments