Skip to content
Merged

195 #198

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/SavingIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<TKey, TValue>
Expand All @@ -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 */
Expand Down
35 changes: 35 additions & 0 deletions tests/src/SavingIteratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading