Skip to content

Commit cc238eb

Browse files
Merge branch '5.0' into 5.1
* 5.0: minor #37121 [Contracts] Add missing "extra.thanks" entries in composer.json (nicolas-grekas) [Process] Fix Permission Denied error when writing sf_proc_00 lock files on Windows fix handling null as empty data No need to create an issue when creating a PR Use ">=" for the "php" requirement [HttpClient] Fix promise behavior in HttplugClient [Console] Fixes question input encoding on Windows
2 parents 7ac6005 + 288e0f5 commit cc238eb

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

Extension/Core/DataTransformer/NumberToLocalizedStringTransformer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,11 @@ public function transform($value)
126126
*/
127127
public function reverseTransform($value)
128128
{
129-
if (!\is_string($value)) {
129+
if (null !== $value && !\is_string($value)) {
130130
throw new TransformationFailedException('Expected a string.');
131131
}
132132

133-
if ('' === $value) {
133+
if (null === $value || '' === $value) {
134134
return null;
135135
}
136136

Tests/Extension/Core/Type/NumberTypeTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,21 @@ public function testSubmitNullUsesDefaultEmptyData($emptyData = '10', $expectedD
124124
$this->assertSame($expectedData, $form->getData());
125125
}
126126

127+
public function testSubmitNullWithEmptyDataSetToNull()
128+
{
129+
$form = $this->factory->create(static::TESTED_TYPE, null, [
130+
'empty_data' => null,
131+
]);
132+
$form->submit(null);
133+
134+
$this->assertTrue($form->isSubmitted());
135+
$this->assertTrue($form->isSynchronized());
136+
$this->assertTrue($form->isValid());
137+
$this->assertSame('', $form->getViewData());
138+
$this->assertNull($form->getNormData());
139+
$this->assertNull($form->getData());
140+
}
141+
127142
public function testSubmitNumericInput(): void
128143
{
129144
$form = $this->factory->create(static::TESTED_TYPE, null, ['input' => 'number']);

0 commit comments

Comments
 (0)