1 | <?php |
||
22 | class OpenWeatherMapTest extends \PHPUnit_Framework_TestCase |
||
23 | { |
||
24 | /** |
||
25 | * @var string |
||
26 | */ |
||
27 | protected $apiKey; |
||
28 | |||
29 | /** |
||
30 | * @var OpenWeatherMap |
||
31 | */ |
||
32 | protected $owm; |
||
33 | |||
34 | /** |
||
35 | * @var OpenWeatherMap |
||
36 | */ |
||
37 | protected $openWeather; |
||
38 | |||
39 | /** |
||
40 | * @var ExampleCacheTest |
||
41 | */ |
||
42 | protected $cache; |
||
43 | |||
44 | protected function setUp() |
||
45 | { |
||
46 | $ini = parse_ini_file(__DIR__.'/../Examples/ApiKey.ini'); |
||
47 | $myApiKey = $ini['api_key']; |
||
48 | $this->apiKey = $myApiKey; |
||
49 | $this->owm = new OpenWeatherMap($this->apiKey, new TestFetcher(), false, 600); |
||
50 | $this->openWeather = new OpenWeatherMap($this->apiKey, null, false, 600); |
||
51 | $this->cache = new ExampleCacheTest(); |
||
52 | } |
||
53 | |||
54 | protected function tearDown() |
||
55 | { |
||
56 | $fileList = glob(__DIR__.'/temps/OpenWeatherMapPHPAPI/*'); |
||
57 | foreach ($fileList as $fileName) { |
||
58 | @unlink($fileName); |
||
|
|||
59 | } |
||
60 | |||
61 | @rmdir(__DIR__.'/temps/OpenWeatherMapPHPAPI'); |
||
62 | @rmdir(__DIR__.'/temps'); |
||
63 | } |
||
64 | |||
65 | public function testApiKeyIsEmpty() |
||
66 | { |
||
67 | $expectApiKey = ''; |
||
68 | $weather = new OpenWeatherMap($expectApiKey, null, false, 600); |
||
69 | $apiKey = $weather->getApiKey(); |
||
70 | |||
71 | $this->assertSame($expectApiKey, $apiKey); |
||
72 | } |
||
73 | |||
74 | public function testApiKeyNotNull() |
||
75 | { |
||
76 | $weather = $this->owm; |
||
77 | $apiKey = $weather->getApiKey(); |
||
78 | |||
79 | $this->assertSame($this->apiKey, $apiKey); |
||
80 | } |
||
81 | |||
82 | public function testSecondIsZero() |
||
83 | { |
||
84 | $weather = new OpenWeatherMap($this->apiKey, null, false, 0); |
||
85 | $apiKey = $weather->getApiKey(); |
||
86 | |||
87 | $this->assertSame($this->apiKey, $apiKey); |
||
88 | } |
||
89 | |||
90 | public function testSetApiKey() |
||
91 | { |
||
92 | $weather = $this->owm; |
||
93 | $weather->setApiKey($this->apiKey); |
||
94 | $apiKey = $weather->getApiKey(); |
||
95 | |||
96 | $this->assertSame($this->apiKey, $apiKey); |
||
97 | } |
||
98 | |||
99 | public function testGetApiKey() |
||
100 | { |
||
101 | $weather = $this->owm; |
||
102 | $apiKey = $weather->getApiKey(); |
||
103 | |||
104 | $this->assertSame($this->apiKey, $apiKey); |
||
105 | } |
||
106 | |||
107 | public function testGetWeather() |
||
108 | { |
||
109 | $currentWeather = $this->owm->getWeather('Berlin', 'imperial', 'en', ''); |
||
110 | |||
111 | $this->assertInstanceOf('\Cmfcmf\OpenWeatherMap\CurrentWeather', $currentWeather); |
||
112 | } |
||
113 | |||
114 | public function testGetWeatherGroup() |
||
115 | { |
||
116 | $currentWeather = $this->owm->getWeatherGroup('2950159', 'imperial', 'en', ''); |
||
117 | |||
118 | $this->assertInstanceOf('\Cmfcmf\OpenWeatherMap\CurrentWeatherGroup', $currentWeather); |
||
119 | } |
||
120 | |||
121 | public function testGetWeatherForecast() |
||
122 | { |
||
123 | $days = 1; |
||
124 | $defaultDay = $this->owm->getWeatherForecast('Berlin', 'imperial', 'en', '', $days); |
||
125 | |||
126 | $days = 16; |
||
127 | $maxDay = $this->owm->getWeatherForecast('Berlin', 'imperial', 'en', '', $days); |
||
128 | |||
129 | $this->assertInstanceOf('\Cmfcmf\OpenWeatherMap\WeatherForecast', $defaultDay); |
||
130 | $this->assertInstanceOf('\Cmfcmf\OpenWeatherMap\WeatherForecast', $maxDay); |
||
131 | } |
||
132 | |||
133 | public function testGetUvi() |
||
141 | |||
142 | public function testGetUviHistory() |
||
151 | |||
152 | public function testGetUviHistoryWithNull() |
||
160 | |||
161 | public function testGetDailyWeatherForecast() |
||
162 | { |
||
163 | $days = 16; |
||
164 | $dailyForecast = $this->owm->getDailyWeatherForecast('Berlin', 'imperial', 'en', '', $days); |
||
165 | |||
166 | $this->assertInstanceOf('\Cmfcmf\OpenWeatherMap\WeatherForecast', $dailyForecast); |
||
167 | } |
||
168 | |||
169 | public function testGetWeatherHistory() |
||
170 | { |
||
171 | // @TODO!! |
||
174 | |||
175 | public function testWasCached() |
||
182 | |||
183 | public function testCached() |
||
194 | |||
195 | public function testBuildQueryUrlParameter() |
||
204 | |||
205 | public function testAbstractCache() |
||
210 | } |
||
211 |
If you suppress an error, we recommend checking for the error condition explicitly: