Skip to content

Commit 724c5c0

Browse files
committedMay 13, 2024·
tests: added one call resource tests
1 parent 898b88b commit 724c5c0

15 files changed

+125
-4
lines changed
 

‎src/Entity/AirPollution/AirPollutionData.php

+3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ public function __construct(array $data)
3838
$this->ammonia = $data['components']['nh3'];
3939
}
4040

41+
/**
42+
* DateTime in UTC
43+
*/
4144
public function getDateTime(): \DateTimeImmutable
4245
{
4346
return $this->dateTime;

‎src/Entity/Location.php

+6
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,17 @@ public function getTimezone(): ?Timezone
115115
return $this->timezone;
116116
}
117117

118+
/**
119+
* Sunrise date in UTC
120+
*/
118121
public function getSunriseAt(): ?\DateTimeImmutable
119122
{
120123
return $this->sunriseAt;
121124
}
122125

126+
/**
127+
* Sunset date in UTC
128+
*/
123129
public function getSunsetAt(): ?\DateTimeImmutable
124130
{
125131
return $this->sunsetAt;

‎src/Entity/OneCall/BaseWeather.php

+3
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ public function __construct(array $data)
5151
$this->snowVolume = $data['snow']['1h'] ?? $data['snow']['3h'] ?? $data['snow'] ?? null;
5252
}
5353

54+
/**
55+
* DateTime in UTC
56+
*/
5457
public function getDateTime(): \DateTimeImmutable
5558
{
5659
return $this->dateTime;

‎src/Entity/OneCall/DayData.php

+12
Original file line numberDiff line numberDiff line change
@@ -62,21 +62,33 @@ public function getMoonPhase(): MoonPhase
6262
return $this->moonPhase;
6363
}
6464

65+
/**
66+
* Moonrise date in UTC
67+
*/
6568
public function getMoonriseAt(): \DateTimeImmutable
6669
{
6770
return $this->moonriseAt;
6871
}
6972

73+
/**
74+
* Moonset date in UTC
75+
*/
7076
public function getMoonsetAt(): \DateTimeImmutable
7177
{
7278
return $this->moonsetAt;
7379
}
7480

81+
/**
82+
* Sunrise date in UTC
83+
*/
7584
public function getSunriseAt(): \DateTimeImmutable
7685
{
7786
return $this->sunriseAt;
7887
}
7988

89+
/**
90+
* Sunset date in UTC
91+
*/
8092
public function getSunsetAt(): \DateTimeImmutable
8193
{
8294
return $this->sunsetAt;

‎src/Entity/OneCall/MinuteData.php

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ public function __construct(array $data)
1414
$this->precipitation = $data['precipitation'];
1515
}
1616

17+
/**
18+
* DateTime in UTC
19+
*/
1720
public function getDateTime(): \DateTimeImmutable
1821
{
1922
return $this->dateTime;

‎src/Entity/OneCall/WeatherData.php

+6
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,17 @@ public function getVisibility(): ?int
4646
return $this->visibility;
4747
}
4848

49+
/**
50+
* Sunrise date in UTC
51+
*/
4952
public function getSunriseAt(): ?\DateTimeImmutable
5053
{
5154
return $this->sunriseAt;
5255
}
5356

57+
/**
58+
* Sunset date in UTC
59+
*/
5460
public function getSunsetAt(): ?\DateTimeImmutable
5561
{
5662
return $this->sunsetAt;

‎src/Entity/OneCall/WeatherSummary.php

+3
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ public function getTimezone(): Timezone
7070
return $this->timezone;
7171
}
7272

73+
/**
74+
* DateTime in UTC
75+
*/
7376
public function getDateTime(): \DateTimeImmutable
7477
{
7578
return $this->dateTime;

‎src/Entity/Weather/WeatherData.php

+3
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ public function __construct(array $data)
6161
$this->snowVolume = $data['snow']['1h'] ?? $data['snow']['3h'] ?? null;
6262
}
6363

64+
/**
65+
* DateTime in UTC
66+
*/
6467
public function getDateTime(): \DateTimeImmutable
6568
{
6669
return $this->dateTime;

‎src/Resource/AirPollutionResource.php

+6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
class AirPollutionResource extends Resource
1212
{
1313
/**
14+
* Get access to current air pollution data
15+
*
1416
* @throws ValidationException
1517
* @throws ClientExceptionInterface
1618
*/
@@ -31,6 +33,8 @@ public function getCurrent(float $latitude, float $longitude): AirPollution
3133
}
3234

3335
/**
36+
* Get access to air pollution forecast data
37+
*
3438
* @throws ValidationException
3539
* @throws ClientExceptionInterface
3640
*/
@@ -51,6 +55,8 @@ public function getForecast(float $latitude, float $longitude): AirPollutionColl
5155
}
5256

