Skip to content

Commit 44d3145

Browse files
committed
Add some more tests.
1 parent 62e6497 commit 44d3145

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

tests/Exceptions/OpenWeatherMapExceptionTest.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,16 +116,25 @@ public function testGetRawWeatherHistoryWithEndDateException()
116116
{
117117
$this->owm->getRawWeatherHistory('Berlin', new \DateTime('now'), 'wrong-endOrCount', 'hour', 'imperial', 'en', '');
118118
}
119-
119+
120120
/**
121121
* @expectedException \InvalidArgumentException
122122
* @dataProvider uviExceptionDataProvider
123123
*/
124-
public function testGetRawUviWithQueryErrorException($lat, $lon, $dateTime)
124+
public function testGetRawUVIndexWithQueryErrorException($lat, $lon, $dateTime)
125125
{
126126
$this->owm->getRawUVIndexData($lat, $lon, $dateTime);
127127
}
128128

129+
/**
130+
* @expectedException \RuntimeException
131+
*/
132+
public function testGetRawUVIndexWithoutApiKey()
133+
{
134+
$this->owm->setApiKey(null);
135+
$this->owm->getRawUVIndexData(1.1, 1.1, new \DateTime());
136+
}
137+
129138
/**
130139
* @expectedException \InvalidArgumentException
131140
*/

tests/OpenWeatherMapTest.php

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
namespace Cmfcmf\OpenWeatherMap\Tests\OpenWeatherMap;
1616

1717
use \Cmfcmf\OpenWeatherMap;
18+
use Cmfcmf\OpenWeatherMap\Exception;
1819
use Cmfcmf\OpenWeatherMap\Tests\TestFetcher;
1920

2021
class OpenWeatherMapTest extends \PHPUnit_Framework_TestCase
@@ -130,19 +131,17 @@ public function testGetWeatherForecast()
130131

131132
public function testGetUVIndex()
132133
{
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+
}
146145
}
147146

148147
public function testGetDailyWeatherForecast()

0 commit comments

Comments
 (0)