public function testGeocodeThrowsChainNoResult() { $mockOne = $this->getMock('Geocoder\\Provider\\Provider'); $mockOne->expects($this->exactly(2))->method('geocode')->will($this->returnCallback(function () { throw new \Exception(); })); $chain = new Chain(array($mockOne, $mockOne)); try { $chain->geocode('Paris'); } catch (ChainNoResult $e) { $this->assertCount(2, $e->getExceptions()); } }
/** * * @param unknown $ipAddress */ public function geocode($ipAddress) { // simple array memory cache if (isset($this->results[$ipAddress])) { return $this->results[$ipAddress]; } $chain = new Chain($this->getWorkingProviders()); try { $result = $chain->geocode($ipAddress); } catch (\Exception $ex) { var_dump($ex); exit; } $firstResult = $result->first(); return [self::LATITUDE => $firstResult->getLatitude(), self::LONGITUDE => $firstResult->getLongitude()]; }