Skip to content

Commit

Permalink
Continue set locale to test function.
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentmuller committed Jun 7, 2024
1 parent 9402589 commit 43f2655
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
3 changes: 0 additions & 3 deletions src/Utils/FormatUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,6 @@ public static function getDateFormatter(
?string $pattern = null,
\DateTimeZone|string|null $timezone = null
): \IntlDateFormatter {
if (self::DEFAULT_LOCALE !== \Locale::getDefault()) {
\Locale::setDefault(self::DEFAULT_LOCALE);
}
$locale = \Locale::getDefault();
$dateType ??= self::DATE_TYPE;
$timeType ??= self::TIME_TYPE;
Expand Down
5 changes: 5 additions & 0 deletions tests/Utils/DateUtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ public function testCompletYear(int $value, int $expected, int $change = 1930):
#[DataProvider('getFormatFormDate')]
public function testFormatFormDate(?\DateTimeInterface $date, ?string $expected): void
{
\Locale::setDefault(FormatUtils::DEFAULT_LOCALE);
$actual = DateUtils::formatFormDate($date);
self::assertSame($expected, $actual);
}
Expand Down Expand Up @@ -255,6 +256,7 @@ public function testGetYear(\DateTimeInterface $date, int $expected): void
#[DataProvider('getMonthNames')]
public function testMonthNames(string $name, int $index): void
{
\Locale::setDefault(FormatUtils::DEFAULT_LOCALE);
$values = DateUtils::getMonths();
self::assertArrayHasKey($index, $values);
self::assertSame($name, $values[$index]);
Expand All @@ -276,6 +278,7 @@ public function testRemoveTime(\DateTime|\DateTimeImmutable $date, \DateTimeInte
#[DataProvider('getShortMonthNames')]
public function testShortMonthNames(string $name, int $index): void
{
\Locale::setDefault(FormatUtils::DEFAULT_LOCALE);
$values = DateUtils::getShortMonths();
self::assertArrayHasKey($index, $values);
self::assertSame($name, $values[$index]);
Expand All @@ -290,6 +293,7 @@ public function testShortMonthsCount(): void
#[DataProvider('getShortWeekdayNames')]
public function testShortWeekdayNames(string $name, int $index, string $firstDay = 'sunday'): void
{
\Locale::setDefault(FormatUtils::DEFAULT_LOCALE);
$values = DateUtils::getShortWeekdays($firstDay);
self::assertArrayHasKey($index, $values);
self::assertSame($name, $values[$index]);
Expand Down Expand Up @@ -325,6 +329,7 @@ public function testSubByString(): void
#[DataProvider('getWeekdayNames')]
public function testWeekdayNames(string $name, int $index, string $firstDay = 'sunday'): void
{
\Locale::setDefault(FormatUtils::DEFAULT_LOCALE);
$values = DateUtils::getWeekdays($firstDay);
self::assertArrayHasKey($index, $values);
self::assertSame($name, $values[$index]);
Expand Down
6 changes: 6 additions & 0 deletions tests/Utils/FormatUtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ public function testDateFormatterPattern(
?int $dateType = null,
?int $timeType = null
): void {
\Locale::setDefault(FormatUtils::DEFAULT_LOCALE);
$actual = FormatUtils::getDateFormatter($dateType, $timeType, $pattern, FormatUtils::DEFAULT_TIME_ZONE);
self::assertSame($expected, $actual->getPattern());
}
Expand Down Expand Up @@ -264,6 +265,7 @@ public function testDefaultTimezone(): void
#[DataProvider('getAmounts')]
public function testFormatAmount(string|int|float|null $number, string $expected): void
{
\Locale::setDefault(FormatUtils::DEFAULT_LOCALE);
$actual = FormatUtils::formatAmount($number);
self::assertSame($expected, $actual);
}
Expand All @@ -278,6 +280,7 @@ public function testFormatDate(
?int $dateType = null,
?string $pattern = null
): void {
\Locale::setDefault(FormatUtils::DEFAULT_LOCALE);
$actual = FormatUtils::formatDate($date, $dateType, $pattern, FormatUtils::DEFAULT_TIME_ZONE);
self::assertSame($expected, $actual);
}
Expand All @@ -294,6 +297,7 @@ public function testFormatDateTime(
?int $timeType = null,
?string $pattern = null
): void {
\Locale::setDefault(FormatUtils::DEFAULT_LOCALE);
$actual = FormatUtils::formatDateTime($date, $dateType, $timeType, $pattern, FormatUtils::DEFAULT_TIME_ZONE);
self::assertSame($expected, $actual);
}
Expand Down Expand Up @@ -324,6 +328,7 @@ public function testFormatPercent(
int $decimals = 0,
int $roundingMode = \NumberFormatter::ROUND_DOWN
): void {
\Locale::setDefault(FormatUtils::DEFAULT_LOCALE);
$actual = FormatUtils::formatPercent($number, $includeSign, $decimals, $roundingMode);
self::assertSame($expected, $actual);

Expand All @@ -344,6 +349,7 @@ public function testFormatTime(
?int $timeType = null,
?string $pattern = null
): void {
\Locale::setDefault(FormatUtils::DEFAULT_LOCALE);
$actual = FormatUtils::formatTime($date, $timeType, $pattern, FormatUtils::DEFAULT_TIME_ZONE);
self::assertSame($expected, $actual);
}
Expand Down

0 comments on commit 43f2655

Please sign in to comment.