Skip to content

Commit e8a6665

Browse files
committed
tests: added air pollution resource tests
1 parent 3ec5544 commit e8a6665

File tree

4 files changed

+61
-224
lines changed

4 files changed

+61
-224
lines changed

src/Endpoint/Util/ValidationTrait.php

Lines changed: 0 additions & 68 deletions
This file was deleted.

tests/AirPollutionEndpointTest_.php

Lines changed: 0 additions & 155 deletions
This file was deleted.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
namespace Integration;
4+
5+
use ProgrammatorDev\OpenWeatherMap\Entity\AirPollution\AirPollution;
6+
use ProgrammatorDev\OpenWeatherMap\Entity\AirPollution\AirPollutionCollection;
7+
use ProgrammatorDev\OpenWeatherMap\Test\AbstractTest;
8+
use ProgrammatorDev\OpenWeatherMap\Test\MockResponse;
9+
use ProgrammatorDev\OpenWeatherMap\Test\Util\TestValidationExceptionTrait;
10+
use ProgrammatorDev\OpenWeatherMap\Test\Util\TestItemResponseTrait;
11+
12+
class AirPollutionResourceTest extends AbstractTest
13+
{
14+
use TestItemResponseTrait;
15+
use TestValidationExceptionTrait;
16+
17+
public static function provideItemResponseData(): \Generator
18+
{
19+
yield 'get current' => [
20+
AirPollution::class,
21+
MockResponse::AIR_POLLUTION_CURRENT,
22+
'airPollution',
23+
'getCurrent',
24+
[50, 50]
25+
];
26+
yield 'get forecast' => [
27+
AirPollutionCollection::class,
28+
MockResponse::AIR_POLLUTION_FORECAST,
29+
'airPollution',
30+
'getForecast',
31+
[50, 50]
32+
];
33+
yield 'get history' => [
34+
AirPollutionCollection::class,
35+
MockResponse::AIR_POLLUTION_HISTORY,
36+
'airPollution',
37+
'getHistory',
38+
[50, 50, new \DateTime('-1 day'), new \DateTime('now')]
39+
];
40+
}
41+
42+
public static function provideValidationExceptionData(): \Generator
43+
{
44+
yield 'get current, latitude lower than -90' => ['airPollution', 'getCurrent', [-91, 50]];
45+
yield 'get current, latitude greater than 90' => ['airPollution', 'getCurrent', [91, 50]];
46+
yield 'get current, longitude lower than -180' => ['airPollution', 'getCurrent', [50, -181]];
47+
yield 'get current, longitude greater than 180' => ['airPollution', 'getCurrent', [50, 181]];
48+
yield 'get forecast, latitude lower than -90' => ['airPollution', 'getForecast', [-91, 50]];
49+
yield 'get forecast, latitude greater than 90' => ['airPollution', 'getForecast', [91, 50]];
50+
yield 'get forecast, longitude lower than -180' => ['airPollution', 'getForecast', [50, -181]];
51+
yield 'get forecast, longitude greater than 180' => ['airPollution', 'getForecast', [50, 181]];
52+
yield 'get history, latitude lower than -90' => ['airPollution', 'getHistory', [-91, 50, new \DateTime('-1 day'), new \DateTime('now')]];
53+
yield 'get history, latitude greater than 90' => ['airPollution', 'getHistory', [91, 50, new \DateTime('-1 day'), new \DateTime('now')]];
54+
yield 'get history, longitude lower than -180' => ['airPollution', 'getHistory', [50, -181, new \DateTime('-1 day'), new \DateTime('now')]];
55+
yield 'get history, longitude greater than 180' => ['airPollution', 'getHistory', [50, 181, new \DateTime('-1 day'), new \DateTime('now')]];
56+
yield 'get history, end date before start date' => ['airPollution', 'getHistory', [50, 50, new \DateTime('now'), new \DateTime('-1 day')]];
57+
}
58+
}

tests/Integration/OpenWeatherMapTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace ProgrammatorDev\OpenWeatherMap\Test\Integration;
44

5+
use ProgrammatorDev\OpenWeatherMap\Resource\AirPollutionResource;
56
use ProgrammatorDev\OpenWeatherMap\Resource\GeocodingResource;
67
use ProgrammatorDev\OpenWeatherMap\Resource\WeatherResource;
78
use ProgrammatorDev\OpenWeatherMap\Test\AbstractTest;
@@ -10,7 +11,8 @@ class OpenWeatherMapTest extends AbstractTest
1011
{
1112
public function testMethods()
1213
{
13-
$this->assertInstanceOf(GeocodingResource::class, $this->api->geocoding());
1414
$this->assertInstanceOf(WeatherResource::class, $this->api->weather());
15+
$this->assertInstanceOf(AirPollutionResource::class, $this->api->airPollution());
16+
$this->assertInstanceOf(GeocodingResource::class, $this->api->geocoding());
1517
}
1618
}

0 commit comments

Comments
 (0)