function it_calculates_the_distance_between_two_different_postcodes_in_km(Address $addressA, Address $addressB, Response $a, Response $b)
 {
     $postcodeA = '1234AB';
     $postcodeB = '5678CD';
     $addressA->getLatitude()->willReturn(52.3747157);
     // Amsterdam (nl)
     $addressA->getLongitude()->willReturn(4.8986182);
     $addressA->distanceToAddress($addressB)->willReturn(177.583)->shouldBeCalledTimes(1);
     $addressB->getLatitude()->willReturn(50.8577968);
     // Maastricht (nl)
     $addressB->getLongitude()->willReturn(5.7009038);
     $a->getAddress()->willReturn($addressA);
     $b->getAddress()->willReturn($addressB);
     $this->client->postcode($postcodeA)->willReturn($a)->shouldBeCalledTimes(1);
     $this->client->postcode($postcodeB)->willReturn($b)->shouldBeCalledTimes(1);
     $this->getDistanceBetweenPostcodesInKM($postcodeA, $postcodeB)->shouldReturn(177.583);
 }
Example #2
0
 /**
  * calculates the distance in KM between postcodeA and postcodeB
  *
  * @param string $postcodeA
  * @param string $postcodeB
  *
  * @return float
  */
 public function getDistanceBetweenPostcodesInKM($postcodeA, $postcodeB)
 {
     $addressA = $this->client->postcode($postcodeA)->getAddress();
     $addressB = $this->client->postcode($postcodeB)->getAddress();
     return $addressA->distanceToAddress($addressB);
 }