|
15 | 15 | namespace Cmfcmf\OpenWeatherMap\Tests\OpenWeatherMap; |
16 | 16 |
|
17 | 17 | use \Cmfcmf\OpenWeatherMap; |
| 18 | +use Cmfcmf\OpenWeatherMap\Exception; |
18 | 19 | use Cmfcmf\OpenWeatherMap\Tests\TestFetcher; |
19 | 20 |
|
20 | 21 | class OpenWeatherMapTest extends \PHPUnit_Framework_TestCase |
@@ -130,19 +131,17 @@ public function testGetWeatherForecast() |
130 | 131 |
|
131 | 132 | public function testGetUVIndex() |
132 | 133 | { |
133 | | - $weather = $this->openWeather; |
134 | | - $result = $weather->getUVIndex(40.7, -74.2, new \DateTime()); |
135 | | - |
136 | | - $this->assertInstanceOf('\Cmfcmf\OpenWeatherMap\UVIndex', $result); |
137 | | - } |
138 | | - |
139 | | - public function testGetUUVIndexForYear() |
140 | | - { |
141 | | - $weather = $this->openWeather; |
142 | | - $year = new \DateTime(date('Y')); |
143 | | - $result = $weather->getUVIndex(40.7, -74.2, $year, 'year'); |
144 | | - |
145 | | - $this->assertInstanceOf('\Cmfcmf\OpenWeatherMap\UVIndex', $result); |
| 134 | + $owm = $this->openWeather; |
| 135 | + $precisions = array('year', 'month', 'day', 'hour', 'minute', 'second'); |
| 136 | + foreach ($precisions as $precision) { |
| 137 | + try { |
| 138 | + $result = $owm->getUVIndex(40.7, -74.2, new \DateTime(), $precision); |
| 139 | + } catch (Exception $e) { |
| 140 | + // OWM might not actually have data for the timespan. |
| 141 | + $this->assertSame('An error occurred: not found', $e->getMessage()); |
| 142 | + } |
| 143 | + $this->assertInstanceOf('\Cmfcmf\OpenWeatherMap\UVIndex', $result); |
| 144 | + } |
146 | 145 | } |
147 | 146 |
|
148 | 147 | public function testGetDailyWeatherForecast() |
|
0 commit comments