Skip to content

Commit a636081

Browse files
authored
Merge pull request #18 from samsonasik/add-test
Add test for keep original data after Finder::last() called
2 parents be860ef + 1a9ecdd commit a636081

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

tests/FinderTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,15 @@
77
use ArrayIterator;
88
use ArrayLookup\Finder;
99
use ArrayObject;
10+
use DateTime;
11+
use DateTimeImmutable;
12+
use DateTimeInterface;
1013
use Generator;
1114
use PHPUnit\Framework\Attributes\DataProvider;
1215
use PHPUnit\Framework\TestCase;
16+
use stdClass;
1317

18+
use function current;
1419
use function str_contains;
1520

1621
final class FinderTest extends TestCase
@@ -254,6 +259,18 @@ public static function lastReturnKeyResortKeyDataProvider(): array
254259
];
255260
}
256261

262+
public function testLastKeepCurrentOriginalData(): void
263+
{
264+
$data = [new DateTime('now'), new DateTimeImmutable('now'), new stdClass()];
265+
266+
// get last
267+
$last = Finder::last($data, static fn(object $datum): bool => $datum instanceof DateTimeInterface);
268+
$this->assertInstanceOf(DateTimeImmutable::class, $last);
269+
270+
// keep first record not changed from data
271+
$this->assertSame(DateTime::class, current($data)::class);
272+
}
273+
257274
#[DataProvider('rowsDataProvider')]
258275
public function testRows(iterable $data, callable $filter, array $expected): void
259276
{

0 commit comments

Comments
 (0)