@@ -109,8 +109,10 @@ test(function () { // submitted form + getValues()
109109 $ _SERVER ['REQUEST_METHOD ' ] = 'POST ' ;
110110
111111 $ form = createForm ();
112+ $ form ->setMappedType (FormData::class);
113+
112114 Assert::truthy ($ form ->isSubmitted ());
113- Assert::equal (ArrayHash:: from ( [
115+ Assert::equal (hydrate (FormData::class, [
114116 'title ' => 'sent title ' ,
115117 'first ' => ArrayHash::from ([
116118 'name ' => '' ,
@@ -127,12 +129,14 @@ test(function () { // submitted form + reset()
127129 $ _SERVER ['REQUEST_METHOD ' ] = 'POST ' ;
128130
129131 $ form = createForm ();
132+ $ form ->setMappedType (FormData::class);
133+
130134 Assert::truthy ($ form ->isSubmitted ());
131135
132136 $ form ->reset ();
133137
134138 Assert::false ($ form ->isSubmitted ());
135- Assert::equal (ArrayHash:: from ( [
139+ Assert::equal (hydrate (FormData::class, [
136140 'title ' => '' ,
137141 'first ' => ArrayHash::from ([
138142 'name ' => '' ,
@@ -149,6 +153,8 @@ test(function () { // setValues() + object
149153 $ _SERVER ['REQUEST_METHOD ' ] = 'POST ' ;
150154
151155 $ form = createForm ();
156+ $ form ->setMappedType (FormData::class);
157+
152158 Assert::truthy ($ form ->isSubmitted ());
153159
154160 $ form ->setValues (hydrate (FormData::class, [
@@ -159,7 +165,7 @@ test(function () { // setValues() + object
159165 ]),
160166 ]));
161167
162- Assert::equal (ArrayHash:: from ( [
168+ Assert::equal (hydrate (FormData::class, [
163169 'title ' => 'new1 ' ,
164170 'first ' => ArrayHash::from ([
165171 'name ' => 'new2 ' ,
@@ -178,7 +184,7 @@ test(function () { // setValues() + object
178184 ]),
179185 ]), true );
180186
181- Assert::equal (ArrayHash:: from ( [
187+ Assert::equal (hydrate (FormData::class, [
182188 'title ' => 'new1 ' ,
183189 'first ' => ArrayHash::from ([
184190 'name ' => 'new2 ' ,
@@ -191,10 +197,64 @@ test(function () { // setValues() + object
191197});
192198
193199
200+ test (function () { // getValues(...arguments...)
201+ $ _SERVER ['REQUEST_METHOD ' ] = null ;
202+
203+ $ form = createForm ();
204+
205+ $ form ->setValues ([
206+ 'title ' => 'new1 ' ,
207+ 'first ' => [
208+ 'name ' => 'new2 ' ,
209+ ],
210+ ]);
211+
212+ Assert::equal (hydrate (FormData::class, [
213+ 'title ' => 'new1 ' ,
214+ 'first ' => ArrayHash::from ([
215+ 'name ' => 'new2 ' ,
216+ 'age ' => null ,
217+ 'second ' => ArrayHash::from ([
218+ 'city ' => '' ,
219+ ]),
220+ ]),
221+ ]), $ form ->getValues (FormData::class));
222+
223+
224+ $ form ->setMappedType (FormData::class);
225+ $ form ['first ' ]->setMappedType (FormFirstLevel::class);
226+ $ form ['first-second ' ]->setMappedType (FormSecondLevel::class);
227+
228+ Assert::equal (hydrate (FormData::class, [
229+ 'title ' => 'new1 ' ,
230+ 'first ' => hydrate (FormFirstLevel::class, [
231+ 'name ' => 'new2 ' ,
232+ 'age ' => null ,
233+ 'second ' => hydrate (FormSecondLevel::class, [
234+ 'city ' => '' ,
235+ ]),
236+ ]),
237+ ]), $ form ->getValues ());
238+
239+ Assert::equal ([
240+ 'title ' => 'new1 ' ,
241+ 'first ' => [
242+ 'name ' => 'new2 ' ,
243+ 'age ' => null ,
244+ 'second ' => [
245+ 'city ' => '' ,
246+ ],
247+ ],
248+ ], $ form ->getValues (true ));
249+ });
250+
251+
194252test (function () { // onSuccess test
195253 $ _SERVER ['REQUEST_METHOD ' ] = 'POST ' ;
196254
197255 $ form = createForm ();
256+ $ form ->setMappedType (FormData::class);
257+
198258 $ form ->onSuccess [] = function (Form $ form , array $ values ) {
199259 Assert::same ([
200260 'title ' => 'sent title ' ,
@@ -222,7 +282,20 @@ test(function () { // onSuccess test
222282 };
223283
224284 $ form ->onSuccess [] = function (Form $ form , $ values ) {
225- Assert::equal (ArrayHash::from ([
285+ Assert::equal (hydrate (FormData::class, [
286+ 'title ' => 'sent title ' ,
287+ 'first ' => ArrayHash::from ([
288+ 'name ' => '' ,
289+ 'age ' => 999 ,
290+ 'second ' => ArrayHash::from ([
291+ 'city ' => 'sent city ' ,
292+ ]),
293+ ]),
294+ ]), $ values );
295+ };
296+
297+ $ form ->onSuccess [] = function (Form $ form , FormData $ values ) {
298+ Assert::equal (hydrate (FormData::class, [
226299 'title ' => 'sent title ' ,
227300 'first ' => ArrayHash::from ([
228301 'name ' => '' ,
0 commit comments