diff --git a/composer.json b/composer.json index e8900b4..1b6f4f0 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,6 @@ "php": ">=8.1", "myclabs/deep-copy": "^1.13", "programmatordev/php-api-sdk": "^2.0", - "programmatordev/yet-another-php-validator": "^1.3", "symfony/options-resolver": "^6.4|^7.3" }, "require-dev": { diff --git a/docs/04-error-handling.md b/docs/04-error-handling.md index aee7575..b50e764 100644 --- a/docs/04-error-handling.md +++ b/docs/04-error-handling.md @@ -1,8 +1,5 @@ # Error Handling -- [API Errors](#api-errors) -- [Validation Errors](#validation-errors) - ## API Errors To handle API response errors, multiple exceptions are provided. You can see all available in the following example: @@ -15,13 +12,9 @@ use ProgrammatorDev\OpenWeatherMap\Exception\UnauthorizedException; use ProgrammatorDev\OpenWeatherMap\Exception\UnexpectedErrorException; try { - $location = $api->geocoding()->getByZipCode('1000-001', 'pt'); - $coordinate = $location->getCoordinate(); + // ... - $weather = $api->oneCall()->getWeather( - $coordinate->getLatitude(), - $coordinate->getLongitude() - ); + $weather = $api->oneCall()->getWeather($latitude, $longitude); } // bad request to the API catch (BadRequestException $exception) { @@ -33,7 +26,7 @@ catch (UnauthorizedException $exception) { echo $exception->getCode(); // 401 echo $exception->getMessage(); } -// resource not found +// resource not found, // for example, when trying to get a location with a zip code that does not exist catch (NotFoundException $exception) { echo $exception->getCode(); // 404 @@ -57,35 +50,13 @@ To catch all API errors with a single exception, `ApiErrorException` is availabl use ProgrammatorDev\OpenWeatherMap\Exception\ApiErrorException; try { - $location = $api->geocoding()->getByZipCode('1000-001', 'pt'); - $coordinate = $location->getCoordinate(); - - $weather = $api->oneCall()->getWeather( - $coordinate->getLatitude(), - $coordinate->getLongitude() - ); + // ... + + $weather = $api->oneCall()->getWeather($latitude, $longitude); } // catches all API response errors catch (ApiErrorException $exception) { echo $exception->getCode(); echo $exception->getMessage(); } -``` - -## Validation Errors - -To catch invalid input data (like an out of range coordinate, blank location name, etc.), the `ValidationException` is available: - -```php -use ProgrammatorDev\Validator\Exception\ValidationException; - -try { - // an invalid latitude value is given - $weather = $api->weather()->getCurrent(999, 50); -} -catch (ValidationException $exception) { - // should print: - // The latitude value should be between -90 and 90, 999 given. - echo $exception->getMessage(); -} ``` \ No newline at end of file diff --git a/src/Entity/Icon.php b/src/Entity/Icon.php index 7b179ba..903399a 100644 --- a/src/Entity/Icon.php +++ b/src/Entity/Icon.php @@ -11,7 +11,7 @@ class Icon public function __construct(array $data) { $this->id = $data['icon']; - $this->url = \sprintf('https://openweathermap.org/img/wn/%s@4x.png', $this->id); + $this->url = sprintf('https://openweathermap.org/img/wn/%s@4x.png', $this->id); } public function getId(): string diff --git a/src/OpenWeatherMap.php b/src/OpenWeatherMap.php index 5c4b043..04b7d0f 100644 --- a/src/OpenWeatherMap.php +++ b/src/OpenWeatherMap.php @@ -86,7 +86,7 @@ private function configureApi(): void // if there was a response with an error status code if ($statusCode >= 400) { - $error = \json_decode($response->getBody()->getContents(), true); + $error = json_decode($response->getBody()->getContents(), true); match ($statusCode) { 400 => throw new BadRequestException($error), @@ -101,7 +101,7 @@ private function configureApi(): void $this->addResponseContentsListener(function(ResponseContentsEvent $event) { // decode json string response into an array $contents = $event->getContents(); - $contents = \json_decode($contents, true); + $contents = json_decode($contents, true); $event->setContents($contents); }); diff --git a/src/Resource/AirPollutionResource.php b/src/Resource/AirPollutionResource.php index 4f40ae1..48980cc 100644 --- a/src/Resource/AirPollutionResource.php +++ b/src/Resource/AirPollutionResource.php @@ -5,7 +5,6 @@ use ProgrammatorDev\Api\Method; use ProgrammatorDev\OpenWeatherMap\Entity\AirPollution\AirPollution; use ProgrammatorDev\OpenWeatherMap\Entity\AirPollution\AirPollutionCollection; -use ProgrammatorDev\Validator\Exception\ValidationException; use Psr\Http\Client\ClientExceptionInterface; class AirPollutionResource extends Resource @@ -13,13 +12,10 @@ class AirPollutionResource extends Resource /** * Get access to current air pollution data * - * @throws ValidationException * @throws ClientExceptionInterface */ public function getCurrent(float $latitude, float $longitude): AirPollution { - $this->validateCoordinate($latitude, $longitude); - $data = $this->api->request( method: Method::GET, path: '/data/2.5/air_pollution', @@ -35,13 +31,10 @@ public function getCurrent(float $latitude, float $longitude): AirPollution /** * Get access to air pollution forecast data per hour * - * @throws ValidationException * @throws ClientExceptionInterface */ public function getForecast(float $latitude, float $longitude): AirPollutionCollection { - $this->validateCoordinate($latitude, $longitude); - $data = $this->api->request( method: Method::GET, path: '/data/2.5/air_pollution/forecast', @@ -57,7 +50,6 @@ public function getForecast(float $latitude, float $longitude): AirPollutionColl /** * Get access to historical air pollution data per hour between two dates * - * @throws ValidationException * @throws ClientExceptionInterface */ public function getHistory( @@ -67,9 +59,6 @@ public function getHistory( \DateTimeInterface $endDate ): AirPollutionCollection { - $this->validateCoordinate($latitude, $longitude); - $this->validateDateOrder($startDate, $endDate); - $utcTimezone = new \DateTimeZone('UTC'); $data = $this->api->request( diff --git a/src/Resource/GeocodingResource.php b/src/Resource/GeocodingResource.php index 263c597..21458bf 100644 --- a/src/Resource/GeocodingResource.php +++ b/src/Resource/GeocodingResource.php @@ -6,7 +6,6 @@ use ProgrammatorDev\OpenWeatherMap\Entity\Geocoding\ZipLocation; use ProgrammatorDev\OpenWeatherMap\Entity\Location; use ProgrammatorDev\OpenWeatherMap\Util\EntityTrait; -use ProgrammatorDev\Validator\Exception\ValidationException; use Psr\Http\Client\ClientExceptionInterface; class GeocodingResource extends Resource @@ -19,14 +18,10 @@ class GeocodingResource extends Resource * Get geographical coordinates (latitude, longitude) by using the name of the location (city name or area name) * * @return Location[] - * @throws ValidationException * @throws ClientExceptionInterface */ public function getByLocationName(string $locationName, int $numResults = self::NUM_RESULTS): array { - $this->validateQuery($locationName, 'locationName'); - $this->validatePositive($numResults, 'numResults'); - $data = $this->api->request( method: Method::GET, path: '/geo/1.0/direct', @@ -42,16 +37,12 @@ public function getByLocationName(string $locationName, int $numResults = self:: /** * Get geographical coordinates (latitude, longitude) by using the zip/postal code * - * @throws ValidationException * @throws ClientExceptionInterface */ public function getByZipCode(string $zipCode, string $countryCode): ZipLocation { - $this->validateQuery($zipCode, 'zipCode'); - $this->validateCountryCode($countryCode); - $data = $this->api->request( - method: 'GET', + method: Method::GET, path: '/geo/1.0/zip', query: [ 'zip' => \sprintf('%s,%s', $zipCode, $countryCode) @@ -62,17 +53,13 @@ public function getByZipCode(string $zipCode, string $countryCode): ZipLocation } /** - * Get name of the location (city name or area name) by using geographical coordinates (latitude, longitude) + * Get the name of the location (city name or area name) by using geographical coordinates (latitude, longitude) * * @return Location[] - * @throws ValidationException * @throws ClientExceptionInterface */ public function getByCoordinate(float $latitude, float $longitude, int $numResults = self::NUM_RESULTS): array { - $this->validateCoordinate($latitude, $longitude); - $this->validatePositive($numResults, 'numResults'); - $data = $this->api->request( method: Method::GET, path: '/geo/1.0/reverse', diff --git a/src/Resource/OneCallResource.php b/src/Resource/OneCallResource.php index 427f2ce..837fd08 100644 --- a/src/Resource/OneCallResource.php +++ b/src/Resource/OneCallResource.php @@ -8,7 +8,6 @@ use ProgrammatorDev\OpenWeatherMap\Entity\OneCall\WeatherSummary; use ProgrammatorDev\OpenWeatherMap\Resource\Util\LanguageTrait; use ProgrammatorDev\OpenWeatherMap\Resource\Util\UnitSystemTrait; -use ProgrammatorDev\Validator\Exception\ValidationException; use Psr\Http\Client\ClientExceptionInterface; class OneCallResource extends Resource @@ -20,13 +19,10 @@ class OneCallResource extends Resource * Get access to current weather, minute forecast for 1 hour, hourly forecast for 48 hours, * daily forecast for 8 days and government weather alerts * - * @throws ValidationException * @throws ClientExceptionInterface */ public function getWeather(float $latitude, float $longitude): Weather { - $this->validateCoordinate($latitude, $longitude); - $data = $this->api->request( method: Method::GET, path: '/data/3.0/onecall', @@ -42,13 +38,10 @@ public function getWeather(float $latitude, float $longitude): Weather /** * Get access to weather data for any datetime * - * @throws ValidationException * @throws ClientExceptionInterface */ public function getWeatherByDate(float $latitude, float $longitude, \DateTimeInterface $dateTime): WeatherMoment { - $this->validateCoordinate($latitude, $longitude); - $utcTimezone = new \DateTimeZone('UTC'); $data = $this->api->request( @@ -67,13 +60,10 @@ public function getWeatherByDate(float $latitude, float $longitude, \DateTimeInt /** * Get access to aggregated weather data for a particular date * - * @throws ValidationException * @throws ClientExceptionInterface */ public function getWeatherSummaryByDate(float $latitude, float $longitude, \DateTimeInterface $date): WeatherSummary { - $this->validateCoordinate($latitude, $longitude); - $data = $this->api->request( method: Method::GET, path: '/data/3.0/onecall/day_summary', diff --git a/src/Resource/Resource.php b/src/Resource/Resource.php index b9f59e7..d17aef8 100644 --- a/src/Resource/Resource.php +++ b/src/Resource/Resource.php @@ -4,12 +4,10 @@ use ProgrammatorDev\OpenWeatherMap\OpenWeatherMap; use ProgrammatorDev\OpenWeatherMap\Resource\Util\CacheTrait; -use ProgrammatorDev\OpenWeatherMap\Resource\Util\ValidationTrait; class Resource { use CacheTrait; - use ValidationTrait; public function __construct(protected OpenWeatherMap $api) {} } \ No newline at end of file diff --git a/src/Resource/Util/UnitSystemTrait.php b/src/Resource/Util/UnitSystemTrait.php index 166ac87..168a220 100644 --- a/src/Resource/Util/UnitSystemTrait.php +++ b/src/Resource/Util/UnitSystemTrait.php @@ -2,20 +2,12 @@ namespace ProgrammatorDev\OpenWeatherMap\Resource\Util; -use ProgrammatorDev\Validator\Exception\ValidationException; use function DeepCopy\deep_copy; trait UnitSystemTrait { - use ValidationTrait; - - /** - * @throws ValidationException - */ public function withUnitSystem(string $unitSystem): static { - $this->validateUnitSystem($unitSystem); - $clone = deep_copy($this, true); $clone->api->addQueryDefault('units', $unitSystem); diff --git a/src/Resource/Util/ValidationTrait.php b/src/Resource/Util/ValidationTrait.php deleted file mode 100644 index 33dd7d6..0000000 --- a/src/Resource/Util/ValidationTrait.php +++ /dev/null @@ -1,71 +0,0 @@ -assert($query, $name); - } - - /** - * @throws ValidationException - */ - protected function validatePositive(int $number, string $name): void - { - Validator::greaterThan(0)->assert($number, $name); - } - - /** - * @throws ValidationException - */ - protected function validateCoordinate(float $latitude, float $longitude): void - { - Validator::range(-90, 90)->assert($latitude, 'latitude'); - Validator::range(-180, 180)->assert($longitude, 'longitude'); - } - - /** - * @throws ValidationException - */ - protected function validateCountryCode(string $countryCode): void - { - Validator::country()->assert($countryCode, 'countryCode'); - } - - /** - * @throws ValidationException - */ - protected function validateLanguage(string $language): void - { - Validator::choice(Language::getOptions())->assert($language, 'language'); - } - - /** - * @throws ValidationException - */ - protected function validateUnitSystem(string $unitSystem): void - { - Validator::choice(UnitSystem::getOptions())->assert($unitSystem, 'unitSystem'); - } - - /** - * @throws ValidationException - */ - protected function validateDateOrder(\DateTimeInterface $startDate, \DateTimeInterface $endDate): void - { - Validator::greaterThan( - constraint: $startDate, - message: 'The endDate must be after the startDate.' - )->assert($endDate); - } -} \ No newline at end of file diff --git a/src/Resource/WeatherResource.php b/src/Resource/WeatherResource.php index c4cd357..96a5b06 100644 --- a/src/Resource/WeatherResource.php +++ b/src/Resource/WeatherResource.php @@ -7,7 +7,6 @@ use ProgrammatorDev\OpenWeatherMap\Entity\Weather\WeatherCollection; use ProgrammatorDev\OpenWeatherMap\Resource\Util\LanguageTrait; use ProgrammatorDev\OpenWeatherMap\Resource\Util\UnitSystemTrait; -use ProgrammatorDev\Validator\Exception\ValidationException; use Psr\Http\Client\ClientExceptionInterface; class WeatherResource extends Resource @@ -20,13 +19,10 @@ class WeatherResource extends Resource /** * Get access to current weather data * - * @throws ValidationException * @throws ClientExceptionInterface */ public function getCurrent(float $latitude, float $longitude): Weather { - $this->validateCoordinate($latitude, $longitude); - $data = $this->api->request( method: Method::GET, path: '/data/2.5/weather', @@ -42,14 +38,10 @@ public function getCurrent(float $latitude, float $longitude): Weather /** * Get access to 5-day weather forecast data with 3-hour steps * - * @throws ValidationException * @throws ClientExceptionInterface */ public function getForecast(float $latitude, float $longitude, int $numResults = self::NUM_RESULTS): WeatherCollection { - $this->validateCoordinate($latitude, $longitude); - $this->validatePositive($numResults, 'numResults'); - $data = $this->api->request( method: Method::GET, path: '/data/2.5/forecast', diff --git a/src/Test/Util/TestValidationExceptionTrait.php b/src/Test/Util/TestValidationExceptionTrait.php deleted file mode 100644 index 073cd15..0000000 --- a/src/Test/Util/TestValidationExceptionTrait.php +++ /dev/null @@ -1,18 +0,0 @@ -expectException(ValidationException::class); - $this->api->$resource()->$method(...$args); - } - - abstract public static function provideValidationExceptionData(): \Generator; -} \ No newline at end of file diff --git a/src/Util/EntityTrait.php b/src/Util/EntityTrait.php index da67145..24ee6ce 100644 --- a/src/Util/EntityTrait.php +++ b/src/Util/EntityTrait.php @@ -6,7 +6,7 @@ trait EntityTrait { private function createEntityList(string $entityClass, array $list): array { - return \array_map(function(array $data) use ($entityClass) { + return array_map(function(array $data) use ($entityClass) { return new $entityClass($data); }, $list); } diff --git a/src/Util/ReflectionTrait.php b/src/Util/ReflectionTrait.php index c1f6f6e..1eb92ab 100644 --- a/src/Util/ReflectionTrait.php +++ b/src/Util/ReflectionTrait.php @@ -11,7 +11,7 @@ private function getClassConstants(string $className): array // Sort by alphabetical order // to be more intuitive when listing values for error messages - \asort($constants); + asort($constants); return $constants; } diff --git a/tests/Integration/AirPollutionResourceTest.php b/tests/Integration/AirPollutionResourceTest.php index 753fe19..ec52e26 100644 --- a/tests/Integration/AirPollutionResourceTest.php +++ b/tests/Integration/AirPollutionResourceTest.php @@ -6,13 +6,11 @@ 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 { @@ -38,21 +36,4 @@ public static function provideItemResponseData(): \Generator [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')]]; - } } \ No newline at end of file diff --git a/tests/Integration/CacheTraitTest.php b/tests/Integration/CacheTraitTest.php index ec6395d..9e8cc73 100644 --- a/tests/Integration/CacheTraitTest.php +++ b/tests/Integration/CacheTraitTest.php @@ -33,6 +33,7 @@ public function getCacheTtl(): ?int public function testMethods(): void { + $this->assertSame(60, $this->resource->getCacheTtl()); $this->assertSame(600, $this->resource->withCacheTtl(600)->getCacheTtl()); $this->assertSame(60, $this->resource->getCacheTtl()); // back to default value } diff --git a/tests/Integration/GeocodingResourceTest.php b/tests/Integration/GeocodingResourceTest.php index 269372f..7f8dfe0 100644 --- a/tests/Integration/GeocodingResourceTest.php +++ b/tests/Integration/GeocodingResourceTest.php @@ -7,14 +7,12 @@ use ProgrammatorDev\OpenWeatherMap\Test\AbstractTest; use ProgrammatorDev\OpenWeatherMap\Test\MockResponse; use ProgrammatorDev\OpenWeatherMap\Test\Util\TestCollectionResponseTrait; -use ProgrammatorDev\OpenWeatherMap\Test\Util\TestValidationExceptionTrait; use ProgrammatorDev\OpenWeatherMap\Test\Util\TestItemResponseTrait; class GeocodingResourceTest extends AbstractTest { use TestItemResponseTrait; use TestCollectionResponseTrait; - use TestValidationExceptionTrait; public static function provideItemResponseData(): \Generator { @@ -44,18 +42,4 @@ public static function provideCollectionResponseData(): \Generator [50, 50] ]; } - - public static function provideValidationExceptionData(): \Generator - { - yield 'get by location name, blank value' => ['geocoding', 'getByLocationName', ['']]; - yield 'get by location name, zero num results' => ['geocoding', 'getByLocationName', ['test', 0]]; - yield 'get by coordinate, latitude lower than -90' => ['geocoding', 'getByCoordinate', [-91, 50]]; - yield 'get by coordinate, latitude greater than 90' => ['geocoding', 'getByCoordinate', [91, 50]]; - yield 'get by coordinate, longitude lower than -180' => ['geocoding', 'getByCoordinate', [50, -181]]; - yield 'get by coordinate, longitude greater than 180' => ['geocoding', 'getByCoordinate', [50, 181]]; - yield 'get by coordinate, zero num results' => ['geocoding', 'getByCoordinate', [50, 50, 0]]; - yield 'get by zip code, blank zip code' => ['geocoding', 'getByZipCode', ['', 'pt']]; - yield 'get by zip code, blank country code' => ['geocoding', 'getByZipCode', ['1000-001', '']]; - yield 'get by zip code, invalid country code' => ['geocoding', 'getByZipCode', ['1000-001', 'invalid']]; - } } \ No newline at end of file diff --git a/tests/Integration/LanguageTraitTest.php b/tests/Integration/LanguageTraitTest.php index 79651ee..31cf054 100644 --- a/tests/Integration/LanguageTraitTest.php +++ b/tests/Integration/LanguageTraitTest.php @@ -26,6 +26,7 @@ public function getLanguage(): string public function testMethods(): void { + $this->assertSame('en', $this->resource->getLanguage()); $this->assertSame('pt', $this->resource->withLanguage('pt')->getLanguage()); $this->assertSame('en', $this->resource->getLanguage()); // back to default value } diff --git a/tests/Integration/OneCallResourceTest.php b/tests/Integration/OneCallResourceTest.php index b9f2c29..4b0de5b 100644 --- a/tests/Integration/OneCallResourceTest.php +++ b/tests/Integration/OneCallResourceTest.php @@ -7,13 +7,11 @@ use ProgrammatorDev\OpenWeatherMap\Entity\OneCall\WeatherSummary; use ProgrammatorDev\OpenWeatherMap\Test\AbstractTest; use ProgrammatorDev\OpenWeatherMap\Test\MockResponse; -use ProgrammatorDev\OpenWeatherMap\Test\Util\TestValidationExceptionTrait; use ProgrammatorDev\OpenWeatherMap\Test\Util\TestItemResponseTrait; class OneCallResourceTest extends AbstractTest { use TestItemResponseTrait; - use TestValidationExceptionTrait; public static function provideItemResponseData(): \Generator { @@ -39,20 +37,4 @@ public static function provideItemResponseData(): \Generator [50, 50, new \DateTime()] ]; } - - public static function provideValidationExceptionData(): \Generator - { - yield 'get weather, latitude lower than -90' => ['oneCall', 'getWeather', [-91, 50]]; - yield 'get weather, latitude greater than 90' => ['oneCall', 'getWeather', [91, 50]]; - yield 'get weather, longitude lower than -180' => ['oneCall', 'getWeather', [50, -181]]; - yield 'get weather, longitude greater than 180' => ['oneCall', 'getWeather', [50, 181]]; - yield 'get weather by date, latitude lower than -90' => ['oneCall', 'getWeatherByDate', [-91, 50, new \DateTime()]]; - yield 'get weather by date, latitude greater than 90' => ['oneCall', 'getWeatherByDate', [91, 50, new \DateTime()]]; - yield 'get weather by date, longitude lower than -180' => ['oneCall', 'getWeatherByDate', [50, -181, new \DateTime()]]; - yield 'get weather by date, longitude greater than 180' => ['oneCall', 'getWeatherByDate', [50, 181, new \DateTime()]]; - yield 'get weather summary by date, latitude lower than -90' => ['oneCall', 'getWeatherSummaryByDate', [-91, 50, new \DateTime()]]; - yield 'get weather summary by date, latitude greater than 90' => ['oneCall', 'getWeatherSummaryByDate', [91, 50, new \DateTime()]]; - yield 'get weather summary by date, longitude lower than -180' => ['oneCall', 'getWeatherSummaryByDate', [50, -181, new \DateTime()]]; - yield 'get weather summary by date, longitude greater than 180' => ['oneCall', 'getWeatherSummaryByDate', [50, 181, new \DateTime()]]; - } } \ No newline at end of file diff --git a/tests/Integration/UnitSystemTraitTest.php b/tests/Integration/UnitSystemTraitTest.php index 629c3b6..11e5919 100644 --- a/tests/Integration/UnitSystemTraitTest.php +++ b/tests/Integration/UnitSystemTraitTest.php @@ -5,7 +5,6 @@ use ProgrammatorDev\OpenWeatherMap\Resource\Resource; use ProgrammatorDev\OpenWeatherMap\Resource\Util\UnitSystemTrait; use ProgrammatorDev\OpenWeatherMap\Test\AbstractTest; -use ProgrammatorDev\Validator\Exception\ValidationException; class UnitSystemTraitTest extends AbstractTest { @@ -27,13 +26,8 @@ public function getUnitSystem(): string public function testMethods(): void { + $this->assertSame('metric', $this->resource->getUnitSystem()); $this->assertSame('imperial', $this->resource->withUnitSystem('imperial')->getUnitSystem()); $this->assertSame('metric', $this->resource->getUnitSystem()); // back to default value } - - public function testValidationException(): void - { - $this->expectException(ValidationException::class); - $this->resource->withUnitSystem('invalid'); - } } \ No newline at end of file diff --git a/tests/Integration/WeatherResourceTest.php b/tests/Integration/WeatherResourceTest.php index de960b8..579aa01 100644 --- a/tests/Integration/WeatherResourceTest.php +++ b/tests/Integration/WeatherResourceTest.php @@ -6,13 +6,11 @@ use ProgrammatorDev\OpenWeatherMap\Entity\Weather\WeatherCollection; use ProgrammatorDev\OpenWeatherMap\Test\AbstractTest; use ProgrammatorDev\OpenWeatherMap\Test\MockResponse; -use ProgrammatorDev\OpenWeatherMap\Test\Util\TestValidationExceptionTrait; use ProgrammatorDev\OpenWeatherMap\Test\Util\TestItemResponseTrait; class WeatherResourceTest extends AbstractTest { use TestItemResponseTrait; - use TestValidationExceptionTrait; public static function provideItemResponseData(): \Generator { @@ -31,17 +29,4 @@ public static function provideItemResponseData(): \Generator [50, 50] ]; } - - public static function provideValidationExceptionData(): \Generator - { - yield 'get current, latitude lower than -90' => ['weather', 'getCurrent', [-91, 50]]; - yield 'get current, latitude greater than 90' => ['weather', 'getCurrent', [91, 50]]; - yield 'get current, longitude lower than -180' => ['weather', 'getCurrent', [50, -181]]; - yield 'get current, longitude greater than 180' => ['weather', 'getCurrent', [50, 181]]; - yield 'get forecast, latitude lower than -90' => ['weather', 'getForecast', [-91, 50]]; - yield 'get forecast, latitude greater than 90' => ['weather', 'getForecast', [91, 50]]; - yield 'get forecast, longitude lower than -180' => ['weather', 'getForecast', [50, -181]]; - yield 'get forecast, longitude greater than 180' => ['weather', 'getForecast', [50, 181]]; - yield 'get forecast, zero num results' => ['weather', 'getForecast', [50, 50, 0]]; - } } \ No newline at end of file