/** * @param $postCode * @return Address */ public function find($postCode) { $this->setRequestUrl(sprintf($this->getRequestUrl(), $postCode, $this->getApiKey())); $response = $this->request(); $address = new Address(); $address->setMunicipality($response['results'][0]['address_components']['state'])->setStreet($response['results'][0]['address_components']['formatted_street'])->setTown($response['results'][0]['address_components']['city'])->setLatitude($response['results'][0]['location']['lat'])->setLongitude($response['results'][0]['location']['lng']); return $address; }
public function testCanReadFindAddressResponse() { $json = file_get_contents(__DIR__ . '\\Geocodio.json'); $response = new Response(200, [], Stream::factory($json)); $json = json_decode($response->getBody(), true); $address = new Address(); $address->setMunicipality($json['results'][0]['address_components']['state'])->setStreet($json['results'][0]['address_components']['formatted_street'])->setTown($json['results'][0]['address_components']['city'])->setLatitude($json['results'][0]['location']['lat'])->setLongitude($json['results'][0]['location']['lng']); $this->assertEquals($address->getMunicipality(), 'CA'); $this->assertEquals($address->getStreet(), 'Bob Hope Dr'); $this->assertEquals($address->getTown(), 'Rancho Mirage'); $this->assertEquals($address->getLatitude(), '33.739464'); $this->assertEquals($address->getLongitude(), '-116.40803'); }