function it_calculates_the_distance_to_another_address(Address $b) { $this->setLatitude(52.3747157); $this->setLongitude(4.8986182); $b->getLatitude()->willReturn(50.8577968); $b->getLongitude()->willReturn(5.7009038); $this->distanceToAddress($b)->shouldReturn(177.583); }
/** * @param array $data */ private function readAddressFromData(array $data) { $this->validateData($data); $this->address = new Address(); $this->address->setStreet($data['resource']['street'])->setPostcode($data['resource']['postcode'])->setTown($data['resource']['town'])->setMunicipality($data['resource']['municipality'])->setProvince($data['resource']['province'])->setLatitude($data['resource']['latitude'])->setLongitude($data['resource']['longitude'])->setXPos($data['resource']['x'])->setYPos($data['resource']['y']); // optional if (array_key_exists('house_number', $data['resource'])) { $this->address->setHouseNumber($data['resource']['house_number']); } }
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); }