Skip to content

Commit e4cf75b

Browse files
committed
Merge branch '7.1' into 7.2
* 7.1: (31 commits) [Serializer] Remove useless calls to `func_get_arg()` fix tests using Twig 3.12 skip tests requiring the intl extension if it's not installed 🐛 throw ParseException on invalid date [FrameworkBundle] Re-remove redundant name attribute from `default_context` fix permitted data type of the default choice [ExpressionLanguage] Improve test coverage Fix invalid phpdoc in ContainerBuilder [HttpKernel] [WebProfileBundle] Fix Routing panel for URLs with a colon [Form] NumberType: Fix parsing of numbers in exponential notation with negative exponent Fix importing PHP config in prepend extension method [Messenger] Prevent waiting time to overflow when using long delays [Security] consistent singular/plural translation in Dutch reset the validation context after validating nested constraints do not duplicate directory separators fix handling empty data in ValueToDuplicatesTransformer fix compatibility with redis extension 6.0.3+ synchronize unsupported scheme tests [String] Fixed Quorum plural, that was inflected to be only "Quora" and never "Quorums" Fix symfony/kaz-info-teh-notifier package ...
2 parents 98ba9d2 + 3018ad1 commit e4cf75b

File tree

5 files changed

+64
-3
lines changed

5 files changed

+64
-3
lines changed

Extension/Core/DataTransformer/NumberToLocalizedStringTransformer.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,8 @@ public function reverseTransform(mixed $value): int|float|null
102102
$value = str_replace(',', $decSep, $value);
103103
}
104104

105-
if (str_contains($value, $decSep)) {
105+
//If the value is in exponential notation with a negative exponent, we end up with a float value too
106+
if (str_contains($value, $decSep) || false !== stripos($value, 'e-')) {
106107
$type = \NumberFormatter::TYPE_DOUBLE;
107108
} else {
108109
$type = \PHP_INT_SIZE === 8

Extension/Core/DataTransformer/ValueToDuplicatesTransformer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public function reverseTransform(mixed $array): mixed
5656
$emptyKeys = [];
5757

5858
foreach ($this->keys as $key) {
59-
if (isset($array[$key]) && '' !== $array[$key] && false !== $array[$key] && [] !== $array[$key]) {
59+
if (isset($array[$key]) && false !== $array[$key] && [] !== $array[$key]) {
6060
if ($array[$key] !== $result) {
6161
throw new TransformationFailedException('All values in the array should be the same.');
6262
}

Tests/Extension/Core/DataTransformer/NumberToLocalizedStringTransformerTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,4 +632,33 @@ public function testReverseTransformSmallInt()
632632

633633
$this->assertSame(1.0, $transformer->reverseTransform('1'));
634634
}
635+
636+
/**
637+
* @dataProvider eNotationProvider
638+
*/
639+
public function testReverseTransformENotation($output, $input)
640+
{
641+
IntlTestHelper::requireFullIntl($this);
642+
643+
\Locale::setDefault('en');
644+
645+
$transformer = new NumberToLocalizedStringTransformer();
646+
647+
$this->assertSame($output, $transformer->reverseTransform($input));
648+
}
649+
650+
public static function eNotationProvider(): array
651+
{
652+
return [
653+
[0.001, '1E-3'],
654+
[0.001, '1.0E-3'],
655+
[0.001, '1e-3'],
656+
[0.001, '1.0e-03'],
657+
[1000.0, '1E3'],
658+
[1000.0, '1.0E3'],
659+
[1000.0, '1e3'],
660+
[1000.0, '1.0e3'],
661+
[1232.0, '1.232e3'],
662+
];
663+
}
635664
}

Tests/Extension/Core/DataTransformer/ValueToDuplicatesTransformerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function testReverseTransformCompletelyEmpty()
6565
'c' => '',
6666
];
6767

68-
$this->assertNull($this->transformer->reverseTransform($input));
68+
$this->assertSame('', $this->transformer->reverseTransform($input));
6969
}
7070

7171
public function testReverseTransformCompletelyNull()

Tests/Extension/Core/Type/RepeatedTypeTest.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Form\Tests\Extension\Core\Type;
1313

1414
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
15+
use Symfony\Component\Form\Extension\Core\Type\TextType;
1516
use Symfony\Component\Form\Form;
1617
use Symfony\Component\Form\Tests\Fixtures\NotMappedType;
1718
use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
@@ -189,6 +190,36 @@ public function testSetOptionsPerChildAndOverwrite()
189190
$this->assertTrue($form['second']->isRequired());
190191
}
191192

193+
/**
194+
* @dataProvider emptyDataProvider
195+
*/
196+
public function testSubmitNullForTextTypeWithEmptyDataOptionSetToEmptyString($emptyData, $submittedData, $expected)
197+
{
198+
$form = $this->factory->create(static::TESTED_TYPE, null, [
199+
'type' => TextType::class,
200+
'options' => [
201+
'empty_data' => $emptyData,
202+
]
203+
]);
204+
$form->submit($submittedData);
205+
206+
$this->assertSame($expected, $form->getData());
207+
}
208+
209+
public static function emptyDataProvider()
210+
{
211+
yield ['', null, ''];
212+
yield ['', ['first' => null, 'second' => null], ''];
213+
yield ['', ['first' => '', 'second' => null], ''];
214+
yield ['', ['first' => null, 'second' => ''], ''];
215+
yield ['', ['first' => '', 'second' => ''], ''];
216+
yield [null, null, null];
217+
yield [null, ['first' => null, 'second' => null], null];
218+
yield [null, ['first' => '', 'second' => null], null];
219+
yield [null, ['first' => null, 'second' => ''], null];
220+
yield [null, ['first' => '', 'second' => ''], null];
221+
}
222+
192223
public function testSubmitUnequal()
193224
{
194225
$input = ['first' => 'foo', 'second' => 'bar'];

0 commit comments

Comments
 (0)