1212namespace Symfony \Component \Form \Tests \Extension \Core \Type ;
1313
1414use Symfony \Component \Form \FormError ;
15+ use Symfony \Component \Form \FormInterface ;
1516
1617class DateTimeTypeTest extends BaseTypeTest
1718{
@@ -608,6 +609,9 @@ public function testSubmitNullUsesDateEmptyData($widget, $emptyData, $expectedDa
608609 ]);
609610 $ form ->submit (null );
610611
612+ if ($ emptyData instanceof \Closure) {
613+ $ emptyData = $ emptyData ($ form );
614+ }
611615 $ this ->assertSame ($ emptyData , $ form ->getViewData ());
612616 $ this ->assertEquals ($ expectedData , $ form ->getNormData ());
613617 $ this ->assertEquals ($ expectedData , $ form ->getData ());
@@ -616,11 +620,17 @@ public function testSubmitNullUsesDateEmptyData($widget, $emptyData, $expectedDa
616620 public function provideEmptyData ()
617621 {
618622 $ expectedData = \DateTime::createFromFormat ('Y-m-d H:i ' , '2018-11-11 21:23 ' );
623+ $ lazyEmptyData = static function (FormInterface $ form ) {
624+ return $ form ->getConfig ()->getCompound () ? ['date ' => ['year ' => '2018 ' , 'month ' => '11 ' , 'day ' => '11 ' ], 'time ' => ['hour ' => '21 ' , 'minute ' => '23 ' ]] : '2018-11-11T21:23:00 ' ;
625+ };
619626
620627 return [
621628 'Simple field ' => ['single_text ' , '2018-11-11T21:23:00 ' , $ expectedData ],
622629 'Compound text field ' => ['text ' , ['date ' => ['year ' => '2018 ' , 'month ' => '11 ' , 'day ' => '11 ' ], 'time ' => ['hour ' => '21 ' , 'minute ' => '23 ' ]], $ expectedData ],
623630 'Compound choice field ' => ['choice ' , ['date ' => ['year ' => '2018 ' , 'month ' => '11 ' , 'day ' => '11 ' ], 'time ' => ['hour ' => '21 ' , 'minute ' => '23 ' ]], $ expectedData ],
631+ 'Simple field lazy ' => ['single_text ' , $ lazyEmptyData , $ expectedData ],
632+ 'Compound text field lazy ' => ['text ' , $ lazyEmptyData , $ expectedData ],
633+ 'Compound choice field lazy ' => ['choice ' , $ lazyEmptyData , $ expectedData ],
624634 ];
625635 }
626636}
0 commit comments