File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed
Expand file tree Collapse file tree 1 file changed +20
-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,21 @@ public static function lastReturnKeyResortKeyDataProvider(): array
254259 ];
255260 }
256261
262+ public function testLastKeepCurrentOriginalData (): void
263+ {
264+ $ obj = new stdClass ();
265+ $ obj ->data = new ArrayIterator ([new DateTime ('now ' ), new DateTimeImmutable ('now ' ), new stdClass ()]);
266+
267+ // get last
268+ $ last = Finder::last ($ obj ->data , static fn (object $ datum ): bool => $ datum instanceof DateTimeInterface);
269+ $ this ->assertInstanceOf (DateTimeImmutable::class, $ last );
270+
271+ // keep first record not changed from data
272+ $ this ->assertInstanceOf (DateTime::class, $ obj ->data [0 ]);
273+ $ arrayCopy = $ obj ->data ->getArrayCopy ();
274+ $ this ->assertSame (DateTime::class, current ($ arrayCopy )::class);
275+ }
276+
257277 #[DataProvider('rowsDataProvider ' )]
258278 public function testRows (iterable $ data , callable $ filter , array $ expected ): void
259279 {
You can’t perform that action at this time.
0 commit comments