Skip to content

Commit 48beae7

Browse files
committed
refactor: Use iterator aggregates.
1 parent ef8f77f commit 48beae7

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

src/Constraint/IsIdenticalIterable.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99

1010
namespace loophp\PhpUnitIterableAssertions\Constraint;
1111

12-
use loophp\iterators\IterableIterator;
12+
use Iterator;
13+
use loophp\iterators\IterableIteratorAggregate;
14+
use loophp\iterators\MultipleIterableAggregate;
1315
use MultipleIterator;
1416
use PHPUnit\Framework\Constraint\Constraint;
1517

@@ -45,12 +47,12 @@ public function toString(): string
4547
*/
4648
protected function matches($other): bool
4749
{
48-
$i1 = new IterableIterator($this->subject);
49-
$i2 = new IterableIterator($other);
50+
[$subject, $other] = array_map(
51+
static fn (iterable $iterable): Iterator => (new IterableIteratorAggregate($iterable))->getIterator(),
52+
[$this->subject, $other]
53+
);
5054

51-
$mi = new MultipleIterator(MultipleIterator::MIT_NEED_ALL);
52-
$mi->attachIterator($i1);
53-
$mi->attachIterator($i2);
55+
$mi = new MultipleIterableAggregate([$subject, $other], MultipleIterator::MIT_NEED_ALL);
5456

5557
$index = 0;
5658

@@ -71,7 +73,7 @@ protected function matches($other): bool
7173
}
7274

7375
if (0 === $this->limit) {
74-
if ($i1->valid() !== $i2->valid()) {
76+
if ($subject->valid() !== $other->valid()) {
7577
return false;
7678
}
7779
}

src/Constraint/IsNotIdenticalIterable.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99

1010
namespace loophp\PhpUnitIterableAssertions\Constraint;
1111

12-
use loophp\iterators\IterableIterator;
12+
use Iterator;
13+
use loophp\iterators\IterableIteratorAggregate;
14+
use loophp\iterators\MultipleIterableAggregate;
1315
use MultipleIterator;
1416
use PHPUnit\Framework\Constraint\Constraint;
1517

@@ -45,12 +47,12 @@ public function toString(): string
4547
*/
4648
protected function matches($other): bool
4749
{
48-
$i1 = new IterableIterator($this->subject);
49-
$i2 = new IterableIterator($other);
50+
[$subject, $other] = array_map(
51+
static fn (iterable $iterable): Iterator => (new IterableIteratorAggregate($iterable))->getIterator(),
52+
[$this->subject, $other]
53+
);
5054

51-
$mi = new MultipleIterator(MultipleIterator::MIT_NEED_ALL);
52-
$mi->attachIterator($i1);
53-
$mi->attachIterator($i2);
55+
$mi = new MultipleIterableAggregate([$subject, $other], MultipleIterator::MIT_NEED_ALL);
5456

5557
$index = 0;
5658

@@ -71,7 +73,7 @@ protected function matches($other): bool
7173
}
7274

7375
if (0 === $this->limit) {
74-
if ($i1->valid() !== $i2->valid()) {
76+
if ($subject->valid() !== $other->valid()) {
7577
return true;
7678
}
7779
}

0 commit comments

Comments
 (0)