Skip to content

Commit

Permalink
Updated http provider
Browse files Browse the repository at this point in the history
  • Loading branch information
lostfocus committed Feb 27, 2024
1 parent 8c011e0 commit e63a82c
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 28 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
42 changes: 21 additions & 21 deletions Src/OpenWeatherMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
Expand Down Expand Up @@ -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)) {
Expand Down
11 changes: 9 additions & 2 deletions Tests/OpenWeatherMapTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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;
Expand All @@ -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);
Expand Down
5 changes: 2 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down

0 comments on commit e63a82c

Please sign in to comment.