Skip to content

Commit f114925

Browse files
committed
Merge branch '4.2'
* 4.2: allow to skip tests based on the supported version Update validators.bg.xlf Update validators.ca.xlf fixed CS Updated validators.eu.xlf with missing translations fixed typo backported a translation [Validator] added missing translation for UK validator Validator: add the Persian translations Update validators.sq.xlf fixed CS forward valid numeric values to transform() add constraint validators before optimizations
2 parents d51d8f6 + b5a5242 commit f114925

File tree

6 files changed

+62
-2
lines changed

6 files changed

+62
-2
lines changed

Extension/Core/DataTransformer/MoneyToLocalizedStringTransformer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function transform($value)
5858
if (!is_numeric($value)) {
5959
throw new TransformationFailedException('Expected a numeric.');
6060
}
61-
$value = (string) ($value / $this->divisor);
61+
$value /= $this->divisor;
6262
}
6363

6464
return parent::transform($value);

Test/FormPerformanceTestCase.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Component\Form\Test;
1313

14+
use Symfony\Component\Form\Tests\VersionAwareTest;
15+
1416
/**
1517
* Base class for performance tests.
1618
*
@@ -21,6 +23,8 @@
2123
*/
2224
abstract class FormPerformanceTestCase extends FormIntegrationTestCase
2325
{
26+
use VersionAwareTest;
27+
2428
/**
2529
* @var int
2630
*/

Tests/AbstractLayoutTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
abstract class AbstractLayoutTest extends FormIntegrationTestCase
2121
{
22+
use VersionAwareTest;
23+
2224
protected $csrfTokenManager;
2325
protected $testableFeatures = [];
2426

Tests/Extension/Core/DataTransformer/MoneyToLocalizedStringTransformerTest.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@
1717

1818
class MoneyToLocalizedStringTransformerTest extends TestCase
1919
{
20+
private $previousLocale;
21+
22+
protected function setUp()
23+
{
24+
$this->previousLocale = setlocale(LC_ALL, '0');
25+
}
26+
27+
protected function tearDown()
28+
{
29+
setlocale(LC_ALL, $this->previousLocale);
30+
}
31+
2032
public function testTransform()
2133
{
2234
// Since we test against "de_AT", we need the full implementation
@@ -73,7 +85,7 @@ public function testReverseTransformEmpty()
7385
$this->assertNull($transformer->reverseTransform(''));
7486
}
7587

76-
public function testFloatToIntConversionMismatchOnReversTransform()
88+
public function testFloatToIntConversionMismatchOnReverseTransform()
7789
{
7890
$transformer = new MoneyToLocalizedStringTransformer(null, null, null, 100);
7991
IntlTestHelper::requireFullIntl($this, false);
@@ -90,4 +102,16 @@ public function testFloatToIntConversionMismatchOnTransform()
90102

91103
$this->assertSame('10,20', $transformer->transform(1020));
92104
}
105+
106+
public function testValidNumericValuesWithNonDotDecimalPointCharacter()
107+
{
108+
// calling setlocale() here is important as it changes the representation of floats when being cast to strings
109+
setlocale(LC_ALL, 'de_AT.UTF-8');
110+
111+
$transformer = new MoneyToLocalizedStringTransformer(4, null, null, 100);
112+
IntlTestHelper::requireFullIntl($this, false);
113+
\Locale::setDefault('de_AT');
114+
115+
$this->assertSame('0,0035', $transformer->transform(12 / 34));
116+
}
93117
}

Tests/Extension/Core/Type/BaseTypeTest.php

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

1414
use Symfony\Component\Form\Test\TypeTestCase;
15+
use Symfony\Component\Form\Tests\VersionAwareTest;
1516

1617
/**
1718
* @author Bernhard Schussek <[email protected]>
1819
*/
1920
abstract class BaseTypeTest extends TypeTestCase
2021
{
22+
use VersionAwareTest;
23+
2124
const TESTED_TYPE = '';
2225

2326
public function testPassDisabledAsOption()

Tests/VersionAwareTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Component\Form\Tests;
13+
14+
trait VersionAwareTest
15+
{
16+
protected static $supportedFeatureSetVersion = 304;
17+
18+
/**
19+
* @param int $requiredFeatureSetVersion
20+
*/
21+
protected function requiresFeatureSet($requiredFeatureSetVersion)
22+
{
23+
if ($requiredFeatureSetVersion > static::$supportedFeatureSetVersion) {
24+
$this->markTestSkipped(sprintf('Test requires features from symfony/form %.2f but only version %.2f is supported.', $requiredFeatureSetVersion / 100, static::$supportedFeatureSetVersion / 100));
25+
}
26+
}
27+
}

0 commit comments

Comments
 (0)