feat: add distance value object and ci workflows
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Unit\ValueObject;
|
||||
|
||||
use App\ValueObject\Distance;
|
||||
use App\ValueObject\Point;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class DistanceTest extends TestCase
|
||||
{
|
||||
public function testCalculatesDistanceBetweenTwoPointsInKilometers(): void
|
||||
{
|
||||
$origin = Point::fromLatLng(48.8566, 2.3522); // Paris
|
||||
$destination = Point::fromLatLng(51.5074, -0.1278); // London
|
||||
|
||||
$distance = Distance::betweenPoints($origin, $destination);
|
||||
|
||||
self::assertEqualsWithDelta(343.4, $distance->inKilometers(), 0.5);
|
||||
}
|
||||
|
||||
public function testCanConvertDistanceToMeters(): void
|
||||
{
|
||||
$origin = Point::fromLatLng(0.0, 0.0);
|
||||
$destination = Point::fromLatLng(0.0, 0.009); // ~1km east on equator
|
||||
|
||||
$distance = Distance::betweenPoints($origin, $destination);
|
||||
|
||||
self::assertEqualsWithDelta(1000, $distance->inMeters(), 10);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user