1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
<?php
declare(strict_types=1);
namespace Lcobucci\Clock;
use DateTimeImmutable;
use DateTimeZone;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use PHPUnit\Framework\TestCase;
use function date_default_timezone_get;
#[CoversClass(SystemClock::class)]
final class SystemClockTest extends TestCase
{
#[Test]
public function nowShouldRespectTheProvidedTimezone(): void
{
$timezone = new DateTimeZone('America/Sao_Paulo');
$clock = new SystemClock($timezone);
$lower = new DateTimeImmutable('now', $timezone);
$now = $clock->now();
$upper = new DateTimeImmutable('now', $timezone);
self::assertEquals($timezone, $now->getTimezone());
self::assertGreaterThanOrEqual($lower, $now);
self::assertLessThanOrEqual($upper, $now);
}
#[Test]
public function fromUTCCreatesAnInstanceUsingUTCAsTimezone(): void
{
$clock = SystemClock::fromUTC();
$now = $clock->now();
self::assertSame('UTC', $now->getTimezone()->getName());
}
#[Test]
public function fromSystemTimezoneCreatesAnInstanceUsingTheDefaultTimezoneInSystem(): void
{
$clock = SystemClock::fromSystemTimezone();
$now = $clock->now();
self::assertSame(date_default_timezone_get(), $now->getTimezone()->getName());
}
}
|