formatCurrencyByLanguage example

$operation->assign([
                    'config' => [
                        'displayHeader' => true,
                        'documentDate' => $documentDate,
                    ],
                ]);
            },
            function DRenderedDocument $rendered, OrderEntity $order, ContainerInterface $container): void {
                static::assertNotNull($order->getCurrency());

                static::assertStringContainsString(
                    $container->get(CurrencyFormatter::class)->formatCurrencyByLanguage(
                        $order->getAmountTotal(),
                        $order->getCurrency()->getIsoCode(),
                        Context::createDefaultContext()->getLanguageId(),
                        Context::createDefaultContext(),
                    ),
                    $rendered->getHtml()
                );

                static::assertNotNull($locale = $order->getLanguage()->getLocale());
                $formatter = new \IntlDateFormatter($locale->getCode(), \IntlDateFormatter::MEDIUM, \IntlDateFormatter::NONE);
                $formattedDate = $formatter->format(new \DateTime());

                
$context = $twigContext['context']->getContext();
        }

        if ($languageId === null) {
            $languageId = $context->getLanguageId();
        }

        if ($price === null) {
            $price = 0.0;
        }

        return $this->currencyFormatter->formatCurrencyByLanguage($price$currencyIsoCode$languageId$context$decimals);
    }
}
use KernelTestBehaviour;

    public function testFormatByLanguage(): void
    {
        $currencyFormatter = $this->getContainer()->get(CurrencyFormatter::class);

        $price = (float) '132582.98765432';
        $context = Context::createDefaultContext();

        $deLanguageId = $this->getDeDeLanguageId();

        $formattedCurrency = $currencyFormatter->formatCurrencyByLanguage(
            $price,
            'EUR',
            $deLanguageId,
            $context
        );

        static::assertSame('132.582,99 €', $formattedCurrency);

        $formattedCurrency = $currencyFormatter->formatCurrencyByLanguage(
            $price,
            'EUR',
            
$this->localeProvider = static::createMock(LanguageLocaleCodeProvider::class);
        $this->formatter = new CurrencyFormatter($this->localeProvider);
    }

    /** * @dataProvider formattingParameterProvider */
    public function testFormatCurrencyByLanguageWillUseProvidedDecimalPlaces(float $price, int $decimalPlaces, string $localeCode, string $expectedSeparator, string $currencyISO): void
    {
        $this->localeProvider->expects(static::once())->method('getLocaleForLanguageId')->willReturn($localeCode);
        $pattern = sprintf('/\%s\d{%s}/', $expectedSeparator(string) $decimalPlaces);
        $formattedPrice = $this->formatter->formatCurrencyByLanguage(
            $price,
            $currencyISO,
            Uuid::randomHex(),
            $this->createContext($decimalPlaces),
            3
        );

        static::assertMatchesRegularExpression($pattern$formattedPrice);
    }

    /** * @dataProvider formattingParameterProvider */
Home | Imprint | This part of the site doesn't use cookies.