Skip to content

Commit b51dbbf

Browse files
committed
Merge pull request #36 from cmfcmf/fix-metric-unit
Also convert "metric" temperature unit to degrees.
2 parents ab387eb + cd108db commit b51dbbf

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

Cmfcmf/OpenWeatherMap/Util/Unit.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ public function __toString()
8181
public function getUnit()
8282
{
8383
// Units are inconsistent. Only celsius and fahrenheit are not abbreviated. This check fixes that.
84-
if ($this->unit == 'celsius') {
84+
// Also, the API started to return "metric" as temperature unit recently. Also fix that.
85+
if ($this->unit == 'celsius' || $this->unit == 'metric') {
8586
return "°C";
8687
} else if ($this->unit == 'fahrenheit') {
8788
return 'F';

tests/Util/UnitTest.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,21 @@ public function testGetUnitWithStringAsUnit()
9696
$this->assertSame("Hey! I'm cmfcmf", $this->unit->getUnit());
9797
}
9898

99-
public function testCelsiusFixture()
99+
public function testCelsiusFix()
100100
{
101101
$this->givenThereIsAUnitWithUnit("celsius");
102102

103103
$this->assertSame("°C", $this->unit->getUnit());
104104
}
105105

106-
public function testFahrenheitFixture()
106+
public function testMetricFix()
107+
{
108+
$this->givenThereIsAUnitWithUnit("metric");
109+
110+
$this->assertSame("°C", $this->unit->getUnit());
111+
}
112+
113+
public function testFahrenheitFix()
107114
{
108115
$this->givenThereIsAUnitWithUnit("fahrenheit");
109116

0 commit comments

Comments
 (0)