@@ -1543,6 +1543,62 @@ public function testToRawArrayRecursiveWithMixedAttributes(): void
15431543 $ this ->assertIsString ($ result2 ['created_at ' ]);
15441544 }
15451545
1546+ public function testToRawArrayDoesNotConvertDateTimeWhenNotDeclaredInDatesOrCasts (): void
1547+ {
1548+ $ entity = new class () extends Entity {
1549+ protected $ attributes = [
1550+ 'custom_date ' => null ,
1551+ ];
1552+ protected $ dates = [];
1553+ protected $ casts = [];
1554+ };
1555+
1556+ $ entity ->custom_date = Time ::parse ('2024-08-20 16:45:00 ' );
1557+
1558+ $ result = $ entity ->toRawArray ();
1559+ $ this ->assertInstanceOf (Time::class, $ result ['custom_date ' ]);
1560+ }
1561+
1562+ public function testToRawArrayRespectsCustomDateTimeStringConversion (): void
1563+ {
1564+ $ customDateTime = new class ('2024-08-20 16:45:00 ' ) extends DateTime {
1565+ public function __toString (): string
1566+ {
1567+ return 'custom-formatted-date ' ;
1568+ }
1569+ };
1570+
1571+ $ entity = new class () extends Entity {
1572+ protected $ attributes = [
1573+ 'created_at ' => null ,
1574+ ];
1575+ protected $ dates = [];
1576+ protected $ casts = [
1577+ 'created_at ' => 'datetime ' ,
1578+ ];
1579+ };
1580+
1581+ $ entity ->created_at = $ customDateTime ;
1582+
1583+ $ result = $ entity ->toRawArray ();
1584+ $ this ->assertSame ('custom-formatted-date ' , $ result ['created_at ' ]);
1585+ }
1586+
1587+ public function testToRawArrayConvertsNativeDateTimeToString (): void
1588+ {
1589+ $ entity = new class () extends Entity {
1590+ protected $ attributes = [
1591+ 'created_at ' => null ,
1592+ ];
1593+ protected $ dates = ['created_at ' ];
1594+ };
1595+
1596+ $ entity ->created_at = new DateTime ('2024-08-20 16:45:00 ' );
1597+
1598+ $ result = $ entity ->toRawArray ();
1599+ $ this ->assertSame ('2024-08-20 16:45:00 ' , $ result ['created_at ' ]);
1600+ }
1601+
15461602 public function testFilledConstruction (): void
15471603 {
15481604 $ data = [
0 commit comments