Skip to content

Commit

Permalink
php 8.1 compat
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Apr 21, 2024
1 parent 8ab291b commit 7b182f7
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 8 deletions.
4 changes: 1 addition & 3 deletions src/AtLeast.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
use Traversable;
use Webmozart\Assert\Assert;

use function iterator_count;

final class AtLeast
{
/**
Expand Down Expand Up @@ -50,7 +48,7 @@ private static function atLeastFoundTimes(
// usage must be higher than 0
Assert::greaterThan($maxCount, 0);

if (iterator_count($data) < $maxCount) {
if (Counter::count($data) < $maxCount) {
return false;
}

Expand Down
4 changes: 1 addition & 3 deletions src/Only.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
use Traversable;
use Webmozart\Assert\Assert;

use function iterator_count;

final class Only
{
/**
Expand Down Expand Up @@ -50,7 +48,7 @@ private static function onlyFoundTimes(
// usage must be higher than 0
Assert::greaterThan($maxCount, 0);

if (iterator_count($data) < $maxCount) {
if (Counter::count($data) < $maxCount) {
return false;
}

Expand Down
23 changes: 22 additions & 1 deletion tests/AtLeastTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace ArrayLookup\Tests;

use ArrayIterator;
use ArrayLookup\AtLeast;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -46,7 +47,7 @@ public static function onceDataProvider(): array
}

#[DataProvider('twiceDataProvider')]
public function testTwice(array $data, callable $filter, bool $expected): void
public function testTwice(iterable $data, callable $filter, bool $expected): void
{
$this->assertSame(
$expected,
Expand Down Expand Up @@ -83,21 +84,41 @@ public static function twiceDataProvider(): array
static fn($datum): bool => $datum == 1,
false,
],
[
new ArrayIterator([1]),
static fn($datum): bool => $datum == 1,
false,
],
[
[1, "1"],
static fn($datum): bool => $datum == 1,
true,
],
[
new ArrayIterator([1, "1"]),
static fn($datum): bool => $datum == 1,
true,
],
[
[1, true],
static fn($datum): bool => $datum == 1,
true,
],
[
new ArrayIterator([1, true]),
static fn($datum): bool => $datum == 1,
true,
],
[
[1, true, "1"],
static fn($datum): bool => $datum == 1,
true,
],
[
new ArrayIterator([1, true, "1"]),
static fn($datum): bool => $datum == 1,
true,
],
];
}

Expand Down
23 changes: 22 additions & 1 deletion tests/OnlyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace ArrayLookup\Tests;

use ArrayIterator;
use ArrayLookup\Only;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -49,7 +50,7 @@ public static function onceDataProvider(): array

// phpcs:enable
#[DataProvider('twiceDataProvider')]
public function testTwice(array $data, callable $filter, bool $expected): void
public function testTwice(iterable $data, callable $filter, bool $expected): void
{
$this->assertSame(
$expected,
Expand Down Expand Up @@ -86,21 +87,41 @@ public static function twiceDataProvider(): array
static fn($datum): bool => $datum == 1,
false,
],
[
new ArrayIterator([1]),
static fn($datum): bool => $datum == 1,
false,
],
[
[1, "1"],
static fn($datum): bool => $datum == 1,
true,
],
[
new ArrayIterator([1, "1"]),
static fn($datum): bool => $datum == 1,
true,
],
[
[1, true],
static fn($datum): bool => $datum == 1,
true,
],
[
new ArrayIterator([1, true]),
static fn($datum): bool => $datum == 1,
true,
],
[
[1, true, "1"],
static fn($datum): bool => $datum == 1,
false,
],
[
new ArrayIterator([1, true, "1"]),
static fn($datum): bool => $datum == 1,
false,
],
];
}

Expand Down

0 comments on commit 7b182f7

Please sign in to comment.