initital commit
This commit is contained in:
87
tests/Unit/Services/GeoPointResolverServiceTest.php
Normal file
87
tests/Unit/Services/GeoPointResolverServiceTest.php
Normal file
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Unit\Services;
|
||||
|
||||
use App\DTO\Factory\GEOPointFactory;
|
||||
use App\DTO\GEOPoint;
|
||||
use App\Services\GeoPointResolverService;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class GeoPointResolverServiceTest extends TestCase
|
||||
{
|
||||
public function testGetCityNameFromGeoPoint(): void
|
||||
{
|
||||
$this->assertEquals('Prague', $this->createService()->getCityNameFromGeoPoint(
|
||||
new GEOPoint(50.073658, 14.418540)
|
||||
));
|
||||
|
||||
$this->assertEquals('New York', $this->createService()->getCityNameFromGeoPoint(
|
||||
new GEOPoint(40.730610, -73.935242)
|
||||
));
|
||||
}
|
||||
|
||||
public function testGetCityNameFromGeoPointInvalid(): void
|
||||
{
|
||||
$this->assertEquals(null, $this->createService()->getCityNameFromGeoPoint(
|
||||
new GEOPoint(40.730610, -1)
|
||||
));
|
||||
}
|
||||
|
||||
public function testGetGeoPointFromCityName(): void
|
||||
{
|
||||
$resolvedGeoPoint = $this->createService()->getGeoPointFromCityName('Prague');
|
||||
|
||||
if ($resolvedGeoPoint === null) {
|
||||
$this->fail('Geo point not found');
|
||||
}
|
||||
|
||||
$this->assertEquals(50.073658, $resolvedGeoPoint->latitude);
|
||||
$this->assertEquals(14.418540, $resolvedGeoPoint->longitude);
|
||||
|
||||
$resolvedGeoPoint = $this->createService()->getGeoPointFromCityName('New York');
|
||||
|
||||
if ($resolvedGeoPoint === null) {
|
||||
$this->fail('Geo point not found');
|
||||
}
|
||||
|
||||
$this->assertEquals(40.730610, $resolvedGeoPoint->latitude);
|
||||
$this->assertEquals(-73.935242, $resolvedGeoPoint->longitude);
|
||||
}
|
||||
|
||||
public function testGetGeoPointFromCityNameInvalid(): void
|
||||
{
|
||||
$resolvedGeoPoint = $this->createService()->getGeoPointFromCityName('Atlantis');
|
||||
$this->assertNull($resolvedGeoPoint);
|
||||
}
|
||||
|
||||
public function createService(): GeoPointResolverService
|
||||
{
|
||||
$geoPointFactory = \Mockery::mock(GEOPointFactory::class);
|
||||
// @phpstan-ignore-next-line method.notFound
|
||||
$geoPointFactory
|
||||
->shouldReceive('createFromString')
|
||||
->with('50.073658', '14.418540')
|
||||
->andReturn(new GEOPoint(50.073658, 14.418540));
|
||||
// @phpstan-ignore-next-line method.notFound
|
||||
$geoPointFactory
|
||||
->shouldReceive('createFromString')
|
||||
->with('40.730610', '-73.935242')
|
||||
->andReturn(new GEOPoint(40.730610, -73.935242));
|
||||
|
||||
return new GeoPointResolverService(
|
||||
[
|
||||
'Prague' => [
|
||||
'lat' => '50.073658',
|
||||
'lon' => '14.418540'
|
||||
],
|
||||
'New York' => [
|
||||
'lat' => '40.730610',
|
||||
'lon' => '-73.935242'
|
||||
]
|
||||
],
|
||||
$geoPointFactory // @phpstan-ignore argument.type
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user