return utc from clock
This commit is contained in:
parent
2fe41a5fe7
commit
13da7c311a
5 changed files with 26 additions and 9 deletions
|
|
@ -4,12 +4,15 @@ namespace Tests\Fakes;
|
|||
|
||||
use App\Auth\Clock;
|
||||
use DateTimeImmutable;
|
||||
use InvalidArgumentException;
|
||||
|
||||
class FakeClock implements Clock
|
||||
{
|
||||
public function __construct(
|
||||
private DateTimeImmutable $currentTime,
|
||||
) {}
|
||||
) {
|
||||
$this->assertUtc($currentTime);
|
||||
}
|
||||
|
||||
public function now(): DateTimeImmutable
|
||||
{
|
||||
|
|
@ -18,6 +21,16 @@ class FakeClock implements Clock
|
|||
|
||||
public function setTime(DateTimeImmutable $newTime): void
|
||||
{
|
||||
$this->assertUtc($newTime);
|
||||
$this->currentTime = $newTime;
|
||||
}
|
||||
|
||||
private function assertUtc(DateTimeImmutable $time): void
|
||||
{
|
||||
if ($time->getTimezone()->getOffset($time) !== 0) {
|
||||
throw new InvalidArgumentException(
|
||||
'FakeClock requires a DateTimeImmutable in UTC.'
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue