Skip to content

Commit 6fbc362

Browse files
committed
chore: refactored WeatherEndpoint tests
1 parent 97e354f commit 6fbc362

File tree

2 files changed

+102
-144
lines changed

2 files changed

+102
-144
lines changed

tests/OneCallEndpointTest.php

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -76,22 +76,22 @@ public function testOneCallMethodsExist()
7676
$this->assertSame(true, method_exists(OneCallEndpoint::class, 'withCacheTtl'));
7777
}
7878

79-
private function assertGetWeatherResponse(OneCall $response): void
79+
private function assertGetWeatherResponse(OneCall $oneCall): void
8080
{
8181
// Coordinate
82-
$coordinate = $response->getCoordinate();
82+
$coordinate = $oneCall->getCoordinate();
8383
$this->assertInstanceOf(Coordinate::class, $coordinate);
8484
$this->assertSame(38.7078, $coordinate->getLatitude());
8585
$this->assertSame(-9.1366, $coordinate->getLongitude());
8686

8787
// Timezone
88-
$timezone = $response->getTimezone();
88+
$timezone = $oneCall->getTimezone();
8989
$this->assertInstanceOf(Timezone::class, $timezone);
9090
$this->assertSame('Europe/Lisbon', $timezone->getIdentifier());
9191
$this->assertSame(3600, $timezone->getOffset());
9292

9393
// Current
94-
$current = $response->getCurrent();
94+
$current = $oneCall->getCurrent();
9595
$this->assertInstanceOf(Weather::class, $current);
9696
$this->assertSame(null, $current->getMoonriseAt());
9797
$this->assertSame(null, $current->getMoonsetAt());
@@ -131,13 +131,13 @@ private function assertGetWeatherResponse(OneCall $response): void
131131
$this->assertSame('https://openweathermap.org/img/wn/02d@4x.png', $currentWeatherConditionsIcon->getImageUrl());
132132

133133
// MinutelyForecast
134-
$minutelyForecast = $response->getMinutelyForecast();
134+
$minutelyForecast = $oneCall->getMinutelyForecast();
135135
$this->assertContainsOnlyInstancesOf(MinuteForecast::class, $minutelyForecast);
136136
$this->assertSame(0.0, $minutelyForecast[0]->getPrecipitation());
137137
$this->assertSame('2023-07-03 11:36:00', $minutelyForecast[0]->getDateTime()->format('Y-m-d H:i:s'));
138138

139139
// HourlyForecast
140-
$hourlyForecast = $response->getHourlyForecast();
140+
$hourlyForecast = $oneCall->getHourlyForecast();
141141
$this->assertContainsOnlyInstancesOf(Weather::class, $hourlyForecast);
142142
$this->assertSame(null, $hourlyForecast[0]->getSunriseAt());
143143
$this->assertSame(null, $hourlyForecast[0]->getSunsetAt());
@@ -177,7 +177,7 @@ private function assertGetWeatherResponse(OneCall $response): void
177177
$this->assertSame('https://openweathermap.org/img/wn/02d@4x.png', $hourlyForecastWeatherConditionsIcon->getImageUrl());
178178

179179
// DailyForecast
180-
$dailyForecast = $response->getDailyForecast();
180+
$dailyForecast = $oneCall->getDailyForecast();
181181
$this->assertContainsOnlyInstancesOf(Weather::class, $dailyForecast);
182182
$this->assertSame('Expect a day of partly cloudy with clear spells', $dailyForecast[0]->getDescription());
183183
$this->assertSame(1017, $dailyForecast[0]->getAtmosphericPressure());
@@ -238,7 +238,7 @@ private function assertGetWeatherResponse(OneCall $response): void
238238
$this->assertSame('FULL_MOON', $dailyForecastMoonPhase->getSysName());
239239

240240
// Alerts
241-
$alerts = $response->getAlerts();
241+
$alerts = $oneCall->getAlerts();
242242
$this->assertContainsOnlyInstancesOf(Alert::class, $alerts);
243243
$this->assertSame('NWS Portland (Northwest Oregon and Southwest Washington)', $alerts[0]->getSenderName());
244244
$this->assertSame('Heat Advisory', $alerts[0]->getEventName());
@@ -248,36 +248,36 @@ private function assertGetWeatherResponse(OneCall $response): void
248248
$this->assertSame('2023-07-06 06:00:00', $alerts[0]->getEndsAt()->format('Y-m-d H:i:s'));
249249
}
250250

251-
private function assertGetHistoryMomentResponse(WeatherLocation $response): void
251+
private function assertGetHistoryMomentResponse(WeatherLocation $weatherLocation): void
252252
{
253-
$this->assertInstanceOf(WeatherLocation::class, $response);
254-
255-
$this->assertSame(null, $response->getMoonriseAt());
256-
$this->assertSame(null, $response->getMoonsetAt());
257-
$this->assertSame(null, $response->getMoonPhase());
258-
$this->assertSame(17.48, $response->getTemperature());
259-
$this->assertSame(17.16, $response->getTemperatureFeelsLike());
260-
$this->assertSame(null, $response->getDescription());
261-
$this->assertSame(1019, $response->getAtmosphericPressure());
262-
$this->assertSame(72, $response->getHumidity());
263-
$this->assertSame(12.38, $response->getDewPoint());
264-
$this->assertSame(null, $response->getUltraVioletIndex());
265-
$this->assertSame(20, $response->getCloudiness());
266-
$this->assertSame(9999, $response->getVisibility());
267-
$this->assertSame(null, $response->getPrecipitationProbability());
268-
$this->assertSame(null, $response->getRain());
269-
$this->assertSame(null, $response->getSnow());
270-
$this->assertSame('2023-01-01 00:00:00', $response->getDateTime()->format('Y-m-d H:i:s'));
271-
$this->assertSame('2023-01-01 07:54:31', $response->getSunriseAt()->format('Y-m-d H:i:s'));
272-
$this->assertSame('2023-01-01 17:25:02', $response->getSunsetAt()->format('Y-m-d H:i:s'));
273-
274-
$wind = $response->getWind();
253+
$this->assertInstanceOf(WeatherLocation::class, $weatherLocation);
254+
255+
$this->assertSame(null, $weatherLocation->getMoonriseAt());
256+
$this->assertSame(null, $weatherLocation->getMoonsetAt());
257+
$this->assertSame(null, $weatherLocation->getMoonPhase());
258+
$this->assertSame(17.48, $weatherLocation->getTemperature());
259+
$this->assertSame(17.16, $weatherLocation->getTemperatureFeelsLike());
260+
$this->assertSame(null, $weatherLocation->getDescription());
261+
$this->assertSame(1019, $weatherLocation->getAtmosphericPressure());
262+
$this->assertSame(72, $weatherLocation->getHumidity());
263+
$this->assertSame(12.38, $weatherLocation->getDewPoint());
264+
$this->assertSame(null, $weatherLocation->getUltraVioletIndex());
265+
$this->assertSame(20, $weatherLocation->getCloudiness());
266+
$this->assertSame(9999, $weatherLocation->getVisibility());
267+
$this->assertSame(null, $weatherLocation->getPrecipitationProbability());
268+
$this->assertSame(null, $weatherLocation->getRain());
269+
$this->assertSame(null, $weatherLocation->getSnow());
270+
$this->assertSame('2023-01-01 00:00:00', $weatherLocation->getDateTime()->format('Y-m-d H:i:s'));
271+
$this->assertSame('2023-01-01 07:54:31', $weatherLocation->getSunriseAt()->format('Y-m-d H:i:s'));
272+
$this->assertSame('2023-01-01 17:25:02', $weatherLocation->getSunsetAt()->format('Y-m-d H:i:s'));
273+
274+
$wind = $weatherLocation->getWind();
275275
$this->assertInstanceOf(Wind::class, $wind);
276276
$this->assertSame(16.54, $wind->getSpeed());
277277
$this->assertSame(337, $wind->getDirection());
278278
$this->assertSame(16.54, $wind->getGust());
279279

280-
$weatherConditions = $response->getWeatherConditions();
280+
$weatherConditions = $weatherLocation->getWeatherConditions();
281281
$this->assertContainsOnlyInstancesOf(WeatherCondition::class, $weatherConditions);
282282
$this->assertSame(801, $weatherConditions[0]->getId());
283283
$this->assertSame('Clouds', $weatherConditions[0]->getName());
@@ -289,38 +289,38 @@ private function assertGetHistoryMomentResponse(WeatherLocation $response): void
289289
$this->assertSame('02n', $weatherConditionsIcon->getId());
290290
$this->assertSame('https://openweathermap.org/img/wn/02n@4x.png', $weatherConditionsIcon->getImageUrl());
291291

292-
$coordinate = $response->getCoordinate();
292+
$coordinate = $weatherLocation->getCoordinate();
293293
$this->assertInstanceOf(Coordinate::class, $coordinate);
294294
$this->assertSame(38.7078, $coordinate->getLatitude());
295295
$this->assertSame(-9.1366, $coordinate->getLongitude());
296296

297-
$timezone = $response->getTimezone();
297+
$timezone = $weatherLocation->getTimezone();
298298
$this->assertInstanceOf(Timezone::class, $timezone);
299299
$this->assertSame('Europe/Lisbon', $timezone->getIdentifier());
300300
$this->assertSame(0, $timezone->getOffset());
301301
}
302302

