This repository was archived by the owner on Nov 1, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +41
-1
lines changed Expand file tree Collapse file tree 2 files changed +41
-1
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,6 @@ public function cast(mixed $value): DataTransferObject
20
20
}
21
21
}
22
22
23
- return new $ this ->classNames [0 ](... $ value );
23
+ return new $ this ->classNames [0 ]($ value );
24
24
}
25
25
}
Original file line number Diff line number Diff line change @@ -102,4 +102,44 @@ public function mapped_from_works_with_default_values()
102
102
$ this ->assertFalse ($ dto ->isPublic );
103
103
$ this ->assertEquals (42 , $ dto ->randomInt );
104
104
}
105
+
106
+ /** @test */
107
+ public function dto_can_have_numeric_keys ()
108
+ {
109
+ $ data = [
110
+ 'title ' => 'Hello world ' ,
111
+ '0 ' => 10 ,
112
+ ];
113
+
114
+ $ dto = new DTOInner ($ data );
115
+
116
+ $ this ->assertEquals ('Hello world ' , $ dto ->title );
117
+ $ this ->assertEquals (10 , $ dto ->zero );
118
+ }
119
+
120
+ /** @test */
121
+ public function dto_can_have_numeric_keys_in_nested_dto ()
122
+ {
123
+ $ data = [
124
+ 'innerDTO ' => [
125
+ 'title ' => 'Hello world ' ,
126
+ '0 ' => 10 ,
127
+ ],
128
+ ];
129
+
130
+ $ dtoOuter = new class ($ data ) extends DataTransferObject {
131
+ public DTOInner $ innerDTO ;
132
+ };
133
+
134
+ $ this ->assertEquals ('Hello world ' , $ dtoOuter ->innerDTO ->title );
135
+ $ this ->assertEquals (10 , $ dtoOuter ->innerDTO ->zero );
136
+ }
137
+ }
138
+
139
+ class DTOInner extends DataTransferObject
140
+ {
141
+ public string $ title ;
142
+
143
+ #[MapFrom('0 ' )]
144
+ public int $ zero ;
105
145
}
You can’t perform that action at this time.
0 commit comments