Skip to content

Commit f6d8f91

Browse files
authored
Merge pull request #12 from MaxGoryunov/feature/5
Feature/5
2 parents a684421 + 3f03def commit f6d8f91

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

.github/workflows/php.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,8 @@ jobs:
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

composer.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,10 @@
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
}

tests/src/SavingIteratorTest.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace MaxGoryunov\SavingIterator\Tests\Src;
44

55
use ArrayIterator;
6+
use Generator;
67
use MaxGoryunov\SavingIterator\Fakes\TimesCalled;
78
use MaxGoryunov\SavingIterator\Fakes\TransparentIterator;
89
use 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

0 commit comments

Comments
 (0)