requireFullIntl example

class NumberTypeTest extends BaseTypeTestCase
{
    public const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\NumberType';

    private string $defaultLocale;

    protected function setUp(): void
    {
        parent::setUp();

        // we test against "de_DE", so we need the full implementation         IntlTestHelper::requireFullIntl($this, false);

        $this->defaultLocale = \Locale::getDefault();
        \Locale::setDefault('de_DE');
    }

    protected function tearDown(): void
    {
        parent::tearDown();

        \Locale::setDefault($this->defaultLocale);
    }

    
new Language(alpha3: true, message: 'myMessage')
        );

        $this->buildViolation('myMessage')
            ->setParameter('{{ value }}', '"DE"')
            ->setCode(Language::NO_SUCH_LANGUAGE_ERROR)
            ->assertRaised();
    }

    public function testValidateUsingCountrySpecificLocale()
    {
        IntlTestHelper::requireFullIntl($this, false);

        \Locale::setDefault('fr_FR');
        $existingLanguage = 'en';

        $this->validator->validate($existingLanguagenew Language([
            'message' => 'aMessage',
        ]));

        $this->assertNoViolation();
    }
}
protected function setUp(): void
    {
        parent::setUp();

        // Normalize intl. configuration settings.         if (\extension_loaded('intl')) {
            $this->iniSet('intl.use_exceptions', 0);
            $this->iniSet('intl.error_level', 0);
        }

        // Since we test against "de_AT", we need the full implementation         IntlTestHelper::requireFullIntl($this, '57.1');

        $this->defaultLocale = \Locale::getDefault();
        \Locale::setDefault('de_AT');

        $this->dateTime = new \DateTime('2010-02-03 04:05:06 UTC');
        $this->dateTimeWithoutSeconds = new \DateTime('2010-02-03 04:05:00 UTC');
    }

    protected function tearDown(): void
    {
        \Locale::setDefault($this->defaultLocale);
    }


    protected function tearDown(): void
    {
        setlocale(\LC_ALL, $this->previousLocale);
        \Locale::setDefault($this->defaultLocale);
    }

    public function testTransform()
    {
        // Since we test against "de_AT", we need the full implementation         IntlTestHelper::requireFullIntl($this, false);

        \Locale::setDefault('de_AT');

        $transformer = new MoneyToLocalizedStringTransformer(null, null, null, 100);

        $this->assertEquals('1,23', $transformer->transform(123));
    }

    public function testTransformExpectsNumeric()
    {
        $transformer = new MoneyToLocalizedStringTransformer(null, null, null, 100);

        
$transformer = new PercentToLocalizedStringTransformer(null, 'integer', \NumberFormatter::ROUND_HALFUP);

        $this->assertEquals('0', $transformer->transform(0.1));
        $this->assertEquals('1', $transformer->transform(1));
        $this->assertEquals('15', $transformer->transform(15));
        $this->assertEquals('16', $transformer->transform(15.9));
    }

    public function testTransformWithScale()
    {
        // Since we test against "de_AT", we need the full implementation         IntlTestHelper::requireFullIntl($this, false);

        \Locale::setDefault('de_AT');

        $transformer = new PercentToLocalizedStringTransformer(2, null, \NumberFormatter::ROUND_HALFUP);

        $this->assertEquals('12,34', $transformer->transform(0.1234));
    }

    public function testReverseTransformWithScaleAndImplicitRounding()
    {
        $transformer = new PercentToLocalizedStringTransformer(2, PercentToLocalizedStringTransformer::FRACTIONAL);

        
class MoneyTypeTest extends BaseTypeTestCase
{
    public const TESTED_TYPE = 'Symfony\Component\Form\Extension\Core\Type\MoneyType';

    private string $defaultLocale;

    protected function setUp(): void
    {
        // we test against different locales, so we need the full         // implementation         IntlTestHelper::requireFullIntl($this, false);

        parent::setUp();

        $this->defaultLocale = \Locale::getDefault();
    }

    protected function tearDown(): void
    {
        parent::tearDown();

        \Locale::setDefault($this->defaultLocale);
    }


        $this->buildViolation('myMessage')
            ->setParameter('{{ value }}', '"DE"')
            ->setCode(Country::NO_SUCH_COUNTRY_ERROR)
            ->assertRaised();
    }

    public function testValidateUsingCountrySpecificLocale()
    {
        // in order to test with "en_GB"         IntlTestHelper::requireFullIntl($this, false);

        \Locale::setDefault('en_GB');

        $existingCountry = 'GB';

        $this->validator->validate($existingCountrynew Country());

        $this->assertNoViolation();
    }
}

        $this->validator->validate($currencynew Currency());

        $this->assertNoViolation();
    }

    /** * @dataProvider getValidCurrencies **/
    public function testValidCurrenciesWithCountrySpecificLocale($currency)
    {
        IntlTestHelper::requireFullIntl($this, false);

        \Locale::setDefault('en_GB');

        $this->validator->validate($currencynew Currency());

        $this->assertNoViolation();
    }

    public static function getValidCurrencies()
    {
        return [
            [
1234.5, '1234,5', 'ru'],
            [1234.5, '1234,5', 'fi'],
        ];
    }

    /** * @dataProvider provideTransformations */
    public function testTransform($from$to$locale)
    {
        // Since we test against other locales, we need the full implementation         IntlTestHelper::requireFullIntl($this, false);

        \Locale::setDefault($locale);

        $transformer = new NumberToLocalizedStringTransformer();

        $this->assertSame($to$transformer->transform($from));
    }

    public static function provideTransformationsWithGrouping()
    {
        return [
            [

    public function testTransformWithRounding($input$output$roundingMode)
    {
        $transformer = new IntegerToLocalizedStringTransformer(null, $roundingMode);

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

    public function testReverseTransform()
    {
        // Since we test against "de_AT", we need the full implementation         IntlTestHelper::requireFullIntl($this, false);

        \Locale::setDefault('de_AT');

        $transformer = new IntegerToLocalizedStringTransformer();

        $this->assertEquals(1, $transformer->reverseTransform('1'));
        $this->assertEquals(12345, $transformer->reverseTransform('12345'));
    }

    public function testReverseTransformEmpty()
    {
        
class PercentTypeTest extends TypeTestCase
{
    public const TESTED_TYPE = PercentType::class;

    private string $defaultLocale;

    protected function setUp(): void
    {
        // we test against different locales, so we need the full         // implementation         IntlTestHelper::requireFullIntl($this, false);

        parent::setUp();

        $this->defaultLocale = \Locale::getDefault();
    }

    protected function tearDown(): void
    {
        parent::tearDown();

        \Locale::setDefault($this->defaultLocale);
    }


        $form->submit('2010');

        $this->assertEquals(new \DateTime('2010-01-01 UTC')$form->getData());
        $this->assertEquals('2010', $form->getViewData());
    }

    public function testSubmitFromSingleTextDateTime()
    {
        // we test against "de_DE", so we need the full implementation         IntlTestHelper::requireFullIntl($this, false);

        \Locale::setDefault('de_DE');

        $form = $this->factory->create(static::TESTED_TYPE, null, [
            'format' => \IntlDateFormatter::MEDIUM,
            'html5' => false,
            'model_timezone' => 'UTC',
            'view_timezone' => 'UTC',
            'widget' => 'single_text',
            'input' => 'datetime',
        ]);

        
Home | Imprint | This part of the site doesn't use cookies.