Skip to content

Commit

Permalink
Set Locale.
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentmuller committed Jun 7, 2024
1 parent 8435e09 commit de4afec
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 9 deletions.
1 change: 1 addition & 0 deletions src/Utils/FormatUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ public static function getNumberFormatter(
): \NumberFormatter {
$hash = self::hashCode($style, $digits, $roundingMode, $percentSymbol);
if (!isset(self::$numberFormatters[$hash])) {
\Locale::setDefault(self::DEFAULT_LOCALE);
$formatter = new \NumberFormatter(\Locale::getDefault(), $style);
$formatter->setAttribute(\NumberFormatter::FRACTION_DIGITS, $digits);
$formatter->setAttribute(\NumberFormatter::ROUNDING_MODE, $roundingMode);
Expand Down
9 changes: 0 additions & 9 deletions tests/Utils/FormatUtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,6 @@ public function testFormatId(int|float|string|null $number, string $expected): v
#[DataProvider('getIntegers')]
public function testFormatInteger(\Countable|array|int|float|string|null $number, string $expected): void
{
if (!$this->updateLocale()) {
self::markTestSkipped('Unable to set locale to "fr_CH".');
}

$actual = FormatUtils::formatInt($number);
self::assertSame($expected, $actual);
}
Expand Down Expand Up @@ -378,9 +374,4 @@ private static function createDate(): \DateTimeInterface
{
return new \DateTime(self::DATE_TIME, new \DateTimeZone(FormatUtils::DEFAULT_TIME_ZONE));
}

private function updateLocale(): bool
{
return false !== \ini_set('intl.default_locale', FormatUtils::DEFAULT_LOCALE);
}
}

0 comments on commit de4afec

Please sign in to comment.