Skip to content

Commit

Permalink
tests: Add more tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Dec 18, 2021
1 parent 72ba6b8 commit 5201840
Showing 1 changed file with 27 additions and 4 deletions.
31 changes: 27 additions & 4 deletions tests/unit/CachingIteratorAggregateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace tests\loophp\iterators;

use Generator;
use loophp\iterators\CachingIteratorAggregate;
use PHPUnit\Framework\TestCase;

Expand All @@ -20,16 +21,38 @@ final class CachingIteratorAggregateTest extends TestCase
{
public function testWithAGenerator(): void
{
$input = static function () {
$input = static function (): Generator {
yield true => true;

yield false => false;

yield ['a'] => ['a'];

yield from range('a', 'c');
};

$iterator = (new CachingIteratorAggregate($input()));

foreach ($iterator as $key => $value);
$a = $b = [];

foreach ($iterator as $key => $value) {
$a[] = [$key, $value];
}

foreach ($iterator as $key => $value) {
$b[] = [$key, $value];
}

foreach ($iterator as $key => $value);
$expected = [
[true, true],
[false, false],
[['a'], ['a']],
[0, 'a'],
[1, 'b'],
[2, 'c'],
];

$this->expectNotToPerformAssertions();
self::assertEquals($expected, $a);
self::assertTrue($a === $b);
}
}

0 comments on commit 5201840

Please sign in to comment.