From e63a82cc19e4b630cb1482f41682fd9dd8bb3aae Mon Sep 17 00:00:00 2001 From: Dominik Schwind Date: Tue, 27 Feb 2024 20:35:47 +0100 Subject: [PATCH] Updated http provider --- CHANGELOG.md | 6 ++++++ README.md | 4 ++-- Src/OpenWeatherMap.php | 42 ++++++++++++++++++------------------ Tests/OpenWeatherMapTest.php | 11 ++++++++-- composer.json | 5 ++--- 5 files changed, 40 insertions(+), 28 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5399064..11b8332 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.2.1] - 2024-02-27 + +### Changed + +* Updated the HTTP provider to replace HTTPlug factories by PSR-17 + ## [0.2.0] - 2022-12-17 ### Changed diff --git a/README.md b/README.md index 4ec6b66..d2d4d85 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,9 @@ ![Packagist Version](https://img.shields.io/packagist/v/php-weather/openweathermap) ![PHP Weather Common Version](https://img.shields.io/badge/phpweather--core-0.4.*-brightgreen) -![PHP Weather HTTP Provider Version](https://img.shields.io/badge/phpweather--http--provider-0.5.*-brightgreen) +![PHP Weather HTTP Provider Version](https://img.shields.io/badge/phpweather--http--provider-0.6.*-brightgreen) ![GitHub Release Date](https://img.shields.io/github/release-date/php-weather/openweathermap) -![GitHub commits since tagged version](https://img.shields.io/github/commits-since/php-weather/openweathermap/0.2.0) +![GitHub commits since tagged version](https://img.shields.io/github/commits-since/php-weather/openweathermap/0.2.1) ![GitHub last commit](https://img.shields.io/github/last-commit/php-weather/openweathermap) ![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/php-weather/openweathermap/php.yml?branch=main) ![GitHub](https://img.shields.io/github/license/php-weather/openweathermap) diff --git a/Src/OpenWeatherMap.php b/Src/OpenWeatherMap.php index 98be2d0..1f0e87c 100644 --- a/Src/OpenWeatherMap.php +++ b/Src/OpenWeatherMap.php @@ -32,6 +32,26 @@ public function __construct(ClientInterface $client, string $key, ?RequestFactor parent::__construct($client, $requestFactory); } + /** + * @param WeatherQuery $query + * @return Weather + * @throws Throwable + */ + public function getHistorical(WeatherQuery $query): Weather + { + throw new NoWeatherData(); + } + + /** + * @param WeatherQuery $query + * @return WeatherCollection + * @throws Throwable + */ + public function getHistoricalTimeLine(WeatherQuery $query): WeatherCollection + { + throw new NoWeatherData(); + } + protected function getCurrentWeatherQueryString(WeatherQuery $query): string { return sprintf( @@ -54,26 +74,6 @@ protected function getForecastWeatherQueryString(WeatherQuery $query): string ); } - /** - * @param WeatherQuery $query - * @return Weather - * @throws Throwable - */ - public function getHistorical(WeatherQuery $query): Weather - { - throw new NoWeatherData(); - } - - /** - * @param WeatherQuery $query - * @return WeatherCollection - * @throws Throwable - */ - public function getHistoricalTimeLine(WeatherQuery $query): WeatherCollection - { - throw new NoWeatherData(); - } - /** * @param WeatherQuery $query * @return string @@ -198,7 +198,7 @@ private function mapItemRawdata(float $latitude, float $longitude, array $rawDat is_array($rawData['clouds']) && array_key_exists('all', $rawData['clouds']) ) { - $weather->setCloudCover($rawData['clouds']['all']); + $weather->setCloudCover($rawData['clouds']['all'] / 100); } if (array_key_exists('pop', $rawData)) { diff --git a/Tests/OpenWeatherMapTest.php b/Tests/OpenWeatherMapTest.php index bd24669..28c53a6 100644 --- a/Tests/OpenWeatherMapTest.php +++ b/Tests/OpenWeatherMapTest.php @@ -5,13 +5,15 @@ use DateTime; use DateTimeZone; -use PHPUnit\Framework\TestCase; use Http\Client\HttpClient; use PHPUnit\Framework\MockObject\MockObject; +use PHPUnit\Framework\TestCase; use PhpWeather\Common\WeatherQuery; +use PhpWeather\Exception; use Psr\Http\Message\RequestFactoryInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; +use Psr\Http\Message\StreamInterface; class OpenWeatherMapTest extends TestCase { @@ -29,6 +31,9 @@ public function setUp(): void $this->provider = new OpenWeatherMap($this->client, $this->key, $this->requestFactory); } + /** + * @throws Exception + */ public function testCurrentWeather(): void { $latitude = 47.8739259; @@ -41,8 +46,10 @@ public function testCurrentWeather(): void $this->requestFactory->expects(self::once())->method('createRequest')->with('GET', $testString)->willReturn($request); $responseBodyString = file_get_contents(__DIR__.'/resources/currentWeather.json'); + $body = $this->createMock(StreamInterface::class); + $body->method('__toString')->willReturn($responseBodyString); $response = $this->createMock(ResponseInterface::class); - $response->expects(self::once())->method('getBody')->willReturn($responseBodyString); + $response->expects(self::once())->method('getBody')->willReturn($body); $this->client->expects(self::once())->method('sendRequest')->with($request)->willReturn($response); $currentWeather = $this->provider->getCurrentWeather($testQuery); diff --git a/composer.json b/composer.json index ee0a028..6f7ae1e 100644 --- a/composer.json +++ b/composer.json @@ -16,12 +16,11 @@ "require": { "php": "^8", "ext-json": "*", - "php-weather/http-provider": "^0.5", + "php-weather/http-provider": "^0.6", "php-weather/core": "^0.4" }, "require-dev": { - "jetbrains/phpstorm-attributes": "^1.0", - "php-http/guzzle7-adapter": "dev-master", + "php-http/guzzle7-adapter": "^1.0", "phpstan/phpstan": "^1.6", "phpunit/phpunit": ">=8.0" },