fix handling null as empty data
This commit is contained in:
parent
c6eb79a514
commit
b5aa55dab9
|
@ -143,11 +143,11 @@ class NumberToLocalizedStringTransformer implements DataTransformerInterface
|
|||
*/
|
||||
public function reverseTransform($value)
|
||||
{
|
||||
if (!\is_string($value)) {
|
||||
if (null !== $value && !\is_string($value)) {
|
||||
throw new TransformationFailedException('Expected a string.');
|
||||
}
|
||||
|
||||
if ('' === $value) {
|
||||
if (null === $value || '' === $value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
@ -85,4 +85,19 @@ class NumberTypeTest extends BaseTypeTest
|
|||
$this->assertSame($expectedData, $form->getNormData());
|
||||
$this->assertSame($expectedData, $form->getData());
|
||||
}
|
||||
|
||||
public function testSubmitNullWithEmptyDataSetToNull()
|
||||
{
|
||||
$form = $this->factory->create(static::TESTED_TYPE, null, [
|
||||
'empty_data' => null,
|
||||
]);
|
||||
$form->submit(null);
|
||||
|
||||
$this->assertTrue($form->isSubmitted());
|
||||
$this->assertTrue($form->isSynchronized());
|
||||
$this->assertTrue($form->isValid());
|
||||
$this->assertSame('', $form->getViewData());
|
||||
$this->assertNull($form->getNormData());
|
||||
$this->assertNull($form->getData());
|
||||
}
|
||||
}
|
||||
|
|
Reference in New Issue