Skip to content

Commit c0e95ef

Browse files
committed
Merge branch '5.4' into 6.0
* 5.4: [Translation] Fix Crowdin documentation urls ignore missing keys when mapping DateTime objects to uninitialized arrays fix writes to static $kernel property [Notifier] Fix test logic [Validator] Hint that `egulias/email-validator` needs to be installed for strict mode as default config
2 parents d3553e1 + 429f193 commit c0e95ef

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

Tests/CompoundFormTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
use Symfony\Component\EventDispatcher\EventDispatcher;
1616
use Symfony\Component\Form\Exception\AlreadySubmittedException;
1717
use Symfony\Component\Form\Extension\Core\DataMapper\DataMapper;
18+
use Symfony\Component\Form\Extension\Core\DataMapper\PropertyPathMapper;
19+
use Symfony\Component\Form\Extension\Core\Type\DateType;
1820
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
1921
use Symfony\Component\Form\Extension\Core\Type\TextType;
2022
use Symfony\Component\Form\Extension\HttpFoundation\HttpFoundationRequestHandler;
@@ -36,6 +38,7 @@
3638
use Symfony\Component\Form\Tests\Fixtures\Map;
3739
use Symfony\Component\HttpFoundation\File\UploadedFile;
3840
use Symfony\Component\HttpFoundation\Request;
41+
use Symfony\Component\PropertyAccess\PropertyAccess;
3942

4043
class CompoundFormTest extends TestCase
4144
{
@@ -1076,6 +1079,30 @@ public function testFileUpload()
10761079
$this->assertNull($this->form->get('bar')->getData());
10771080
}
10781081

1082+
public function testMapDateTimeObjectsWithEmptyArrayData()
1083+
{
1084+
$propertyAccessor = PropertyAccess::createPropertyAccessorBuilder()
1085+
->enableExceptionOnInvalidIndex()
1086+
->getPropertyAccessor();
1087+
$form = $this->factory->createBuilder()
1088+
->setDataMapper(new PropertyPathMapper($propertyAccessor))
1089+
->add('date', DateType::class, [
1090+
'auto_initialize' => false,
1091+
'format' => 'dd/MM/yyyy',
1092+
'html5' => false,
1093+
'model_timezone' => 'UTC',
1094+
'view_timezone' => 'UTC',
1095+
'widget' => 'single_text',
1096+
])
1097+
->getForm();
1098+
1099+
$form->submit([
1100+
'date' => '04/08/2022',
1101+
]);
1102+
1103+
$this->assertEquals(['date' => new \DateTime('2022-08-04', new \DateTimeZone('UTC'))], $form->getData());
1104+
}
1105+
10791106
private function createForm(string $name = 'name', bool $compound = true): FormInterface
10801107
{
10811108
$builder = $this->getBuilder($name);

0 commit comments

Comments
 (0)