Skip to content

Commit

Permalink
chore: fix phpunit 10 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
drupol committed Feb 6, 2023
1 parent 70f95b6 commit 3aab1e1
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 24 deletions.
1 change: 1 addition & 0 deletions tests/unit/CollectionGenericOperationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
final class CollectionGenericOperationTest extends TestCase
{
use GenericCollectionProviders;

use IterableAssertions;

/**
Expand Down
44 changes: 32 additions & 12 deletions tests/unit/CollectionSpecificOperationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,6 +32,7 @@
final class CollectionSpecificOperationTest extends TestCase
{
use GenericCollectionProviders;

use IterableAssertions;

public function testApplyOperation(): void
Expand Down Expand Up @@ -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))
);
}

Expand All @@ -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))
);
}

Expand Down Expand Up @@ -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))
);
}

Expand Down
1 change: 1 addition & 0 deletions tests/unit/CustomCollectionGenericOperationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
final class CustomCollectionGenericOperationTest extends TestCase
{
use GenericCollectionProviders;

use IterableAssertions;

/**
Expand Down
44 changes: 32 additions & 12 deletions tests/unit/CustomCollectionSpecificOperationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,6 +32,7 @@
final class CustomCollectionSpecificOperationTest extends TestCase
{
use GenericCollectionProviders;

use IterableAssertions;

public function testApplyOperation(): void
Expand Down Expand Up @@ -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))
);
}

Expand All @@ -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))
);
}

Expand Down Expand Up @@ -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))
);
}

Expand Down
1 change: 1 addition & 0 deletions tests/unit/IssuesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
final class IssuesTest extends TestCase
{
use GenericCollectionProviders;

use IterableAssertions;

public function testIssue264()
Expand Down

0 comments on commit 3aab1e1

Please sign in to comment.