1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
/** |
3
|
|
|
* This file is part of the daikon-cqrs/value-object project. |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Daikon\Tests\ValueObject; |
10
|
|
|
|
11
|
|
|
use Daikon\ValueObject\GeoPoint; |
12
|
|
|
use PHPUnit\Framework\TestCase; |
13
|
|
|
|
14
|
|
|
final class GeoPointTest extends TestCase |
15
|
|
|
{ |
16
|
|
|
private const COORDS = [ |
17
|
|
|
'lon' => 13.413215, |
18
|
|
|
'lat' => 52.521918 |
19
|
|
|
]; |
20
|
|
|
|
21
|
|
|
private GeoPoint $geoPoint; |
22
|
|
|
|
23
|
1 |
|
public function testToNative(): void |
24
|
|
|
{ |
25
|
1 |
|
$this->assertEquals(GeoPoint::NULL_ISLAND, GeoPoint::fromNative(null)->toNative()); |
26
|
1 |
|
$this->assertEquals(self::COORDS, $this->geoPoint->toNative()); |
27
|
1 |
|
} |
28
|
|
|
|
29
|
1 |
|
public function testEquals(): void |
30
|
|
|
{ |
31
|
1 |
|
$samePoint = GeoPoint::fromNative(self::COORDS); |
32
|
1 |
|
$this->assertTrue($this->geoPoint->equals($samePoint)); |
33
|
1 |
|
$differentPoint = GeoPoint::fromNative([ 'lon' => 12.11716, 'lat' => 49.248 ]); |
34
|
1 |
|
$this->assertFalse($this->geoPoint->equals($differentPoint)); |
35
|
1 |
|
} |
36
|
|
|
|
37
|
1 |
|
public function testGetLon(): void |
38
|
|
|
{ |
39
|
1 |
|
$this->assertEquals(self::COORDS['lon'], $this->geoPoint->getLon()->toNative()); |
40
|
1 |
|
} |
41
|
|
|
|
42
|
1 |
|
public function testGetLat(): void |
43
|
|
|
{ |
44
|
1 |
|
$this->assertEquals(self::COORDS['lat'], $this->geoPoint->getLat()->toNative()); |
45
|
1 |
|
} |
46
|
|
|
|
47
|
1 |
|
public function testToString(): void |
48
|
|
|
{ |
49
|
1 |
|
$this->assertEquals( |
50
|
1 |
|
sprintf('lon: %f, lat: %f', self::COORDS['lon'], self::COORDS['lat']), |
51
|
1 |
|
(string)$this->geoPoint |
52
|
|
|
); |
53
|
1 |
|
} |
54
|
|
|
|
55
|
5 |
|
protected function setUp(): void |
56
|
|
|
{ |
57
|
5 |
|
$this->geoPoint = GeoPoint::fromNative(self::COORDS); |
58
|
5 |
|
} |
59
|
|
|
} |
60
|
|
|
|