5357
/**
58+
* Get access to historical air pollution data
59+
*
5460
* @throws ValidationException
5561
* @throws ClientExceptionInterface
5662
*/

‎src/Resource/GeocodingResource.php

+6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ class GeocodingResource extends Resource
1616
private const NUM_RESULTS = 5;
1717

1818
/**
19+
* Get geographical coordinates (latitude, longitude) by using the name of the location (city name or area name)
20+
*
1921
* @return Location[]
2022
* @throws ValidationException
2123
* @throws ClientExceptionInterface
@@ -38,6 +40,8 @@ public function getByLocationName(string $locationName, int $numResults = self::
3840
}
3941

4042
/**
43+
* Get geographical coordinates (latitude, longitude) by using the zip/postal code
44+
*
4145
* @throws ValidationException
4246
* @throws ClientExceptionInterface
4347
*/
@@ -58,6 +62,8 @@ public function getByZipCode(string $zipCode, string $countryCode): ZipLocation
5862
}
5963

6064
/**
65+
* Get name of the location (city name or area name) by using geographical coordinates (latitude, longitude)
66+
*
6167
* @return Location[]
6268
* @throws ValidationException
6369
* @throws ClientExceptionInterface

‎src/Resource/OneCallResource.php

+8-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use ProgrammatorDev\Api\Method;
66
use ProgrammatorDev\OpenWeatherMap\Entity\OneCall\Weather;
7-
use ProgrammatorDev\OpenWeatherMap\Entity\OneCall\WeatherData;
87
use ProgrammatorDev\OpenWeatherMap\Entity\OneCall\WeatherMoment;
98
use ProgrammatorDev\OpenWeatherMap\Entity\OneCall\WeatherSummary;
109
use ProgrammatorDev\OpenWeatherMap\Resource\Util\LanguageTrait;
@@ -18,6 +17,9 @@ class OneCallResource extends Resource
1817
use UnitSystemTrait;
1918

2019
/**
20+
* Get access to current weather, minute forecast for 1 hour, hourly forecast for 48 hours,
21+
* daily forecast for 8 days and government weather alerts
22+
*
2123
* @throws ValidationException
2224
* @throws ClientExceptionInterface
2325
*/
@@ -38,10 +40,12 @@ public function getWeather(float $latitude, float $longitude): Weather
3840
}
3941

4042
/**
43+
* Get access to weather data for any datetime
44+
*
4145
* @throws ValidationException
4246
* @throws ClientExceptionInterface
4347
*/
44-
public function getWeatherByDateTime(float $latitude, float $longitude, \DateTimeInterface $dateTime): WeatherMoment
48+
public function getWeatherByDate(float $latitude, float $longitude, \DateTimeInterface $dateTime): WeatherMoment
4549
{
4650
$this->validateCoordinate($latitude, $longitude);
4751

@@ -61,6 +65,8 @@ public function getWeatherByDateTime(float $latitude, float $longitude, \DateTim
6165
}
6266

6367
/**
68+
* Get access to aggregated weather data for a particular date
69+
*
6470
* @throws ValidationException
6571
* @throws ClientExceptionInterface
6672
*/

‎src/Resource/WeatherResource.php

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ class WeatherResource extends Resource
1818
private const NUM_RESULTS = 40;
1919

2020
/**
21+
* Get access to current weather data
22+
*
2123
* @throws ValidationException
2224
* @throws ClientExceptionInterface
2325
*/
@@ -38,6 +40,8 @@ public function getCurrent(float $latitude, float $longitude): Weather
3840
}
3941

4042
/**
43+
* Get access to 5-day weather forecast data with 3-hour steps
44+
*
4145
* @throws ValidationException
4246
* @throws ClientExceptionInterface
4347
*/

‎src/Test/MockResponse.php

