From eac16135103e8ddeaf33bb5005e5e61a33284b82 Mon Sep 17 00:00:00 2001 From: Dominik Schwind Date: Tue, 27 Feb 2024 20:22:44 +0100 Subject: [PATCH] Updated http provider --- CHANGELOG.md | 6 ++++++ README.md | 4 ++-- Src/OpenMeteo.php | 2 +- Tests/OpenMeteoTest.php | 10 +++++----- composer.json | 3 +-- 5 files changed, 15 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3bef047..e692705 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.3.2] - 2024-02-27 + +### Changed + +* Updated the HTTP provider to replace HTTPlug factories by PSR-17 + ## [0.3.1] - 2023-09-23 ### Fixed diff --git a/README.md b/README.md index 3a944c0..cf14659 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,9 @@ ![Packagist Version](https://img.shields.io/packagist/v/php-weather/open-meteo) ![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/open-meteo) -![GitHub commits since tagged version](https://img.shields.io/github/commits-since/php-weather/open-meteo/0.3.1) +![GitHub commits since tagged version](https://img.shields.io/github/commits-since/php-weather/open-meteo/0.3.2) ![GitHub last commit](https://img.shields.io/github/last-commit/php-weather/open-meteo) ![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/php-weather/open-meteo/php.yml?branch=main) ![GitHub](https://img.shields.io/github/license/php-weather/open-meteo) diff --git a/Src/OpenMeteo.php b/Src/OpenMeteo.php index b7777c3..4fb9c71 100644 --- a/Src/OpenMeteo.php +++ b/Src/OpenMeteo.php @@ -138,7 +138,7 @@ protected function mapRawData(float $latitude, float $longitude, array $rawData, if ($weatherDateTime < $currentDateTime) { $weather->setType(Type::HISTORICAL); - } elseif ($weatherDateTime === $currentDateTime) { + } elseif ($weatherDateTime == $currentDateTime) { $weather->setType(Type::CURRENT); } else { $weather->setType(Type::FORECAST); diff --git a/Tests/OpenMeteoTest.php b/Tests/OpenMeteoTest.php index c2010b7..51c0670 100644 --- a/Tests/OpenMeteoTest.php +++ b/Tests/OpenMeteoTest.php @@ -4,23 +4,23 @@ namespace PhpWeather\Provider\OpenMeteo; use GuzzleHttp\Psr7\Stream; -use Http\Client\HttpClient; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use PhpWeather\Common\WeatherQuery; +use Psr\Http\Client\ClientInterface; use Psr\Http\Message\RequestFactoryInterface; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; class OpenMeteoTest extends TestCase { - private MockObject|HttpClient $client; + private MockObject|ClientInterface $client; private MockObject|RequestFactoryInterface $requestFactory; private OpenMeteo $provider; public function setUp(): void { - $this->client = $this->createMock(HttpClient::class); + $this->client = $this->createMock(ClientInterface::class); $this->requestFactory = $this->createMock(RequestFactoryInterface::class); $this->provider = new OpenMeteo($this->client, $this->requestFactory); @@ -30,7 +30,7 @@ public function testCurrentWeather(): void { $latitude = 47.8739259; $longitude = 8.0043961; - $datetime = (new \DateTime())->setTimezone(new \DateTimeZone('UTC'))->setDate(2022, 07,31)->setTime(16,00); + $datetime = (new \DateTime())->setTimezone(new \DateTimeZone('UTC'))->setDate(2022, 07, 31)->setTime(16, 00); $testQuery = WeatherQuery::create($latitude, $longitude, $datetime); $testString = 'https://api.open-meteo.com/v1/forecast?latitude=47.8739259&longitude=8.0043961&hourly=temperature_2m,relativehumidity_2m,dewpoint_2m,apparent_temperature,pressure_msl,precipitation,weathercode,cloudcover,windspeed_10m,winddirection_10m&timezone=UTC¤t_weather=true&start_date=2022-07-31&end_date=2022-08-01'; @@ -39,7 +39,7 @@ public function testCurrentWeather(): void $responseBodyString = file_get_contents(__DIR__.'/resources/currentWeather.json'); $response = $this->createMock(ResponseInterface::class); - if ($resource = fopen('data://text/plain,' . $responseBodyString, 'rb')) { + if ($resource = fopen('data://text/plain,'.$responseBodyString, 'rb')) { $reponseStream = new Stream($resource); } else { $this->fail(); diff --git a/composer.json b/composer.json index 838bd98..a50172f 100644 --- a/composer.json +++ b/composer.json @@ -16,11 +16,10 @@ "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": "^1.0", "phpstan/phpstan": "^1.6", "phpunit/phpunit": ">=8.0"