/** * Return an instance of WeatherConnectorInterface * * @return WeatherConnectorInterface */ public function getWeatherConnector() { if (!isset($this->weatherConnector)) { $weatherConnector = new WeatherConnector(); $weatherConnector->setLock($this->getLock()); $this->weatherConnector = $weatherConnector; } return $this->weatherConnector; }
/** * Test that we can get a Current instance from the WeatherConnector when * we search with an id */ public function testGetWeatherUsingId() { $weatherConnector = new WeatherConnector(); $options = array('id' => 2172797, 'mode' => 'xml'); // http://api.openweathermap.org/data/2.5/weather?id=2172797&mode=xml $results = file_get_contents(__DIR__ . '/../../data/weather/xml/2172797.xml'); $mockResponse = $this->getMock('\\Zend\\Http\\Response'); $mockResponse->expects($this->once())->method('isSuccess')->will($this->returnValue(true)); $mockResponse->expects($this->once())->method('getBody')->will($this->returnValue($results)); $mockClient = $this->getMock('\\Zend\\Http\\Client'); $mockClient->expects($this->once())->method('dispatch')->with($this->isInstanceOf('\\Zend\\Http\\Request'))->will($this->returnValue($mockResponse)); $mockLock = $this->getMock('\\OpenWeatherMap\\Lock\\Lock', array(), array(), 'mockLock', false); $mockLock->expects($this->once())->method('acquire')->will($this->returnValue(true)); $mockLock->expects($this->once())->method('release')->will($this->returnValue(true)); $weatherConnector->setHttpClient($mockClient); $weatherConnector->setLock($mockLock); $current = $weatherConnector->getWeather($options); $this->assertInstanceOf('\\OpenWeatherMap\\Entity\\Current', $current); }