Skip to content

Commit

Permalink
Merge branch '6.4' into 7.1
Browse files Browse the repository at this point in the history
* 6.4: (23 commits)
  fix tests using Twig 3.12
  skip tests requiring the intl extension if it's not installed
  🐛 throw ParseException on invalid date
  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
  [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
  [Validator] review latvian translations
  [Validator] Add Dutch translation for `WordCount` constraint
  allow more unicode characters in URL paths
  [String][EnglishInflector] Fix words ending in 'le', e.g., articles
  ...
  • Loading branch information
derrabus committed Aug 12, 2024
2 parents 11df2e2 + 330d337 commit 3018ad1
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ public function reverseTransform(mixed $value): int|float|null
$value = str_replace(',', $decSep, $value);
}

if (str_contains($value, $decSep)) {
//If the value is in exponential notation with a negative exponent, we end up with a float value too
if (str_contains($value, $decSep) || false !== stripos($value, 'e-')) {
$type = \NumberFormatter::TYPE_DOUBLE;
} else {
$type = \PHP_INT_SIZE === 8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function reverseTransform(mixed $array): mixed
$emptyKeys = [];

foreach ($this->keys as $key) {
if (isset($array[$key]) && '' !== $array[$key] && false !== $array[$key] && [] !== $array[$key]) {
if (isset($array[$key]) && false !== $array[$key] && [] !== $array[$key]) {
if ($array[$key] !== $result) {
throw new TransformationFailedException('All values in the array should be the same.');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -632,4 +632,33 @@ public function testReverseTransformSmallInt()

$this->assertSame(1.0, $transformer->reverseTransform('1'));
}

/**
* @dataProvider eNotationProvider
*/
public function testReverseTransformENotation($output, $input)
{
IntlTestHelper::requireFullIntl($this);

\Locale::setDefault('en');

$transformer = new NumberToLocalizedStringTransformer();

$this->assertSame($output, $transformer->reverseTransform($input));
}

public static function eNotationProvider(): array
{
return [
[0.001, '1E-3'],
[0.001, '1.0E-3'],
[0.001, '1e-3'],
[0.001, '1.0e-03'],
[1000.0, '1E3'],
[1000.0, '1.0E3'],
[1000.0, '1e3'],
[1000.0, '1.0e3'],
[1232.0, '1.232e3'],
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function testReverseTransformCompletelyEmpty()
'c' => '',
];

$this->assertNull($this->transformer->reverseTransform($input));
$this->assertSame('', $this->transformer->reverseTransform($input));
}

public function testReverseTransformCompletelyNull()
Expand Down
31 changes: 31 additions & 0 deletions Tests/Extension/Core/Type/RepeatedTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Component\Form\Tests\Extension\Core\Type;

use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Form;
use Symfony\Component\Form\Tests\Fixtures\NotMappedType;
use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
Expand Down Expand Up @@ -188,6 +189,36 @@ public function testSetOptionsPerChildAndOverwrite()
$this->assertTrue($form['second']->isRequired());
}

/**
* @dataProvider emptyDataProvider
*/
public function testSubmitNullForTextTypeWithEmptyDataOptionSetToEmptyString($emptyData, $submittedData, $expected)
{
$form = $this->factory->create(static::TESTED_TYPE, null, [
'type' => TextType::class,
'options' => [
'empty_data' => $emptyData,
]
]);
$form->submit($submittedData);

$this->assertSame($expected, $form->getData());
}

public static function emptyDataProvider()
{
yield ['', null, ''];
yield ['', ['first' => null, 'second' => null], ''];
yield ['', ['first' => '', 'second' => null], ''];
yield ['', ['first' => null, 'second' => ''], ''];
yield ['', ['first' => '', 'second' => ''], ''];
yield [null, null, null];
yield [null, ['first' => null, 'second' => null], null];
yield [null, ['first' => '', 'second' => null], null];
yield [null, ['first' => null, 'second' => ''], null];
yield [null, ['first' => '', 'second' => ''], null];
}

public function testSubmitUnequal()
{
$input = ['first' => 'foo', 'second' => 'bar'];
Expand Down

0 comments on commit 3018ad1

Please sign in to comment.