initital commit

This commit is contained in:
2025-01-26 21:17:23 +01:00
commit 2a7345ba56
72 changed files with 9458 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
<?php
declare(strict_types=1);
namespace App\Tests\Unit\DTO\Factory;
use App\DTO\Factory\GEOPointFactory;
use App\DTO\GEOPoint;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
class GEOPointFactoryTest extends TestCase
{
public function testCreateFromStringWillAcceptGeopoints(): void
{
$service = $this->createService();
$geopoint = $service->createFromString('20.303', '30.22');
$this->assertInstanceOf(GEOPoint::class, $geopoint);
$this->assertEquals(20.303, $geopoint->latitude);
$this->assertEquals(30.22, $geopoint->longitude);
}
#[DataProvider('invalidGeoPointProvider')]
public function testCreateFromStringInvalidString(string $lat, string $lon): void
{
$service = $this->createService();
$geopoint = $service->createFromString($lat, $lon);
$this->assertEquals(null, $geopoint);
}
/**
* @return array<int|string, array<int|string, string>>
*/
public static function invalidGeoPointProvider(): array
{
return [
['foo', 'foo'],
['33.33', 'foo'],
['foo', '33.33'],
['foo3', 'foo3'],
['33.33', 'foo3'],
['foo3', '33.33'],
];
}
public function createService(): GEOPointFactory
{
return new GEOPointFactory();
}
}

View 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();
}
}