Skip to content

Commit c872cab

Browse files
committed
Merge branch 'master' into airPollution
2 parents 941af8d + 3abb656 commit c872cab

File tree

6 files changed

+71
-6
lines changed

6 files changed

+71
-6
lines changed

Cmfcmf/OpenWeatherMap/CurrentWeather.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public function __construct($data, $units)
124124
$this->pressure = new Unit($data->main->pressure, 'hPa');
125125
$this->wind = new Wind(
126126
new Unit($data->wind->speed, $windSpeedUnit),
127-
property_exists($data->wind, 'deg') ? new Unit($data->wind->deg) : null
127+
property_exists($data->wind, 'deg') && $data->wind->deg !== null ? new Unit($data->wind->deg) : null
128128
);
129129
$this->clouds = new Unit($data->clouds->all, '%');
130130

Cmfcmf/OpenWeatherMap/Util/Wind.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class Wind
2929
public $speed;
3030

3131
/**
32-
* @var Unit The wind direction.
32+
* @var Unit|null The wind direction.
3333
*/
3434
public $direction;
3535

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ $units = 'metric';
4949

5050
// You can use every PSR-17 compatible HTTP request factory
5151
// and every PSR-18 compatible HTTP client. This example uses
52-
// `http-interop/http-factory-guzzle` and `php-http/guzzle6-adapter`
52+
// `http-interop/http-factory-guzzle` ^1.0 and `php-http/guzzle6-adapter` ^2.0 || ^1.0
5353
// which you need to install separately.
5454
$httpRequestFactory = new RequestFactory();
5555
$httpClient = GuzzleAdapter::createWithConfig([]);

tests/FakeData.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class FakeData
4141
"wind":{"speed":5.71,"deg":229.501},
4242
"dt_txt":"2014-07-23 09:00:00"
4343
},{
44-
"id":1851632,
44+
"id":1851633,
4545
"dt":1406106000,
4646
"coord":{"lon":138.933334,"lat":34.966671},
4747
"sys":{"type":3,"id":168940,"message":0.0297,"country":"US","sunrise":1427723751,"sunset":1427768967},
@@ -57,7 +57,7 @@ class FakeData
5757
},
5858
"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04d"}],
5959
"clouds":{"all":88},
60-
"wind":{"speed":5.71,"deg":229.501},
60+
"wind":{"speed":5.71,"deg":null},
6161
"dt_txt":"2014-07-23 09:00:00"
6262
}]
6363
}';
@@ -131,4 +131,26 @@ public static function forecastXML()
131131
const AIR_POLLUTION_CO = <<<JSON
132132
{"time":"2019-10-26T18:15:01Z","location":{"latitude":40.0013,"longitude":-74.5899},"data":[{"precision":-4.999999987376214e-07,"pressure":1000,"value":1.3621800576402165e-07},{"precision":-4.999999987376214e-07,"pressure":681.2920532226562,"value":1.1375255581924648e-07},{"precision":-4.999999987376214e-07,"pressure":464.15887451171875,"value":1.038646146866995e-07},{"precision":4.547785792397008e-08,"pressure":316.2277526855469,"value":1.7132454388502083e-07},{"precision":2.0379493648192692e-08,"pressure":215.44346618652344,"value":1.1696990753762293e-07},{"precision":1.3544046773006357e-08,"pressure":146.77992248535156,"value":6.227620730214767e-08},{"precision":1.1640130637147195e-08,"pressure":100,"value":4.9975231064536274e-08},{"precision":1.0211765655299132e-08,"pressure":68.12920379638672,"value":5.12039584066315e-08},{"precision":8.732828682411764e-09,"pressure":46.415889739990234,"value":3.545491722434235e-08},{"precision":9.014621049630023e-09,"pressure":31.62277603149414,"value":1.8382916522341475e-08},{"precision":9.907536124842409e-09,"pressure":21.544347763061523,"value":1.8576894467159377e-09},{"precision":1.2424509421293806e-08,"pressure":14.677992820739746,"value":-9.168636516676543e-09},{"precision":1.5284239651691678e-08,"pressure":10,"value":2.2812981725905956e-08},{"precision":2.1570169650431126e-08,"pressure":6.812920570373535,"value":5.2754966617385435e-08},{"precision":2.913583330155234e-08,"pressure":4.6415886878967285,"value":6.849927558505442e-08},{"precision":3.875063470104578e-08,"pressure":3.1622776985168457,"value":-1.6690947290953773e-08},{"precision":5.409619419083356e-08,"pressure":2.1544346809387207,"value":-2.6772934091923162e-08},{"precision":7.21046475860021e-08,"pressure":1.4677993059158325,"value":1.0366177605192206e-07},{"precision":9.633781417051068e-08,"pressure":1,"value":4.523308305692808e-08},{"precision":1.4515163115902396e-07,"pressure":0.6812920570373535,"value":7.092549481058086e-08},{"precision":2.062685240389328e-07,"pressure":0.46415889263153076,"value":6.615503878037998e-08},{"precision":2.907468115154188e-07,"pressure":0.3162277638912201,"value":-3.38239033226273e-07},{"precision":4.297635598504712e-07,"pressure":0.2154434621334076,"value":1.6955895034698187e-06},{"precision":6.078225851524621e-07,"pressure":0.14677992463111877,"value":2.2467602889264526e-07},{"precision":6.833994916632946e-07,"pressure":0.10000000149011612,"value":7.392927159344254e-07},{"precision":1.017242993839318e-06,"pressure":0.04641588777303696,"value":2.740956688285223e-06},{"precision":1.8878859009419102e-06,"pressure":0.02154434658586979,"value":2.360790404054569e-06},{"precision":3.784052296396112e-06,"pressure":0.009999999776482582,"value":8.210285159293562e-06},{"precision":6.664358807029203e-06,"pressure":0.004641588777303696,"value":1.6543688616366126e-05},{"precision":-1.0293148989148904e-05,"pressure":0.002154434798285365,"value":4.2166899220319465e-05},{"precision":-1.5317784345825203e-05,"pressure":0.0010000000474974513,"value":4.3754778744187206e-05},{"precision":-1.9999999494757503e-05,"pressure":0.00046415888937190175,"value":1.658740802668035e-05},{"precision":-1.9999999494757503e-05,"pressure":0.00021544346236623824,"value":1.658740802668035e-05},{"precision":-1.9999999494757503e-05,"pressure":9.999999747378752e-05,"value":1.658740802668035e-05},{"precision":-1.9999999494757503e-05,"pressure":4.641588748199865e-05,"value":1.658740802668035e-05},{"precision":-1.9999999494757503e-05,"pressure":2.1544346964219585e-05,"value":1.658740802668035e-05},{"precision":-1.9999999494757503e-05,"pressure":9.999999747378752e-06,"value":1.658740802668035e-05}]}
133133
JSON;
134+
135+
const CURRENT_WEATHER_XML_NO_WIND_DIRECTION = <<<XML
136+
<current>
137+
<city id="2950159" name="Berlin">
138+
<coord lon="13.41" lat="52.52"></coord>
139+
<country>DE</country>
140+
<sun rise="2017-01-02T07:16:51" set="2017-01-02T15:04:50"></sun>
141+
</city>
142+
<temperature value="36.48" min="35.6" max="37.4" unit="fahrenheit"></temperature>
143+
<humidity value="86" unit="%"></humidity>
144+
<pressure value="1014" unit="hPa"></pressure>
145+
<wind>
146+
<speed value="9.17" name="Fresh Breeze"></speed>
147+
<gusts></gusts>
148+
</wind>
149+
<clouds value="75" name="broken clouds"></clouds>
150+
<visibility value="8000"></visibility>
151+
<precipitation mode="no"></precipitation>
152+
<weather number="500" value="light rain" icon="10d"></weather>
153+
<lastupdate value="2017-01-02T12:20:00"></lastupdate>
154+
</current>
155+
XML;
134156
}

