From 8b8ead613b6ef41849e4a9d35905774939d47289 Mon Sep 17 00:00:00 2001 From: Max Goryunov Date: Wed, 13 Aug 2025 13:45:39 +0300 Subject: [PATCH 1/2] #195 default to ArrayAddingIterator --- composer.json | 2 +- src/SavingIterator.php | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index d58727f..bcfad4e 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "maxgoryunov/saving-iterator", "description": "True Caching Iterator for PHP", "require": { - "php": ">=8.0" + "php": ">=8.1" }, "require-dev": { "phpstan/phpstan": "^1.4.6", diff --git a/src/SavingIterator.php b/src/SavingIterator.php index db22a4b..cd0f144 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 */ From 02026297b6e7bcf52b658aa6a68820e8452c9383 Mon Sep 17 00:00:00 2001 From: Max Goryunov Date: Fri, 22 Aug 2025 22:15:50 +0300 Subject: [PATCH 2/2] #195 test without AddingIterator --- tests/src/SavingIteratorTest.php | 35 ++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) 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