/** * @param Response $response * @return Address * @throws \LogicException */ private function getAddressFromResponse(Response $response) { $address = $response->getAddress(); if (!$address instanceof Address) { throw new \LogicException('Response::getAddress should return instanceof Address'); } return $address; }
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); }