diff --git a/src/SavingIterator.php b/src/SavingIterator.php index 552eb17..4e2be8f 100644 --- a/src/SavingIterator.php +++ b/src/SavingIterator.php @@ -6,6 +6,11 @@ /** * Iterator which stores iterated values. + * + * @todo #195:15min README has to mention that now it is not required to + * create ArrayAddingIterator and pass it into the constructor because now it + * is a default option. + * * @template TKey * @template TValue * @extends IteratorEnvelope @@ -22,7 +27,7 @@ final class SavingIterator extends IteratorEnvelope */ public function __construct( Iterator $origin, - AddingIterator $target + AddingIterator $target = new ArrayAddingIterator() ) { parent::__construct( /** @phpstan-ignore-next-line */ diff --git a/tests/src/SavingIteratorTest.php b/tests/src/SavingIteratorTest.php index a21878e..44d1250 100644 --- a/tests/src/SavingIteratorTest.php +++ b/tests/src/SavingIteratorTest.php @@ -57,6 +57,41 @@ public function testIteratesWithGivenIterator(): void ); } + /** + * @covers ::__construct + * @covers ::rewind + * @covers ::valid + * @covers ::current + * @covers ::key + * @covers ::next + * + * @uses MaxGoryunov\SavingIterator\Fakes\SurveyEnvelope + * @uses MaxGoryunov\SavingIterator\Fakes\The + * @uses MaxGoryunov\SavingIterator\Src\ArrayAddingIterator + * @uses MaxGoryunov\SavingIterator\Src\ValidAddingIterator + * @uses MaxGoryunov\SavingIterator\Src\ContextVeil + * @uses MaxGoryunov\SavingIterator\Src\ClosureReaction + * + * @small + * + * @return void + */ + public function testWorksWithDefaultAddingIterator(): void + { + (new The( + [11, 12, 13, 14, 15] + ))->act( + fn (array $nums) => $this->assertEquals( + $nums, + iterator_to_array( + new SavingIterator( + new ArrayIterator($nums) + ) + ) + ) + ); + } + /** * @covers ::rewind * @covers ::valid