Skip to content

Commit

Permalink
tests: added air pollution resource tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andrepimpao committed May 9, 2024
1 parent 3ec5544 commit e8a6665
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 224 deletions.
68 changes: 0 additions & 68 deletions src/Endpoint/Util/ValidationTrait.php

This file was deleted.

155 changes: 0 additions & 155 deletions tests/AirPollutionEndpointTest_.php

This file was deleted.

58 changes: 58 additions & 0 deletions tests/Integration/AirPollutionResourceTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

namespace Integration;

use ProgrammatorDev\OpenWeatherMap\Entity\AirPollution\AirPollution;
use ProgrammatorDev\OpenWeatherMap\Entity\AirPollution\AirPollutionCollection;
use ProgrammatorDev\OpenWeatherMap\Test\AbstractTest;
use ProgrammatorDev\OpenWeatherMap\Test\MockResponse;
use ProgrammatorDev\OpenWeatherMap\Test\Util\TestValidationExceptionTrait;
use ProgrammatorDev\OpenWeatherMap\Test\Util\TestItemResponseTrait;

class AirPollutionResourceTest extends AbstractTest
{
use TestItemResponseTrait;
use TestValidationExceptionTrait;

public static function provideItemResponseData(): \Generator
{
yield 'get current' => [
AirPollution::class,
MockResponse::AIR_POLLUTION_CURRENT,
'airPollution',
'getCurrent',
[50, 50]
];
yield 'get forecast' => [
AirPollutionCollection::class,
MockResponse::AIR_POLLUTION_FORECAST,
'airPollution',
'getForecast',
[50, 50]
];
yield 'get history' => [
AirPollutionCollection::class,
MockResponse::AIR_POLLUTION_HISTORY,
'airPollution',
'getHistory',
[50, 50, new \DateTime('-1 day'), new \DateTime('now')]
];
}

public static function provideValidationExceptionData(): \Generator
{
yield 'get current, latitude lower than -90' => ['airPollution', 'getCurrent', [-91, 50]];
yield 'get current, latitude greater than 90' => ['airPollution', 'getCurrent', [91, 50]];
yield 'get current, longitude lower than -180' => ['airPollution', 'getCurrent', [50, -181]];
yield 'get current, longitude greater than 180' => ['airPollution', 'getCurrent', [50, 181]];
yield 'get forecast, latitude lower than -90' => ['airPollution', 'getForecast', [-91, 50]];
yield 'get forecast, latitude greater than 90' => ['airPollution', 'getForecast', [91, 50]];
yield 'get forecast, longitude lower than -180' => ['airPollution', 'getForecast', [50, -181]];
yield 'get forecast, longitude greater than 180' => ['airPollution', 'getForecast', [50, 181]];
yield 'get history, latitude lower than -90' => ['airPollution', 'getHistory', [-91, 50, new \DateTime('-1 day'), new \DateTime('now')]];
yield 'get history, latitude greater than 90' => ['airPollution', 'getHistory', [91, 50, new \DateTime('-1 day'), new \DateTime('now')]];
yield 'get history, longitude lower than -180' => ['airPollution', 'getHistory', [50, -181, new \DateTime('-1 day'), new \DateTime('now')]];
yield 'get history, longitude greater than 180' => ['airPollution', 'getHistory', [50, 181, new \DateTime('-1 day'), new \DateTime('now')]];
yield 'get history, end date before start date' => ['airPollution', 'getHistory', [50, 50, new \DateTime('now'), new \DateTime('-1 day')]];
}
}
4 changes: 3 additions & 1 deletion tests/Integration/OpenWeatherMapTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace ProgrammatorDev\OpenWeatherMap\Test\Integration;

use ProgrammatorDev\OpenWeatherMap\Resource\AirPollutionResource;
use ProgrammatorDev\OpenWeatherMap\Resource\GeocodingResource;
use ProgrammatorDev\OpenWeatherMap\Resource\WeatherResource;
use ProgrammatorDev\OpenWeatherMap\Test\AbstractTest;
Expand All @@ -10,7 +11,8 @@ class OpenWeatherMapTest extends AbstractTest
{
public function testMethods()
{
$this->assertInstanceOf(GeocodingResource::class, $this->api->geocoding());
$this->assertInstanceOf(WeatherResource::class, $this->api->weather());
$this->assertInstanceOf(AirPollutionResource::class, $this->api->airPollution());
$this->assertInstanceOf(GeocodingResource::class, $this->api->geocoding());
}
}

0 comments on commit e8a6665

Please sign in to comment.