initital commit
This commit is contained in:
49
tests/Unit/DTO/Factory/WeatherAtTimePointFactoryTest.php
Normal file
49
tests/Unit/DTO/Factory/WeatherAtTimePointFactoryTest.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user