303-
private function assertGetHistoryAggregateResponse(WeatherAggregate $response): void
303+
private function assertGetHistoryAggregateResponse(WeatherAggregate $weatherAggregate): void
304304
{
305-
$this->assertInstanceOf(WeatherAggregate::class, $response);
305+
$this->assertInstanceOf(WeatherAggregate::class, $weatherAggregate);
306306

307-
$this->assertSame(75, $response->getCloudiness());
308-
$this->assertSame(71, $response->getHumidity());
309-
$this->assertSame(2.53, $response->getPrecipitation());
310-
$this->assertSame(1017, $response->getAtmosphericPressure());
311-
$this->assertSame('2023-01-01 00:00:00', $response->getDateTime()->format('Y-m-d H:i:s'));
307+
$this->assertSame(75, $weatherAggregate->getCloudiness());
308+
$this->assertSame(71, $weatherAggregate->getHumidity());
309+
$this->assertSame(2.53, $weatherAggregate->getPrecipitation());
310+
$this->assertSame(1017, $weatherAggregate->getAtmosphericPressure());
311+
$this->assertSame('2023-01-01 00:00:00', $weatherAggregate->getDateTime()->format('Y-m-d H:i:s'));
312312

313-
$coordinate = $response->getCoordinate();
313+
$coordinate = $weatherAggregate->getCoordinate();
314314
$this->assertInstanceOf(Coordinate::class, $coordinate);
315315
$this->assertSame(38.7077507, $coordinate->getLatitude());
316316
$this->assertSame(-9.1365919, $coordinate->getLongitude());
317317

318-
$timezone = $response->getTimezone();
318+
$timezone = $weatherAggregate->getTimezone();
319319
$this->assertInstanceOf(Timezone::class, $timezone);
320320
$this->assertSame(null, $timezone->getIdentifier());
321321
$this->assertSame(0, $timezone->getOffset());
322322

323-
$temperature = $response->getTemperature();
323+
$temperature = $weatherAggregate->getTemperature();
324324
$this->assertInstanceOf(Temperature::class, $temperature);
325325
$this->assertSame(17.23, $temperature->getMorning());
326326
$this->assertSame(18.26, $temperature->getDay());
@@ -329,7 +329,7 @@ private function assertGetHistoryAggregateResponse(WeatherAggregate $response):
329329
$this->assertSame(12.52, $temperature->getMin());
330330
$this->assertSame(18.29, $temperature->getMax());
331331

332-
$wind = $response->getWind();
332+
$wind = $weatherAggregate->getWind();
333333
$this->assertInstanceOf(Wind::class, $wind);
334334
$this->assertSame(26.38, $wind->getSpeed());
335335
$this->assertSame(225, $wind->getDirection());

0 commit comments

Comments
 (0)