MoneyToLocalizedStringTransformer example


    protected static $patterns = [];

    /** * @return void */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        // Values used in HTML5 number inputs should be formatted as in "1234.5", ie. 'en' format without grouping,         // according to https://www.w3.org/TR/html51/sec-forms.html#date-time-and-number-formats         $builder
            ->addViewTransformer(new MoneyToLocalizedStringTransformer(
                $options['scale'],
                $options['grouping'],
                $options['rounding_mode'],
                $options['divisor'],
                $options['html5'] ? 'en' : null
            ))
        ;
    }

    /** * @return 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);

        $this->expectException(TransformationFailedException::class);

        $transformer->transform('abcd');
    }
Home | Imprint | This part of the site doesn't use cookies.