Skip to content

Commit 60a8a39

Browse files
committed
Merge branch '6.1' into 6.2
* 6.1: [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 a55e834 + 6723f2c commit 60a8a39

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
{
@@ -1086,6 +1089,30 @@ public function testFileUpload()
10861089
$this->assertNull($this->form->get('bar')->getData());
10871090
}
10881091

1092+
public function testMapDateTimeObjectsWithEmptyArrayData()
1093+
{
1094+
$propertyAccessor = PropertyAccess::createPropertyAccessorBuilder()
1095+
->enableExceptionOnInvalidIndex()
1096+
->getPropertyAccessor();
1097+
$form = $this->factory->createBuilder()
1098+
->setDataMapper(new PropertyPathMapper($propertyAccessor))
1099+
->add('date', DateType::class, [
1100+
'auto_initialize' => false,
1101+
'format' => 'dd/MM/yyyy',
1102+
'html5' => false,
1103+
'model_timezone' => 'UTC',
1104+
'view_timezone' => 'UTC',
1105+
'widget' => 'single_text',
1106+
])
1107+
->getForm();
1108+
1109+
$form->submit([
1110+
'date' => '04/08/2022',
1111+
]);
1112+
1113+
$this->assertEquals(['date' => new \DateTime('2022-08-04', new \DateTimeZone('UTC'))], $form->getData());
1114+
}
1115+
10891116
private function createForm(string $name = 'name', bool $compound = true): FormInterface
10901117
{
10911118
$builder = $this->getBuilder($name);

0 commit comments

Comments
 (0)