예제 #1
0
 public function testCoordinateGetter()
 {
     $stub = $this->getMockBuilder('Location\\Coordinate\\CoordinateInterface')->getMock();
     $stub->method('getLatitude')->willReturn(51.3775265);
     $stub->method('getLongitude')->willReturn(6.0789937);
     $location = new Location($stub);
     $this->assertSame($stub, $location->getCoordinate());
 }
예제 #2
0
 public function testInstanceFromCoordinate()
 {
     $stub = $this->getMockBuilder('Location\\Coordinate\\CoordinateInterface')->getMock();
     $stub->method('getLatitude')->willReturn(51.3775265);
     $stub->method('getLongitude')->willReturn(6.0789937);
     $location = Location::fromCoordinate($stub);
     $this->assertInstanceOf('Location\\Location', $location);
     $this->assertSame($stub, $location->getCoordinate());
 }
예제 #3
0
 public function testLocationDistanceBetweenAmsterdamAndVenlo()
 {
     // Amsterdam
     $stub1 = $this->getMockBuilder('Location\\Coordinate\\CoordinateInterface')->getMock();
     $stub1->method('getLatitude')->willReturn(52.3079989);
     $stub1->method('getLongitude')->willReturn(4.9715451);
     $amsterdam = new Location($stub1);
     // Venlo
     $stub2 = $this->getMockBuilder('Location\\Coordinate\\CoordinateInterface')->getMock();
     $stub2->method('getLatitude')->willReturn(51.3703748);
     $stub2->method('getLongitude')->willReturn(6.1724031);
     $venlo = new Location($stub2);
     // Distance calculator
     $stub3 = $this->getMockBuilder('Location\\Distance\\DistanceCalculatorInterface')->getMock();
     $stub3->method('calculateDistanceBetween')->willReturn(10);
     // Calculate the distance.
     $distance = $amsterdam->calculateDistanceFromLocation($venlo, $stub3);
     $this->assertSame(10, $distance);
 }
예제 #4
0
 /**
  * Returns the distance in meters from the receiver’s location to
  * the given location using the given distance calculator formula.
  *
  * @param Location $location The location to calculate the distance from.
  * @param DistanceCalculatorInterface $calculator The distance calculator formula.
  *
  * @return float The distance in meters between the two locations.
  */
 public function calculateDistanceFromLocation(Location $location, DistanceCalculatorInterface $calculator)
 {
     return $calculator->calculateDistanceBetween($this->getCoordinate(), $location->getCoordinate());
 }