+2-2
Large diffs are not rendered by default.
+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
namespace ProgrammatorDev\OpenWeatherMap\Test\Integration;
4+
5+
use ProgrammatorDev\OpenWeatherMap\Entity\OneCall\Weather;
6+
use ProgrammatorDev\OpenWeatherMap\Entity\OneCall\WeatherMoment;
7+
use ProgrammatorDev\OpenWeatherMap\Entity\OneCall\WeatherSummary;
8+
use ProgrammatorDev\OpenWeatherMap\Test\AbstractTest;
9+
use ProgrammatorDev\OpenWeatherMap\Test\MockResponse;
10+
use ProgrammatorDev\OpenWeatherMap\Test\Util\TestValidationExceptionTrait;
11+
use ProgrammatorDev\OpenWeatherMap\Test\Util\TestItemResponseTrait;
12+
13+
class OneCallResourceTest extends AbstractTest
14+
{
15+
use TestItemResponseTrait;
16+
use TestValidationExceptionTrait;
17+
18+
public static function provideItemResponseData(): \Generator
19+
{
20+
yield 'get weather' => [
21+
Weather::class,
22+
MockResponse::ONE_CALL_WEATHER,
23+
'oneCall',
24+
'getWeather',
25+
[50, 50]
26+
];
27+
yield 'get weather by date' => [
28+
WeatherMoment::class,
29+
MockResponse::ONE_CALL_TIMEMACHINE,
30+
'oneCall',
31+
'getWeatherByDate',
32+
[50, 50, new \DateTime()]
33+
];
34+
yield 'get weather summary by date' => [
35+
WeatherSummary::class,
36+
MockResponse::ONE_CALL_DAY_SUMMARY,
37+
'oneCall',
38+
'getWeatherSummaryByDate',
39+
[50, 50, new \DateTime()]
40+
];
41+
}
42+
43+
public static function provideValidationExceptionData(): \Generator
44+
{
45+
yield 'get weather, latitude lower than -90' => ['oneCall', 'getWeather', [-91, 50]];
46+
yield 'get weather, latitude greater than 90' => ['oneCall', 'getWeather', [91, 50]];
47+
yield 'get weather, longitude lower than -180' => ['oneCall', 'getWeather', [50, -181]];
48+
yield 'get weather, longitude greater than 180' => ['oneCall', 'getWeather', [50, 181]];
49+
yield 'get weather by date, latitude lower than -90' => ['oneCall', 'getWeatherByDate', [-91, 50, new \DateTime()]];
50+
yield 'get weather by date, latitude greater than 90' => ['oneCall', 'getWeatherByDate', [91, 50, new \DateTime()]];
51+
yield 'get weather by date, longitude lower than -180' => ['oneCall', 'getWeatherByDate', [50, -181, new \DateTime()]];
52+
yield 'get weather by date, longitude greater than 180' => ['oneCall', 'getWeatherByDate', [50, 181, new \DateTime()]];
53+
yield 'get weather summary by date, latitude lower than -90' => ['oneCall', 'getWeatherSummaryByDate', [-91, 50, new \DateTime()]];
54+
yield 'get weather summary by date, latitude greater than 90' => ['oneCall', 'getWeatherSummaryByDate', [91, 50, new \DateTime()]];
55+
yield 'get weather summary by date, longitude lower than -180' => ['oneCall', 'getWeatherSummaryByDate', [50, -181, new \DateTime()]];
56+
yield 'get weather summary by date, longitude greater than 180' => ['oneCall', 'getWeatherSummaryByDate', [50, 181, new \DateTime()]];
57+
}
58+
}

‎tests/Integration/OpenWeatherMapTest.php

+2
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44

55
use ProgrammatorDev\OpenWeatherMap\Resource\AirPollutionResource;
66
use ProgrammatorDev\OpenWeatherMap\Resource\GeocodingResource;
7+
use ProgrammatorDev\OpenWeatherMap\Resource\OneCallResource;
78
use ProgrammatorDev\OpenWeatherMap\Resource\WeatherResource;
89
use ProgrammatorDev\OpenWeatherMap\Test\AbstractTest;
910

1011
class OpenWeatherMapTest extends AbstractTest
1112
{
1213
public function testMethods()
1314
{
15+
$this->assertInstanceOf(OneCallResource::class, $this->api->oneCall());
1416
$this->assertInstanceOf(WeatherResource::class, $this->api->weather());
1517
$this->assertInstanceOf(AirPollutionResource::class, $this->api->airPollution());
1618
$this->assertInstanceOf(GeocodingResource::class, $this->api->geocoding());

0 commit comments

Comments
 (0)
Please sign in to comment.