Skip to content

Commit

Permalink
use iterator_count()
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Apr 21, 2024
1 parent 7d600ee commit fdb31ba
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/AtLeast.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private static function atLeastFoundTimes(
// usage must be higher than 0
Assert::greaterThan($maxCount, 0);

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

Expand Down
2 changes: 1 addition & 1 deletion src/Only.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private static function onlyFoundTimes(
// usage must be higher than 0
Assert::greaterThan($maxCount, 0);

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

Expand Down
15 changes: 15 additions & 0 deletions tests/AtLeastTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,21 @@ public static function twiceDataProvider(): array
static fn($datum): bool => $datum == 1,
false,
],
[
[1, "1"],
static fn($datum): bool => $datum == 1,
true,
],
[
[1, true],
static fn($datum): bool => $datum == 1,
true,
],
[
[1, true, "1"],
static fn($datum): bool => $datum == 1,
true,
],
];
}

Expand Down
5 changes: 5 additions & 0 deletions tests/OnlyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ public static function twiceDataProvider(): array
static fn($datum): bool => $datum == 1,
false,
],
[
[1, "1"],
static fn($datum): bool => $datum == 1,
true,
],
];
}

Expand Down

0 comments on commit fdb31ba

Please sign in to comment.