-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Christian Kolb
committed
Jun 9, 2024
1 parent
b32f3b6
commit 03d6ed2
Showing
1 changed file
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DigitalCraftsman\DateTimePrecision\Moment; | ||
|
||
use DigitalCraftsman\DateTimePrecision\Moment; | ||
use DigitalCraftsman\DateTimePrecision\Weekday; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** @coversDefaultClass \DigitalCraftsman\DateTimePrecision\Moment */ | ||
final class WeekdayTest extends TestCase | ||
{ | ||
/** | ||
* @test | ||
* | ||
* @dataProvider dataProviderForTime | ||
* | ||
* @covers ::weekday | ||
*/ | ||
public function weekday_works( | ||
Weekday $expectedResult, | ||
Moment $dateTime, | ||
): void { | ||
// -- Act & Assert | ||
self::assertEquals($expectedResult, $dateTime->weekday()); | ||
} | ||
|
||
/** | ||
* @return array<string, array{ | ||
* 0: Weekday, | ||
* 1: Moment, | ||
* }> | ||
*/ | ||
public static function dataProviderForTime(): array | ||
{ | ||
return [ | ||
'same weekday in UTC' => [ | ||
Weekday::SATURDAY, | ||
Moment::fromString('2022-10-08 15:00:00'), | ||
], | ||
'weekday adapted due to weekday zone difference' => [ | ||
Weekday::SATURDAY, | ||
Moment::fromStringInTimeZone('2022-10-08 00:00:00', new \DateTimeZone('Europe/Berlin')) | ||
->toTimeZone(new \DateTimeZone('Europe/Berlin')), | ||
], | ||
]; | ||
} | ||
|
||
/** | ||
* @test | ||
* | ||
* @dataProvider dataProviderForTimeInTimeZone | ||
* | ||
* @covers ::weekdayInTimeZone | ||
*/ | ||
public function weekday_in_weekday_zone_works( | ||
Weekday $expectedResult, | ||
Moment $dateTime, | ||
\DateTimeZone $weekdayZone, | ||
): void { | ||
// -- Act & Assert | ||
self::assertEquals($expectedResult, $dateTime->weekdayInTimeZone($weekdayZone)); | ||
} | ||
|
||
/** | ||
* @return array<string, array{ | ||
* 0: Weekday, | ||
* 1: Moment, | ||
* 2: \DateTimeZone, | ||
* }> | ||
*/ | ||
public static function dataProviderForTimeInTimeZone(): array | ||
{ | ||
return [ | ||
'same weekday in UTC' => [ | ||
Weekday::SATURDAY, | ||
Moment::fromString('2022-10-08 15:00:00'), | ||
new \DateTimeZone('UTC'), | ||
], | ||
'adapting weekday for two hours through timezone difference' => [ | ||
Weekday::SUNDAY, | ||
Moment::fromString('2022-10-08 23:00:00'), | ||
new \DateTimeZone('Europe/Berlin'), | ||
], | ||
'same weekday when timezone was used for creation of datetime' => [ | ||
Weekday::SATURDAY, | ||
Moment::fromStringInTimeZone('2022-10-08 15:00:00', new \DateTimeZone('Europe/Berlin')), | ||
new \DateTimeZone('Europe/Berlin'), | ||
], | ||
]; | ||
} | ||
} |