Skip to content

Commit

Permalink
Merge pull request #18 from samsonasik/add-test
Browse files Browse the repository at this point in the history
Add test for keep original data after Finder::last() called
  • Loading branch information
samsonasik authored Apr 8, 2024
2 parents be860ef + 1a9ecdd commit a636081
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/FinderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@
use ArrayIterator;
use ArrayLookup\Finder;
use ArrayObject;
use DateTime;
use DateTimeImmutable;
use DateTimeInterface;
use Generator;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use stdClass;

use function current;
use function str_contains;

final class FinderTest extends TestCase
Expand Down Expand Up @@ -254,6 +259,18 @@ public static function lastReturnKeyResortKeyDataProvider(): array
];
}

public function testLastKeepCurrentOriginalData(): void
{
$data = [new DateTime('now'), new DateTimeImmutable('now'), new stdClass()];

// get last
$last = Finder::last($data, static fn(object $datum): bool => $datum instanceof DateTimeInterface);
$this->assertInstanceOf(DateTimeImmutable::class, $last);

// keep first record not changed from data
$this->assertSame(DateTime::class, current($data)::class);
}

#[DataProvider('rowsDataProvider')]
public function testRows(iterable $data, callable $filter, array $expected): void
{
Expand Down

0 comments on commit a636081

Please sign in to comment.