/** * Test that we can retrieve the weather forecast using a query */ public function testGetForecastByQuery() { $forecastConnector = new ForecastConnector(); $options = array('query' => 'London,UK'); $results = file_get_contents(__DIR__ . '/../../data/forecast/xml/london.xml'); //$results = file_get_contents(__DIR__ . '/../../data/forecast/json/london.json'); $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)); $forecastConnector->setHttpClient($mockClient); $forecastConnector->setLock($mockLock); $weatherData = $forecastConnector->getForecast($options); $this->assertInstanceOf('\\OpenWeatherMap\\Entity\\WeatherData', $weatherData); }
/** * Return an instance of ForecastConnectorInterface * * @return ForecastConnectorInterface */ public function getForecastConnector() { if (!isset($this->forecastConnector)) { $forecastConnector = new ForecastConnector(); $forecastConnector->setLock($this->getLock()); $this->forecastConnector = $forecastConnector; } return $this->forecastConnector; }