Skip to content

[Form] deprecate precision in IntegerToLocalizedStringTransformer #28569

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions UPGRADE-4.2.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ Finder
Form
----

* The `$scale` argument of the `IntegerToLocalizedStringTransformer` is deprecated.

* Deprecated calling `FormRenderer::searchAndRenderBlock` for fields which were already rendered.
Instead of expecting such calls to return empty strings, check if the field has already been rendered.

Expand Down
5 changes: 5 additions & 0 deletions UPGRADE-5.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ EventDispatcher

* The `TraceableEventDispatcherInterface` has been removed.

Form
----

* The `$scale` argument of the `IntegerToLocalizedStringTransformer` was removed.

Finder
------

Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/Form/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ CHANGELOG
4.2.0
-----

* deprecated the `$scale` argument of the `IntegerToLocalizedStringTransformer`
* added `Symfony\Component\Form\ClearableErrorsInterface`
* deprecated calling `FormRenderer::searchAndRenderBlock` for fields which were already rendered

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,18 @@ class IntegerToLocalizedStringTransformer extends NumberToLocalizedStringTransfo
/**
* Constructs a transformer.
*
* @param int $scale Unused
* @param bool $grouping Whether thousands should be grouped
* @param int $roundingMode One of the ROUND_ constants in this class
*/
public function __construct(?int $scale = 0, ?bool $grouping = false, int $roundingMode = self::ROUND_DOWN)
public function __construct($grouping = false, $roundingMode = self::ROUND_DOWN)
{
if (\is_int($grouping) || \is_bool($roundingMode) || 2 < \func_num_args()) {
@trigger_error(sprintf('Passing a precision as the first value to %s::__construct() is deprecated since Symfony 4.2 and support for it will be dropped in 5.0.', __CLASS__), E_USER_DEPRECATED);

$grouping = $roundingMode;
$roundingMode = 2 < \func_num_args() ? func_get_arg(2) : self::ROUND_DOWN;
}

parent::__construct(0, $grouping, $roundingMode);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,7 @@ class IntegerType extends AbstractType
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->addViewTransformer(
new IntegerToLocalizedStringTransformer(
$options['scale'],
$options['grouping'],
$options['rounding_mode']
));
$builder->addViewTransformer(new IntegerToLocalizedStringTransformer($options['grouping'], $options['rounding_mode']));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@ public function transformWithRoundingProvider()
* @dataProvider transformWithRoundingProvider
*/
public function testTransformWithRounding($input, $output, $roundingMode)
{
$transformer = new IntegerToLocalizedStringTransformer(null, $roundingMode);

$this->assertEquals($output, $transformer->transform($input));
}

/**
* @group legacy
* @expectedDeprecation Passing a precision as the first value to %s::__construct() is deprecated since Symfony 4.2 and support for it will be dropped in 5.0.
* @dataProvider transformWithRoundingProvider
*/
public function testTransformWithRoundingUsingLegacyConstructorSignature($input, $output, $roundingMode)
{
$transformer = new IntegerToLocalizedStringTransformer(null, null, $roundingMode);

Expand Down Expand Up @@ -114,6 +126,25 @@ public function testReverseTransformWithGrouping()

\Locale::setDefault('de_DE');

$transformer = new IntegerToLocalizedStringTransformer(true);

$this->assertEquals(1234, $transformer->reverseTransform('1.234,5'));
$this->assertEquals(12345, $transformer->reverseTransform('12.345,912'));
$this->assertEquals(1234, $transformer->reverseTransform('1234,5'));
$this->assertEquals(12345, $transformer->reverseTransform('12345,912'));
}

/**
* @group legacy
* @expectedDeprecation Passing a precision as the first value to %s::__construct() is deprecated since Symfony 4.2 and support for it will be dropped in 5.0.
*/
public function testReverseTransformWithGroupingUsingLegacyConstructorSignature()
{
// Since we test against "de_DE", we need the full implementation
IntlTestHelper::requireFullIntl($this, false);

\Locale::setDefault('de_DE');

$transformer = new IntegerToLocalizedStringTransformer(null, true);

$this->assertEquals(1234, $transformer->reverseTransform('1.234,5'));
Expand Down Expand Up @@ -177,6 +208,18 @@ public function reverseTransformWithRoundingProvider()
* @dataProvider reverseTransformWithRoundingProvider
*/
public function testReverseTransformWithRounding($input, $output, $roundingMode)
{
$transformer = new IntegerToLocalizedStringTransformer(null, $roundingMode);

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

/**
* @group legacy
* @expectedDeprecation Passing a precision as the first value to %s::__construct() is deprecated since Symfony 4.2 and support for it will be dropped in 5.0.
* @dataProvider reverseTransformWithRoundingProvider
*/
public function testReverseTransformWithRoundingUsingLegacyConstructorSignature($input, $output, $roundingMode)
{
$transformer = new IntegerToLocalizedStringTransformer(null, null, $roundingMode);

Expand Down