From 3aab1e112e7ba0aa323cb184191a2a2c1146a232 Mon Sep 17 00:00:00 2001 From: Pol Dellaiera Date: Mon, 6 Feb 2023 22:05:46 +0100 Subject: [PATCH] chore: fix phpunit 10 compatibility --- tests/unit/CollectionGenericOperationTest.php | 1 + .../unit/CollectionSpecificOperationTest.php | 44 ++++++++++++++----- .../CustomCollectionGenericOperationTest.php | 1 + .../CustomCollectionSpecificOperationTest.php | 44 ++++++++++++++----- tests/unit/IssuesTest.php | 1 + 5 files changed, 67 insertions(+), 24 deletions(-) diff --git a/tests/unit/CollectionGenericOperationTest.php b/tests/unit/CollectionGenericOperationTest.php index b72a7c373..80f752564 100644 --- a/tests/unit/CollectionGenericOperationTest.php +++ b/tests/unit/CollectionGenericOperationTest.php @@ -17,6 +17,7 @@ final class CollectionGenericOperationTest extends TestCase { use GenericCollectionProviders; + use IterableAssertions; /** diff --git a/tests/unit/CollectionSpecificOperationTest.php b/tests/unit/CollectionSpecificOperationTest.php index 60ac3185b..eb3401a0d 100644 --- a/tests/unit/CollectionSpecificOperationTest.php +++ b/tests/unit/CollectionSpecificOperationTest.php @@ -13,6 +13,7 @@ use loophp\collection\Operation\Coalesce; use loophp\collection\Operation\Current; use loophp\collection\Operation\Limit; +use loophp\iterators\CachingIteratorAggregate; use loophp\PhpUnitIterableAssertions\Traits\IterableAssertions; use OutOfBoundsException; use PHPUnit\Framework\TestCase; @@ -31,6 +32,7 @@ final class CollectionSpecificOperationTest extends TestCase { use GenericCollectionProviders; + use IterableAssertions; public function testApplyOperation(): void @@ -157,24 +159,30 @@ public function testCoalesceOperation(): void $coalesce = new Coalesce(); - self::assertCount(1, $coalesce->__invoke()($input)); + self::assertEquals( + 1, + iterator_count(new CachingIteratorAggregate($coalesce->__invoke()($input))) + ); self::assertIdenticalIterable( [ 0 => 'a', ], - $coalesce->__invoke()($input) + new CachingIteratorAggregate($coalesce->__invoke()($input)) ); $input = ['', null, 'foo', false, ...range('a', 'e')]; - self::assertCount(1, $coalesce->__invoke()($input)); + self::assertEquals( + 1, + iterator_count(new CachingIteratorAggregate($coalesce->__invoke()($input))) + ); self::assertIdenticalIterable( [ 2 => 'foo', ], - $coalesce->__invoke()($input) + new CachingIteratorAggregate($coalesce->__invoke()($input)) ); } @@ -186,14 +194,17 @@ public function testCurrentOperation(): void self::assertIdenticalIterable( ['a'], - $current->__invoke()(0)(null)($input) + new CachingIteratorAggregate($current->__invoke()(0)(null)($input)) ); - self::assertCount(1, $current->__invoke()(0)(null)($input)); + self::assertEquals( + 1, + iterator_count(new CachingIteratorAggregate($current->__invoke()(0)(null)($input))) + ); self::assertIdenticalIterable( ['unavailable'], - $current->__invoke()(10)('unavailable')($input) + new CachingIteratorAggregate($current->__invoke()(10)('unavailable')($input)) ); } @@ -299,20 +310,29 @@ public function testLimitOperation(): void $limit = new Limit(); $input = range('a', 'e'); - self::assertCount(1, $limit()(1)(0)($input)); + self::assertEquals( + 1, + iterator_count(new CachingIteratorAggregate($limit()(1)(0)($input))) + ); - self::assertCount(2, $limit()(2)(0)($input)); + self::assertEquals( + 2, + iterator_count(new CachingIteratorAggregate($limit()(2)(0)($input))) + ); self::assertIdenticalIterable( [2 => 'c'], - $limit()(1)(2)($input) + new CachingIteratorAggregate($limit()(1)(2)($input)) ); - self::assertCount(2, $limit()(2)(2)($input)); + self::assertEquals( + 2, + iterator_count(new CachingIteratorAggregate($limit()(2)(2)($input))) + ); self::assertIdenticalIterable( ['a', 'b', 'c', 'd', 'e'], - $limit()()()($input) + new CachingIteratorAggregate($limit()()()($input)) ); } diff --git a/tests/unit/CustomCollectionGenericOperationTest.php b/tests/unit/CustomCollectionGenericOperationTest.php index 6fe374df3..b195390d0 100644 --- a/tests/unit/CustomCollectionGenericOperationTest.php +++ b/tests/unit/CustomCollectionGenericOperationTest.php @@ -17,6 +17,7 @@ final class CustomCollectionGenericOperationTest extends TestCase { use GenericCollectionProviders; + use IterableAssertions; /** diff --git a/tests/unit/CustomCollectionSpecificOperationTest.php b/tests/unit/CustomCollectionSpecificOperationTest.php index 0e1e1c6a1..163593b73 100644 --- a/tests/unit/CustomCollectionSpecificOperationTest.php +++ b/tests/unit/CustomCollectionSpecificOperationTest.php @@ -13,6 +13,7 @@ use loophp\collection\Operation\Coalesce; use loophp\collection\Operation\Current; use loophp\collection\Operation\Limit; +use loophp\iterators\CachingIteratorAggregate; use loophp\PhpUnitIterableAssertions\Traits\IterableAssertions; use OutOfBoundsException; use PHPUnit\Framework\TestCase; @@ -31,6 +32,7 @@ final class CustomCollectionSpecificOperationTest extends TestCase { use GenericCollectionProviders; + use IterableAssertions; public function testApplyOperation(): void @@ -157,24 +159,30 @@ public function testCoalesceOperation(): void $coalesce = new Coalesce(); - self::assertCount(1, $coalesce->__invoke()($input)); + self::assertEquals( + 1, + iterator_count(new CachingIteratorAggregate($coalesce->__invoke()($input))) + ); self::assertIdenticalIterable( [ 0 => 'a', ], - $coalesce->__invoke()($input) + new CachingIteratorAggregate($coalesce->__invoke()($input)) ); $input = ['', null, 'foo', false, ...range('a', 'e')]; - self::assertCount(1, $coalesce->__invoke()($input)); + self::assertEquals( + 1, + iterator_count(new CachingIteratorAggregate($coalesce->__invoke()($input))) + ); self::assertIdenticalIterable( [ 2 => 'foo', ], - $coalesce->__invoke()($input) + new CachingIteratorAggregate($coalesce->__invoke()($input)) ); } @@ -186,14 +194,17 @@ public function testCurrentOperation(): void self::assertIdenticalIterable( ['a'], - $current->__invoke()(0)(null)($input) + new CachingIteratorAggregate($current->__invoke()(0)(null)($input)) ); - self::assertCount(1, $current->__invoke()(0)(null)($input)); + self::assertEquals( + 1, + iterator_count(new CachingIteratorAggregate($current->__invoke()(0)(null)($input))) + ); self::assertIdenticalIterable( ['unavailable'], - $current->__invoke()(10)('unavailable')($input) + new CachingIteratorAggregate($current->__invoke()(10)('unavailable')($input)) ); } @@ -299,20 +310,29 @@ public function testLimitOperation(): void $limit = new Limit(); $input = range('a', 'e'); - self::assertCount(1, $limit()(1)(0)($input)); + self::assertEquals( + 1, + iterator_count(new CachingIteratorAggregate($limit()(1)(0)($input))) + ); - self::assertCount(2, $limit()(2)(0)($input)); + self::assertEquals( + 2, + iterator_count(new CachingIteratorAggregate($limit()(2)(0)($input))) + ); self::assertIdenticalIterable( [2 => 'c'], - $limit()(1)(2)($input) + new CachingIteratorAggregate($limit()(1)(2)($input)) ); - self::assertCount(2, $limit()(2)(2)($input)); + self::assertEquals( + 2, + iterator_count(new CachingIteratorAggregate($limit()(2)(2)($input))) + ); self::assertIdenticalIterable( ['a', 'b', 'c', 'd', 'e'], - $limit()()()($input) + new CachingIteratorAggregate($limit()()()($input)) ); } diff --git a/tests/unit/IssuesTest.php b/tests/unit/IssuesTest.php index 4669e7177..379b40fef 100644 --- a/tests/unit/IssuesTest.php +++ b/tests/unit/IssuesTest.php @@ -17,6 +17,7 @@ final class IssuesTest extends TestCase { use GenericCollectionProviders; + use IterableAssertions; public function testIssue264()