tests/OpenWeatherMap/CurrentWeatherGroupTest.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ public function setUp()
3232
$this->currentWeatherGroup = new CurrentWeatherGroup($this->fakeJson, 'metric');
3333
}
3434

35+
public function testWindDirection()
36+
{
37+
$this->assertSame($this->currentWeatherGroup->current()->wind->direction->getValue(), 229.501);
38+
$this->currentWeatherGroup->next();
39+
$this->assertNull($this->currentWeatherGroup->current()->wind->direction);
40+
}
41+
3542
public function testRewind()
3643
{
3744
$expectIndex = 1851632;
@@ -50,7 +57,7 @@ public function testCurrent()
5057
}
5158
public function testNext()
5259
{
53-
$expectIndex = 1851632;
60+
$expectIndex = 1851633;
5461
$this->currentWeatherGroup->next();
5562
$position = $this->currentWeatherGroup->key();
5663

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
/*
4+
* OpenWeatherMap-PHP-API — A PHP API to parse weather data from https://OpenWeatherMap.org.
5+
*
6+
* @license MIT
7+
*
8+
* Please see the LICENSE file distributed with this source code for further
9+
* information regarding copyright and licensing.
10+
*
11+
* Please visit the following links to read about the usage policies and the license of
12+
* OpenWeatherMap data before using this library:
13+
*
14+
* @see https://OpenWeatherMap.org/price
15+
* @see https://OpenWeatherMap.org/terms
16+
* @see https://OpenWeatherMap.org/appid
17+
*/
18+
19+
namespace Cmfcmf\OpenWeatherMap\Tests\OpenWeatherMap;
20+
21+
use Cmfcmf\OpenWeatherMap\CurrentWeather;
22+
use Cmfcmf\OpenWeatherMap\Tests\FakeData;
23+
24+
class CurrentWeatherTest extends \PHPUnit_Framework_TestCase
25+
{
26+
public function testWindDirection()
27+
{
28+
$fakeXml = new \SimpleXMLElement(FakeData::CURRENT_WEATHER_XML);
29+
$weather = new CurrentWeather($fakeXml, "metric");
30+
$this->assertSame($weather->wind->direction->getValue(), 300.0);
31+
32+
$fakeXml = new \SimpleXMLElement(FakeData::CURRENT_WEATHER_XML_NO_WIND_DIRECTION);
33+
$weather = new CurrentWeather($fakeXml, "metric");
34+
$this->assertNull($weather->wind->direction);
35+
}
36+
}

0 commit comments

Comments
 (0)