Skip to content

Commit

Permalink
Update DateUtilsTest.php
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentmuller committed Jun 6, 2024
1 parent 0e45d11 commit 2e79cd2
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions tests/Utils/DateUtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,6 @@
#[CoversClass(DateUtils::class)]
class DateUtilsTest extends TestCase
{
private const TIME_ZONE = 'Europe/Zurich';

protected function setUp(): void
{
\Locale::setDefault(FormatUtils::DEFAULT_LOCALE);
\setlocale(\LC_ALL, FormatUtils::DEFAULT_LOCALE);
\date_default_timezone_set(self::TIME_ZONE);
}

public static function getCompletYears(): \Iterator
{
yield [29, 2029];
Expand Down Expand Up @@ -259,6 +250,9 @@ public function testGetYear(\DateTimeInterface $date, int $expected): void
#[DataProvider('getMonthNames')]
public function testMonthNames(string $name, int $index): void
{
\Locale::setDefault(FormatUtils::DEFAULT_LOCALE);
\setlocale(\LC_ALL, FormatUtils::DEFAULT_LOCALE);

$values = DateUtils::getMonths();
self::assertArrayHasKey($index, $values);
self::assertSame($name, $values[$index]);
Expand All @@ -280,6 +274,9 @@ public function testRemoveTime(\DateTime|\DateTimeImmutable $date, \DateTimeInte
#[DataProvider('getShortMonthNames')]
public function testShortMonthNames(string $name, int $index): void
{
\Locale::setDefault(FormatUtils::DEFAULT_LOCALE);
\setlocale(\LC_ALL, FormatUtils::DEFAULT_LOCALE);

$values = DateUtils::getShortMonths();
self::assertArrayHasKey($index, $values);
self::assertSame($name, $values[$index]);
Expand All @@ -294,6 +291,9 @@ public function testShortMonthsCount(): void
#[DataProvider('getShortWeekdayNames')]
public function testShortWeekdayNames(string $name, int $index, string $firstDay = 'sunday'): void
{
\Locale::setDefault(FormatUtils::DEFAULT_LOCALE);
\setlocale(\LC_ALL, FormatUtils::DEFAULT_LOCALE);

$values = DateUtils::getShortWeekdays($firstDay);
self::assertArrayHasKey($index, $values);
self::assertSame($name, $values[$index]);
Expand Down Expand Up @@ -326,15 +326,12 @@ public function testSubByString(): void
self::assertSame('2020-01-03', $add->format('Y-m-d'));
}

public function testTimeZone(): void
{
$actual = \date_default_timezone_get();
self::assertSame(self::TIME_ZONE, $actual);
}

#[DataProvider('getWeekdayNames')]
public function testWeekdayNames(string $name, int $index, string $firstDay = 'sunday'): void
{
\Locale::setDefault(FormatUtils::DEFAULT_LOCALE);
\setlocale(\LC_ALL, FormatUtils::DEFAULT_LOCALE);

$values = DateUtils::getWeekdays($firstDay);
self::assertArrayHasKey($index, $values);
self::assertSame($name, $values[$index]);
Expand Down

0 comments on commit 2e79cd2

Please sign in to comment.