8000 Merge branch '6.1' into 6.2 · enumag/symfony@001cbe7 · GitHub < 8000 meta name="theme-color" content="#1e2327">
[go: up one dir, main page]

Skip to content

Commit 001cbe7

Browse files
committed
Merge branch '6.1' into 6.2
* 6.1: clean up legacy test fix dispatch signal event check for compatibility with the contract interface ignore missing keys when mapping DateTime objects to uninitialized arrays
2 parents b1521f3 + 0b8581e commit 001cbe7

File tree

4 files changed

+41
-6
lines changed

4 files changed

+41
-6
lines changed

src/Symfony/Component/Console/Application.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -958,9 +958,8 @@ protected function doRunCommand(Command $command, InputInterface $input, OutputI
958958

959959
if ($this->signalsToDispatchEvent) {
960960
$commandSignals = $command instanceof SignalableCommandInterface ? $command->getSubscribedSignals() : [];
961-
$dispatchSignals = $this->dispatcher && $this->dispatcher->hasListeners(ConsoleEvents::SIGNAL);
962961

963-
if ($commandSignals || $dispatchSignals) {
962+
if ($commandSignals || null !== $this->dispatcher) {
964963
if (!$this->signalRegistry) {
965964
throw new RuntimeException('Unable to subscribe to signal events. Make sure that the `pcntl` extension is installed and that "pcntl_*" functions are not disabled by your php.ini\'s "disable_functions" directive.');
966965
}
@@ -980,7 +979,7 @@ protected function doRunCommand(Command $command, InputInterface $input, OutputI
980979
}
981980
}
982981

983-
if ($dispatchSignals) {
982+
if (null !== $this->dispatcher) {
984983
foreach ($this->signalsToDispatchEvent as $signal) {
985984
$event = new ConsoleSignalEvent($command, $input, $output, $signal);
986985

src/Symfony/Component/Form/Extension/Core/DataAccessor/PropertyPathAccessor.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\Form\Exception\AccessException;
1616
use Symfony\Component\Form\FormInterface;
1717
use Symfony\Component\PropertyAccess\Exception\AccessException as PropertyAccessException;
18+
use Symfony\Component\PropertyAccess\Exception\NoSuchIndexException;
1819
use Symfony\Component\PropertyAccess\Exception\UninitializedPropertyException;
1920
use Symfony\Component\PropertyAccess\PropertyAccess;
2021
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
@@ -90,6 +91,10 @@ private function getPropertyValue(object|array $data, PropertyPathInterface $pro
9091
try {
9192
return $this->propertyAccessor->getValue($data, $propertyPath);
9293
} catch (PropertyAccessException $e) {
94+
if (\is_array($data) && $e instanceof NoSuchIndexException) {
95+
return null;
96+
}
97+
9398
if (!$e instanceof UninitializedPropertyException
9499
// For versions without UninitializedPropertyException check the exception message
95100
&& (class_exists(UninitializedPropertyException::class) || !str_contains($e->getMessage(), 'You should initialize it'))

src/Symfony/Component/Form/Tests/CompoundFormTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\EventDispatcher\EventDispatcher;
1616
use Symfony\Component\Form\Exception\AlreadySubmittedException;
17+
use Symfony\Component\Form\Extension\Core\DataAccessor\PropertyPathAccessor;
1718
use Symfony\Component\Form\Extension\Core\DataMapper\DataMapper;
18-
use Symfony\Component\Form\Extension\Core\DataMapper\PropertyPathMapper;
1919
use Symfony\Component\Form\Extension\Core\Type\DateType;
2020
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
2121
use Symfony\Component\Form\Extension\Core\Type\TextType;
@@ -1089,13 +1089,13 @@ public function testFileUpload()
10891089
$this->assertNull($this->form->get('bar')->getData());
10901090
}
10911091

1092-
public function testMapDateTimeObjectsWithEmptyArrayData()
1092+
public function testMapDateTimeObjectsWithEmptyArrayDataUsingDataMapper()
10931093
{
10941094
$propertyAccessor = PropertyAccess::createPropertyAccessorBuilder()
10951095
->enableExceptionOnInvalidIndex()
10961096
->getPropertyAccessor();
10971097
$form = $this->factory->createBuilder()
1098-
->setDataMapper(new PropertyPathMapper($propertyAccessor))
1098+
->setDataMapper(new DataMapper(new PropertyPathAccessor($propertyAccessor)))
10991099
->add('date', DateType::class, [
11001100
'auto_initialize' => false,
11011101
'format' => 'dd/MM/yyyy',

src/Symfony/Component/Form/Tests/Extension/Core/DataMapper/DataMapperTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@
1414
use PHPUnit\Framework\TestCase;
1515
use Symfony\Component\EventDispatcher\EventDispatcher;
1616
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
17+
use Symfony\Component\Form\Extension\Core\DataAccessor\PropertyPathAccessor;
1718
use Symfony\Component\Form\Extension\Core\DataMapper\DataMapper;
19+
use Symfony\Component\Form\Extension\Core\Type\DateType;
1820
use Symfony\Component\Form\Form;
1921
use Symfony\Component\Form\FormConfigBuilder;
22+
use Symfony\Component\Form\FormFactoryBuilder;
2023
use Symfony\Component\Form\Tests\Fixtures\TypehintedPropertiesCar;
24+
use Symfony\Component\PropertyAccess\PropertyAccess;
2125
use Symfony\Component\PropertyAccess\PropertyPath;
2226

2327
class DataMapperTest extends TestCase
@@ -382,6 +386,33 @@ public function testMapFormsToDataUsingSetCallbackOption()
382386

383387
self::assertSame('Jane Doe', $person->myName());
384388
}
389+
390+
public function testMapFormsToDataMapsDateTimeInstanceToArrayIfNotSetBefore()
391+
{
392+
$propertyAccessor = PropertyAccess::createPropertyAccessorBuilder()
393+
->enableExceptionOnInvalidIndex()
394+
->getPropertyAccessor();
395+
$propertyAccessor = PropertyAccess::createPropertyAccessorBuilder()
396+
->enableExceptionOnInvalidIndex()
397+
->getPropertyAccessor();
398+
$form = (new FormFactoryBuilder())->getFormFactory()->createBuilder()
399+
->setDataMapper(new DataMapper(new PropertyPathAccessor($propertyAccessor)))
400+
->add('date', DateType::class, [
401+
'auto_initialize' => false,
402+
'format' => 'dd/MM/yyyy',
403+
'html5' => false,
404+
'model_timezone' => 'UTC',
405+
'view_timezone' => 'UTC',
406+
'widget' => 'single_text',
407+
])
408+
->getForm();
409+
410+
$form->submit([
411+
'date' => '04/08/2022',
412+
]);
413+
414+
$this->assertEquals(['date' => new \DateTime('2022-08-04', new \DateTimeZone('UTC'))], $form->getData());
415+
}
385416
}
386417

387418
class SubmittedForm extends Form

0 commit comments

Comments
 (0)
0