50 lines
1.6 KiB
PHP
50 lines
1.6 KiB
PHP
|
<?php
|
||
|
|
||
|
declare(strict_types=1);
|
||
|
|
||
|
namespace App\Tests\Unit\DTO\Factory;
|
||
|
|
||
|
use App\DTO\Factory\WeatherAtTimePointFactory;
|
||
|
use DateTimeZone;
|
||
|
use PHPUnit\Framework\TestCase;
|
||
|
|
||
|
class WeatherAtTimePointFactoryTest extends TestCase
|
||
|
{
|
||
|
public function testDifferentTimeZone(): void
|
||
|
{
|
||
|
$oldTz = date_default_timezone_get();
|
||
|
// POSIX convention change +/- sign
|
||
|
date_default_timezone_set('Etc/GMT-2');
|
||
|
$service = $this->createService();
|
||
|
$weatherAtTimePoint = $service->createFromUntrustedDataWithTz(
|
||
|
new \DateTimeImmutable('2020-01-01 00:00:00', new DateTimeZone('Etc/GMT+0')),
|
||
|
0,
|
||
|
0,
|
||
|
0
|
||
|
);
|
||
|
$this->assertEquals('Etc/GMT-2', $weatherAtTimePoint->date->getTimezone()->getName());
|
||
|
$this->assertEquals('2020-01-01 02:00:00', $weatherAtTimePoint->date->format('Y-m-d H:i:s'));
|
||
|
date_default_timezone_set($oldTz);
|
||
|
}
|
||
|
|
||
|
public function testCreateWithYYYYmmddFormat(): void
|
||
|
{
|
||
|
$tz = date_default_timezone_get();
|
||
|
// POSIX convention change +/- sign
|
||
|
$service = $this->createService();
|
||
|
$weatherAtTimePoint = $service->createFromUntrustedWithDateYYYYmmdd(
|
||
|
"2020-01-01",
|
||
|
0,
|
||
|
0,
|
||
|
0
|
||
|
);
|
||
|
$this->assertEquals($tz, $weatherAtTimePoint->date->getTimezone()->getName());
|
||
|
$this->assertEquals('2020-01-01 00:00:00', $weatherAtTimePoint->date->format('Y-m-d H:i:s'));
|
||
|
}
|
||
|
|
||
|
private function createService(): WeatherAtTimePointFactory
|
||
|
{
|
||
|
return new WeatherAtTimePointFactory();
|
||
|
}
|
||
|
}
|