|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Wolnosciowiec\CoordinatesBundle\Tests\Model\Entity\Coordinates; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; |
|
6
|
|
|
use Wolnosciowiec\CoordinatesBundle\Model\Entity\Coordinates\Coordinates; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* CoordinatesTest |
|
10
|
|
|
* =============== |
|
11
|
|
|
* |
|
12
|
|
|
* @see Coordinates |
|
13
|
|
|
*/ |
|
14
|
|
|
class CoordinatesTest extends WebTestCase |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* Test bounding square calculation |
|
18
|
|
|
*/ |
|
19
|
|
|
public function testBoundingSquare() |
|
20
|
|
|
{ |
|
21
|
|
|
// Wrocław, okolice ronda |
|
22
|
|
|
$coords = new Coordinates(51.090041, 17.018763); |
|
23
|
|
|
$coords->setMaxAcceptedDistance(20); |
|
24
|
|
|
|
|
25
|
|
|
// villages nearby to Wrocław are shown |
|
26
|
|
|
$this->assertSame([50.67400897831277, 51.506073021687229], $coords->getBoundingSquare()->getLatitude()); |
|
27
|
|
|
$this->assertSame([16.838898678816253, 17.198627321183746], $coords->getBoundingSquare()->getLongitude()); |
|
28
|
|
|
$this->assertSame(20.0, $coords->getMaxAcceptedDistance()); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Test distance comparison |
|
33
|
|
|
*/ |
|
34
|
|
|
public function testDistanceComparison() |
|
35
|
|
|
{ |
|
36
|
|
|
// Wrocław, centrum |
|
37
|
|
|
$coords = new Coordinates(51.090041, 17.018763); |
|
38
|
|
|
|
|
39
|
|
|
// Trzebnica |
|
40
|
|
|
$comparison = $coords->compareWith(new Coordinates(51.308600, 17.070917)); |
|
41
|
|
|
|
|
42
|
|
|
$this->assertLessThan(60, $comparison->getInMiles()); |
|
43
|
|
|
$this->assertGreaterThan(30, $comparison->getInMiles()); |
|
44
|
|
|
|
|
45
|
|
|
$this->assertLessThan(100, $comparison->getInKilometers()); |
|
46
|
|
|
$this->assertGreaterThan(35, $comparison->getInKilometers()); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Test validation of invalid coordinates (non-float values) |
|
51
|
|
|
* ========================================================= |
|
52
|
|
|
* |
|
53
|
|
|
* @expectedException \InvalidArgumentException |
|
54
|
|
|
*/ |
|
55
|
|
|
public function testInvalidCoordinates() |
|
56
|
|
|
{ |
|
57
|
|
|
new Coordinates(1, 2); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|