File tree Expand file tree Collapse file tree 3 files changed +69
-0
lines changed Expand file tree Collapse file tree 3 files changed +69
-0
lines changed Original file line number Diff line number Diff line change 1717 - name : Install Composer
1818 run : composer install
1919
20+ - name : Include files for autoloading
21+ run : composer dump-autoload
22+
2023 - name : Run PHPUnit tests
2124 run : ./vendor/bin/phpunit tests
Original file line number Diff line number Diff line change 66 "vimeo/psalm" : " ^4.8" ,
77 "phpmd/phpmd" : " ^2.10" ,
88 "friendsofphp/php-cs-fixer" : " ^3.0"
9+ },
10+ "autoload" : {
11+ "psr-4" : {
12+ "MaxGoryunov\\ SavingIterator\\ " : " "
13+ }
914 }
1015}
Original file line number Diff line number Diff line change 33namespace MaxGoryunov \SavingIterator \Tests \Src ;
44
55use ArrayIterator ;
6+ use Generator ;
67use MaxGoryunov \SavingIterator \Fakes \TimesCalled ;
78use MaxGoryunov \SavingIterator \Fakes \TransparentIterator ;
89use MaxGoryunov \SavingIterator \Src \SavingIterator ;
@@ -71,6 +72,66 @@ public function testDoesNotCallOriginIfValuesAreInCache(): void
7172 $ this ->assertEquals (count ($ input ), $ called ->value ());
7273 }
7374
75+ /**
76+ * @covers ::__construct
77+ * @covers ::rewind
78+ * @covers ::valid
79+ * @covers ::current
80+ * @covers ::key
81+ * @covers ::next
82+ *
83+ * @small
84+ *
85+ * @return void
86+ */
87+ public function testWorksWithGenerator (): void
88+ {
89+ $ limit = 6 ;
90+ $ this ->assertEquals (
91+ range (0 , $ limit ),
92+ iterator_to_array (
93+ new SavingIterator (
94+ (
95+ function () use ($ limit ): Generator
96+ {
97+ for ($ i = 0 ; $ i <= $ limit ; $ i ++) {
98+ yield $ i ;
99+ }
100+ }
101+ )()
102+ )
103+ )
104+ );
105+ }
106+
107+ /**
108+ * @covers ::__construct
109+ * @covers ::rewind
110+ * @covers ::valid
111+ * @covers ::current
112+ * @covers ::key
113+ * @covers ::next
114+ *
115+ * @small
116+ *
117+ * @return void
118+ */
119+ public function testWorksWithGeneratorMultipleTimes (): void
120+ {
121+ $ iterator = new SavingIterator (
122+ (function (): Generator
123+ {
124+ for ($ i = 0 ; $ i < 10 ; $ i ++) {
125+ yield $ i ;
126+ }
127+ })()
128+ );
129+ $ this ->assertEquals (
130+ iterator_to_array ($ iterator ),
131+ iterator_to_array ($ iterator )
132+ );
133+ }
134+
74135 /**
75136 * @covers ::__construct
76137 * @covers ::rewind
You can’t perform that action at this time.
0 commit comments