Skip to content

Commit 33396a9

Browse files
committed
Merge branch '4.4' into 5.2
* 4.4: skip intl dependent tests if the extension is missing make DateCaster tests timezone-agnostic error if the input string couldn't be parsed as a date IntegerType: Always use en for IntegerToLocalizedStringTransformer Fixes #40456 Uses the correct assignment action for console options depending if they are short or long [HttpKernel] ConfigDataCollector to return known data without the need of a Kernel [HttpClient] fix using stream_copy_to_stream() with responses cast to php streams FIx Trying to clone an uncloneable object of class
2 parents 55dc304 + 9ced5b7 commit 33396a9

File tree

4 files changed

+46
-6
lines changed

4 files changed

+46
-6
lines changed

Extension/Core/DataTransformer/DateTimeToLocalizedStringTransformer.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ public function reverseTransform($value)
130130
} elseif ($timestamp > 253402214400) {
131131
// This timestamp represents UTC midnight of 9999-12-31 to prevent 5+ digit years
132132
throw new TransformationFailedException('Years beyond 9999 are not supported.');
133+
} elseif (false === $timestamp) {
134+
// the value couldn't be parsed but the Intl extension didn't report an error code, this
135+
// could be the case when the Intl polyfill is used which always returns 0 as the error code
136+
throw new TransformationFailedException(sprintf('"%s" could not be parsed as a date.', $value));
133137
}
134138

135139
try {

Extension/Core/DataTransformer/IntegerToLocalizedStringTransformer.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@ class IntegerToLocalizedStringTransformer extends NumberToLocalizedStringTransfo
2424
/**
2525
* Constructs a transformer.
2626
*
27-
* @param bool $grouping Whether thousands should be grouped
28-
* @param int $roundingMode One of the ROUND_ constants in this class
27+
* @param bool $grouping Whether thousands should be grouped
28+
* @param int $roundingMode One of the ROUND_ constants in this class
29+
* @param string|null $locale locale used for transforming
2930
*/
30-
public function __construct(?bool $grouping = false, ?int $roundingMode = \NumberFormatter::ROUND_DOWN)
31+
public function __construct(?bool $grouping = false, ?int $roundingMode = \NumberFormatter::ROUND_DOWN, ?string $locale)
3132
{
32-
parent::__construct(0, $grouping, $roundingMode);
33+
parent::__construct(0, $grouping, $roundingMode, $locale);
3334
}
3435

3536
/**

Extension/Core/Type/IntegerType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class IntegerType extends AbstractType
2626
*/
2727
public function buildForm(FormBuilderInterface $builder, array $options)
2828
{
29-
$builder->addViewTransformer(new IntegerToLocalizedStringTransformer($options['grouping'], $options['rounding_mode']));
29+
$builder->addViewTransformer(new IntegerToLocalizedStringTransformer($options['grouping'], $options['rounding_mode'], !$options['grouping'] ? 'en' : null));
3030
}
3131

3232
/**

Tests/Extension/Core/Type/IntegerTypeTest.php

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,48 @@ class IntegerTypeTest extends BaseTypeTest
1717
{
1818
public const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\IntegerType';
1919

20+
private $previousLocale;
21+
2022
protected function setUp(): void
2123
{
2224
IntlTestHelper::requireIntl($this, false);
23-
25+
$this->previousLocale = \Locale::getDefault();
2426
parent::setUp();
2527
}
2628

29+
protected function tearDown(): void
30+
{
31+
\Locale::setDefault($this->previousLocale);
32+
}
33+
34+
/**
35+
* @requires extension intl
36+
*/
37+
public function testArabicLocale()
38+
{
39+
\Locale::setDefault('ar');
40+
41+
$form = $this->factory->create(static::TESTED_TYPE);
42+
$form->submit('123456');
43+
44+
$this->assertSame(123456, $form->getData());
45+
$this->assertSame('123456', $form->getViewData());
46+
}
47+
48+
/**
49+
* @requires extension intl
50+
*/
51+
public function testArabicLocaleNonHtml5()
52+
{
53+
\Locale::setDefault('ar');
54+
55+
$form = $this->factory->create(static::TESTED_TYPE, null, ['grouping' => true]);
56+
$form->submit('123456');
57+
58+
$this->assertSame(123456, $form->getData());
59+
$this->assertSame('١٢٣٬٤٥٦', $form->getViewData());
60+
}
61+
2762
public function testSubmitRejectsFloats()
2863
{
2964
$form = $this->factory->create(static::TESTED_TYPE);

0 commit comments

Comments
 (0)