File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed
Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change 77use ArrayIterator ;
88use ArrayLookup \Finder ;
99use ArrayObject ;
10+ use DateTime ;
11+ use DateTimeImmutable ;
12+ use DateTimeInterface ;
1013use Generator ;
1114use PHPUnit \Framework \Attributes \DataProvider ;
1215use PHPUnit \Framework \TestCase ;
16+ use stdClass ;
1317
18+ use function current ;
1419use function str_contains ;
1520
1621final 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 {
You can’t perform that action at this time.
0 commit comments