diff --git a/src/DTO/Measurements/Humidity.php b/src/DTO/Measurements/Humidity.php index 4ad961c..6244d1d 100644 --- a/src/DTO/Measurements/Humidity.php +++ b/src/DTO/Measurements/Humidity.php @@ -19,7 +19,7 @@ class Humidity extends AbstractDTO * * @var float|null */ - protected $value = 0.0; + protected $value; /** * Unit type. @@ -49,7 +49,7 @@ public function __construct(array $data = []) */ public function parse(array $data): void { - $this->setValue((float) $data['humidity']); + $this->setValue($data['humidity'] ?? null); } /** @@ -60,7 +60,7 @@ public function parse(array $data): void */ public function setValue(?float $value) : self { - $this->value = $value !== null ? (float) $value : 0.0; + $this->value = $value !== null ? (float) $value : null; return $this; } diff --git a/src/DTO/Measurements/Precipitation.php b/src/DTO/Measurements/Precipitation.php index acf64e7..085fd90 100644 --- a/src/DTO/Measurements/Precipitation.php +++ b/src/DTO/Measurements/Precipitation.php @@ -26,21 +26,21 @@ class Precipitation extends AbstractDTO * * @var float|null */ - protected $value = 0.0; + protected $value; /** * Lowest predicted amount (uncertain). * - * @var float + * @var float|null */ - protected $lowestValue = 0.0; + protected $lowestValue; /** * Highest predicted amount (uncertain). * - * @var float + * @var float|null */ - protected $highestValue = 0.0; + protected $highestValue; /** * Unit type. @@ -70,22 +70,52 @@ public function __construct(array $data = []) */ public function parse(array $data): void { - $this->setType($data['precipType']) - ->setValue((float) ($data['prec50'] ?? $data['precip3'] ?? null)); + // Set precipitation type based on danish key. + $this->setTypeByDanishKey($data['precipType'] ?? null); + + // If "temp50" is empty, + // then we know EPS is not available. + if (!empty($data['temp50'])) { + $this->setValue($data['prec50'] ?? null) + ->setLowestValue($data['prec10'] ?? null) + ->setHighestValue($data['prec90'] ?? null); + } else { + $this->setValue($data['precip1'] ?? null); + } + } - if (!empty($data['prec50'])) { - $this->setLowestValue((float) $data['prec10']) - ->setHighestValue((float) $data['prec90']); + /** + * Set precipitation type by danish key. + * + * @param string|null $key + * @return $this + */ + public function setTypeByDanishKey(?string $key) : self + { + switch ($key) { + case 'regn': + $this->setType('rain'); + break; + case 'hagl': + $this->setType('hail'); + break; + case 'slud': + $this->setType('sleet'); + break; + case 'sne': + $this->setType('snow'); + break; } + return $this; } /** * Set precipitation type. * - * @param string $type + * @param string|null $type * @return $this */ - public function setType(string $type) : self + public function setType(?string $type) : self { $this->type = $type; return $this; @@ -109,7 +139,7 @@ public function getType() :? string */ public function setValue(?float $value) : self { - $this->value = (float) ($value < 0.1 ? 0.0 : $value); + $this->value = $value !== null ? (float) ($value < 0.1 ? 0.0 : $value) : null; return $this; } @@ -131,7 +161,7 @@ public function getValue() :? float */ public function setLowestValue(?float $value) : self { - $this->lowestValue = (float) ($value < 0.1 ? 0.0 : $value); + $this->lowestValue = $value !== null ? (float) ($value < 0.1 ? 0.0 : $value) : null; return $this; } @@ -153,7 +183,7 @@ public function getLowestValue() :? float */ public function setHighestValue(?float $value) : self { - $this->highestValue = (float) ($value < 0.1 ? 0 : $value); + $this->highestValue = $value !== null ? (float) ($value < 0.1 ? 0 : $value) : null; return $this; } diff --git a/src/DTO/Measurements/Pressure.php b/src/DTO/Measurements/Pressure.php index 7f6b084..2147da6 100644 --- a/src/DTO/Measurements/Pressure.php +++ b/src/DTO/Measurements/Pressure.php @@ -17,9 +17,9 @@ class Pressure extends AbstractDTO /** * Pressure value. * - * @var float + * @var float|null */ - protected $value = 0.0; + protected $value; /** * Unit type. @@ -49,7 +49,7 @@ public function __construct(array $data = []) */ public function parse(array $data): void { - $this->setValue((float) $data['pressure']); + $this->setValue($data['pressure'] ?? null); } /** @@ -60,7 +60,7 @@ public function parse(array $data): void */ public function setValue(?float $value) : self { - $this->value = $value !== null ? (float) $value : 0.0; + $this->value = $value !== null ? (float) $value : null; return $this; } diff --git a/src/DTO/Measurements/Temperature.php b/src/DTO/Measurements/Temperature.php index 707b285..1ed67f3 100644 --- a/src/DTO/Measurements/Temperature.php +++ b/src/DTO/Measurements/Temperature.php @@ -17,23 +17,23 @@ class Temperature extends AbstractDTO /** * Predicted/expected temperature. * - * @var float + * @var float|null */ - protected $value = 0.0; + protected $value; /** * Lowest predicted temperature (uncertain). * - * @var float + * @var float|null */ - protected $lowestValue = 0.0; + protected $lowestValue; /** * Highest predicted temperature (uncertain). * - * @var float + * @var float|null */ - protected $highestValue = 0.0; + protected $highestValue; /** * Unit type. @@ -63,11 +63,14 @@ public function __construct(array $data = []) */ public function parse(array $data): void { - $this->setValue((float) ($data['temp50'] ?? $data['temp'] ?? null)); - + // If "temp50" is empty, + // then we know EPS is not available. if (!empty($data['temp50'])) { - $this->setLowestValue((float) $data['temp10']) - ->setHighestValue((float) $data['temp90']); + $this->setValue($data['temp50'] ?? null) + ->setLowestValue($data['temp10'] ?? null) + ->setHighestValue($data['temp90'] ?? null); + } else { + $this->setValue($data['temp'] ?? null); } } @@ -79,7 +82,7 @@ public function parse(array $data): void */ public function setValue(?float $value) : self { - $this->value = $value !== null ? (float) $value : 0.0; + $this->value = $value !== null ? (float) $value : null; return $this; } @@ -101,7 +104,7 @@ public function getValue() :? float */ public function setLowestValue(?float $value) : self { - $this->lowestValue = $value !== null ? (float) $value : 0.0; + $this->lowestValue = $value !== null ? (float) $value : null; return $this; } @@ -123,7 +126,7 @@ public function getLowestValue() :? float */ public function setHighestValue(?float $value) : self { - $this->highestValue = $value !== null ? (float) $value : 0.0; + $this->highestValue = $value !== null ? (float) $value : null; return $this; } diff --git a/src/DTO/Measurements/Visibility.php b/src/DTO/Measurements/Visibility.php index c2e0368..6cde12e 100644 --- a/src/DTO/Measurements/Visibility.php +++ b/src/DTO/Measurements/Visibility.php @@ -17,9 +17,9 @@ class Visibility extends AbstractDTO /** * Visibility value. * - * @var float + * @var float|null */ - protected $value = 0.0; + protected $value; /** * Unit type. @@ -49,7 +49,7 @@ public function __construct(array $data = []) */ public function parse(array $data): void { - $this->setValue((float) $data['visibility']); + $this->setValue($data['visibility'] ?? null); } /** @@ -60,7 +60,7 @@ public function parse(array $data): void */ public function setValue(?float $value) : self { - $this->value = $value !== null ? (float) $value : 0.0; + $this->value = $value !== null ? (float) $value : null; return $this; } diff --git a/src/DTO/Measurements/Wind/Direction.php b/src/DTO/Measurements/Wind/Direction.php index a826fef..9ca8af6 100644 --- a/src/DTO/Measurements/Wind/Direction.php +++ b/src/DTO/Measurements/Wind/Direction.php @@ -31,7 +31,7 @@ class Direction extends AbstractDTO * * @var float|null */ - protected $degrees = 0.0; + protected $degrees; /** * Parse data. @@ -66,19 +66,19 @@ public function setDirectionByDegrees(?float $degrees) : self if ($degrees < 360 && $degrees > 337.5) { $this->setDirection('N'); } elseif ($degrees > 292.5) { - $this->setDirection('NV'); + $this->setDirection('NW'); } elseif ($degrees > 247.5) { $this->setDirection('V'); } elseif ($degrees > 202.5) { - $this->setDirection('SV'); + $this->setDirection('SW'); } elseif ($degrees > 157.5) { $this->setDirection('S'); } elseif ($degrees > 112.5) { - $this->setDirection('SØ'); + $this->setDirection('SE'); } elseif ($degrees > 67.5) { - $this->setDirection('Ø'); + $this->setDirection('E'); } elseif ($degrees > 22.5) { - $this->setDirection('NØ'); + $this->setDirection('NE'); } elseif ($degrees >= 0) { $this->setDirection('N'); } @@ -95,68 +95,82 @@ public function setDirection(?string $direction) : self { switch ($direction) { case 'N': - $this->direction = 'Nord'; + $this->direction = 'North'; $this->setAbbreviation('N'); break; case 'S': - $this->direction = 'Syd'; + $this->direction = 'South'; $this->setAbbreviation('S'); break; case 'Ø': - $this->direction = 'Øst'; - $this->setAbbreviation('Ø'); + case 'E': + $this->direction = 'East'; + $this->setAbbreviation('E'); break; case 'V': - $this->direction = 'Vest'; - $this->setAbbreviation('V'); + case 'W': + $this->direction = 'West'; + $this->setAbbreviation('W'); break; case 'NØ': - $this->direction = 'Nordøst'; - $this->setAbbreviation('NØ'); + case 'NE': + $this->direction = 'Northeast'; + $this->setAbbreviation('NE'); break; case 'NV': - $this->direction = 'Nordvest'; - $this->setAbbreviation('NV'); + case 'NW': + $this->direction = 'Northwest'; + $this->setAbbreviation('NW'); break; case 'SØ': - $this->direction = 'Sydøst'; - $this->setAbbreviation('SØ'); + case 'SE': + $this->direction = 'Southeast'; + $this->setAbbreviation('SE'); break; case 'SV': - $this->direction = 'Sydvest'; - $this->setAbbreviation('SV'); + case 'SW': + $this->direction = 'Southwest'; + $this->setAbbreviation('SW'); break; case 'NNØ': - $this->direction = 'Nord-nordøst'; - $this->setAbbreviation('NNØ'); + case 'NNE': + $this->direction = 'North-northeast'; + $this->setAbbreviation('NNE'); break; case 'NNV': - $this->direction = 'Nord-nordvest'; - $this->setAbbreviation('NNV'); + case 'NNW': + $this->direction = 'North-northwest'; + $this->setAbbreviation('NNW'); break; case 'ØNØ': - $this->direction = 'Øst-nordøst'; - $this->setAbbreviation('ØNØ'); + case 'ENE': + $this->direction = 'East-northeast'; + $this->setAbbreviation('ENE'); break; case 'ØSØ': - $this->direction = 'Øst-sydøst'; - $this->setAbbreviation('ØSØ'); + case 'ESE': + $this->direction = 'East-southeast'; + $this->setAbbreviation('ESE'); break; case 'SSØ': - $this->direction = 'Syd-sydøst'; - $this->setAbbreviation('SSØ'); + case 'SSE': + $this->direction = 'South-southeast'; + $this->setAbbreviation('SSE'); break; case 'SSV': - $this->direction = 'Syd-sydvest'; + case 'SSW': + $this->direction = 'South-southwest'; $this->setAbbreviation('SSV'); break; case 'VNV': - $this->direction = 'Vest-nordvest'; - $this->setAbbreviation('VNV'); + case 'WNW': + $this->direction = 'West-northwest'; + $this->setAbbreviation('WNW'); break; case 'VSV': - $this->direction = 'Vest-sydvest'; - $this->setAbbreviation('VSV'); + case 'WSW': + $this->direction = 'West-southwest'; + $this->setAbbreviation('WSW'); break; } return $this; @@ -202,7 +216,7 @@ public function getAbbreviation() :? string */ public function setDegrees(?float $degrees) : self { - $this->degrees = $degrees !== null ? (float) $degrees : 0.0; + $this->degrees = $degrees !== null ? (float) $degrees : null; return $this; } diff --git a/src/DTO/Measurements/Wind/Gust.php b/src/DTO/Measurements/Wind/Gust.php index 8f33a26..3063ad6 100644 --- a/src/DTO/Measurements/Wind/Gust.php +++ b/src/DTO/Measurements/Wind/Gust.php @@ -17,9 +17,9 @@ class Gust extends AbstractDTO /** * Wind speed value. * - * @var float + * @var float|null */ - protected $value = 0.0; + protected $value; /** * Unit type. @@ -49,7 +49,7 @@ public function __construct(array $data = []) */ public function parse(array $data): void { - $this->setValue((float) $data['windGust']); + $this->setValue($data['windGust'] ?? null); } /** @@ -60,7 +60,7 @@ public function parse(array $data): void */ public function setValue(?float $value) : self { - $this->value = $value !== null ? (float) $value : 0.0; + $this->value = $value !== null ? (float) $value : null; return $this; } diff --git a/src/DTO/Measurements/Wind/Speed.php b/src/DTO/Measurements/Wind/Speed.php index b6e71fb..9ce591b 100644 --- a/src/DTO/Measurements/Wind/Speed.php +++ b/src/DTO/Measurements/Wind/Speed.php @@ -17,23 +17,23 @@ class Speed extends AbstractDTO /** * Wind speed value. * - * @var float + * @var float|null */ - protected $value = 0.0; + protected $value; /** * Lowest predicted wind speed (uncertain). * - * @var float + * @var float|null */ - protected $lowestValue = 0.0; + protected $lowestValue; /** * Highest predicted wind speed (uncertain). * - * @var float + * @var float|null */ - protected $highestValue = 0.0; + protected $highestValue; /** * Unit type. @@ -63,9 +63,15 @@ public function __construct(array $data = []) */ public function parse(array $data): void { - $this->setValue((float) $data['windSpeed']) - ->setLowestValue( (float) $data['windspeed10']) - ->setHighestValue((float) $data['windspeed90']); + // If "temp50" is empty, + // then we know EPS is not available. + if (!empty($data['temp50'])) { + $this->setValue($data['windspeed50'] ?? null) + ->setLowestValue($data['windspeed10'] ?? null) + ->setHighestValue($data['windspeed90'] ?? null); + } else { + $this->setValue($data['windSpeed'] ?? null); + } } /** @@ -76,7 +82,7 @@ public function parse(array $data): void */ public function setValue(?float $value) : self { - $this->value = $value !== null ? (float) $value : 0.0; + $this->value = $value !== null ? (float) $value : null; return $this; } @@ -98,7 +104,7 @@ public function getValue() :? float */ public function setLowestValue(?float $value) : self { - $this->lowestValue = $value !== null ? (float) $value : 0.0; + $this->lowestValue = $value !== null ? (float) $value : null; return $this; } @@ -120,7 +126,7 @@ public function getLowestValue() :? float */ public function setHighestValue(?float $value) : self { - $this->highestValue = $value !== null ? (float) $value : 0.0; + $this->highestValue = $value !== null ? (float) $value : null; return $this; } diff --git a/tests/DTO/Forecast/DayTest.php b/tests/DTO/Forecast/DayTest.php index 126733e..e305b7e 100644 --- a/tests/DTO/Forecast/DayTest.php +++ b/tests/DTO/Forecast/DayTest.php @@ -88,7 +88,7 @@ public function testWind() : void // Assertions. $this->assertInstanceOf(Wind::class, $dto->getWind()); $this->assertIsFloat($dto->getWind()->getSpeed()->getValue()); - $this->assertEquals(2.784574942897006, $dto->getWind()->getSpeed()->getValue()); + $this->assertEquals(2.9302678, $dto->getWind()->getSpeed()->getValue()); $this->assertIsFloat($dto->getWind()->getSpeed()->getLowestValue()); $this->assertEquals(2.1742203, $dto->getWind()->getSpeed()->getLowestValue()); $this->assertIsFloat($dto->getWind()->getSpeed()->getHighestValue()); diff --git a/tests/DTO/Forecast/HourTest.php b/tests/DTO/Forecast/HourTest.php index 2be98fc..4ad37e6 100644 --- a/tests/DTO/Forecast/HourTest.php +++ b/tests/DTO/Forecast/HourTest.php @@ -88,7 +88,7 @@ public function testWind() : void // Assertions. $this->assertInstanceOf(Wind::class, $dto->getWind()); $this->assertIsFloat($dto->getWind()->getSpeed()->getValue()); - $this->assertEquals(2.784574942897006, $dto->getWind()->getSpeed()->getValue()); + $this->assertEquals(2.9302678, $dto->getWind()->getSpeed()->getValue()); $this->assertIsFloat($dto->getWind()->getSpeed()->getLowestValue()); $this->assertEquals(2.1742203, $dto->getWind()->getSpeed()->getLowestValue()); $this->assertIsFloat($dto->getWind()->getSpeed()->getHighestValue()); diff --git a/tests/DTO/Measurements/PrecipitationTest.php b/tests/DTO/Measurements/PrecipitationTest.php index 292a4e8..73ebb43 100644 --- a/tests/DTO/Measurements/PrecipitationTest.php +++ b/tests/DTO/Measurements/PrecipitationTest.php @@ -7,6 +7,7 @@ use Rugaard\DMI\DTO\Units\Length\Meter; use Rugaard\DMI\DTO\Units\Length\Millimeter; use Rugaard\DMI\Tests\AbstractTestCase; +use Tightenco\Collect\Support\Collection; /** * Class PrecipitationTest. @@ -15,6 +16,66 @@ */ class PrecipitationTest extends AbstractTestCase { + /** + * Test set/get type. + * + * @return void + */ + public function testType() : void + { + // Supported precipitation types. + $precipitationTypes = Collection::make(['rain', 'hail', 'sleet', 'snow']); + + $precipitationTypes->each(function ($precipitationType) { + // Instantiate empty DTO. + $dto = new Precipitation; + + // Set precipitation type. + $dto->setType($precipitationType); + + // Assertions. + $this->assertIsString($dto->getType()); + $this->assertEquals($precipitationType, $dto->getType()); + }); + } + + /** + * Test set/get type by danish key. + * + * @return void + */ + public function testTypeByDanishKey() : void + { + // Supported precipitation types. + $precipitationTypes = Collection::make([ + 'regn' => 'rain', + 'hagl' => 'hail', + 'slud' => 'sleet', + 'sne' => 'snow' + ]); + + $precipitationTypes->each(function ($precipitationType, $danishPrecipitationType) { + // Instantiate empty DTO. + $dto = new Precipitation; + + // Set precipitation type. + $dto->setTypeByDanishKey($danishPrecipitationType); + + // Assertions. + $this->assertIsString($dto->getType()); + $this->assertEquals($precipitationType, $dto->getType()); + }); + + // Test unsupported precipitation type. + $dto = new Precipitation; + + // Set unsupported precipitation type. + $dto->setTypeByDanishKey('glitter'); + + // Assertions. + $this->assertNull($dto->getType()); + } + /** * Test set/get value. * diff --git a/tests/DTO/Measurements/Wind/DirectionTest.php b/tests/DTO/Measurements/Wind/DirectionTest.php index 786f752..31e44e9 100644 --- a/tests/DTO/Measurements/Wind/DirectionTest.php +++ b/tests/DTO/Measurements/Wind/DirectionTest.php @@ -23,15 +23,15 @@ public function testDegreesAndDirection() : void { // Mocked test data. $mockedData = Collection::make([ - Collection::make(['value' => 338, 'expectedDirection' => 'Nord']), - Collection::make(['value' => 293, 'expectedDirection' => 'Nordvest']), - Collection::make(['value' => 248, 'expectedDirection' => 'Vest']), - Collection::make(['value' => 203, 'expectedDirection' => 'Sydvest']), - Collection::make(['value' => 158, 'expectedDirection' => 'Syd']), - Collection::make(['value' => 113, 'expectedDirection' => 'Sydøst']), - Collection::make(['value' => 68, 'expectedDirection' => 'Øst']), - Collection::make(['value' => 23, 'expectedDirection' => 'Nordøst']), - Collection::make(['value' => 0, 'expectedDirection' => 'Nord']), + Collection::make(['value' => 338, 'expectedDirection' => 'North']), + Collection::make(['value' => 293, 'expectedDirection' => 'Northwest']), + Collection::make(['value' => 248, 'expectedDirection' => 'West']), + Collection::make(['value' => 203, 'expectedDirection' => 'Southwest']), + Collection::make(['value' => 158, 'expectedDirection' => 'South']), + Collection::make(['value' => 113, 'expectedDirection' => 'Southeast']), + Collection::make(['value' => 68, 'expectedDirection' => 'East']), + Collection::make(['value' => 23, 'expectedDirection' => 'Northeast']), + Collection::make(['value' => 0, 'expectedDirection' => 'North']), ]); // Test each wind degree. @@ -47,13 +47,11 @@ public function testDegreesAndDirection() : void $this->assertEquals($data->get('value'), $dto->getDegrees()); $this->assertIsString($dto->getDirection()); $this->assertEquals($data->get('expectedDirection'), $dto->getDirection()); - }); // Test non-existing wind direction. $dto = (new Direction)->setDirectionByDegrees(-1); - $this->assertIsFloat($dto->getDegrees()); - $this->assertEquals(0.0, $dto->getDegrees()); + $this->assertNull($dto->getDegrees()); $this->assertNull($dto->getDirection()); } @@ -66,15 +64,15 @@ public function testDirectionByDegrees() : void { // Mocked test data. $mockedData = Collection::make([ - Collection::make(['value' => 338, 'expectedDirection' => 'Nord']), - Collection::make(['value' => 293, 'expectedDirection' => 'Nordvest']), - Collection::make(['value' => 248, 'expectedDirection' => 'Vest']), - Collection::make(['value' => 203, 'expectedDirection' => 'Sydvest']), - Collection::make(['value' => 158, 'expectedDirection' => 'Syd']), - Collection::make(['value' => 113, 'expectedDirection' => 'Sydøst']), - Collection::make(['value' => 68, 'expectedDirection' => 'Øst']), - Collection::make(['value' => 23, 'expectedDirection' => 'Nordøst']), - Collection::make(['value' => 0, 'expectedDirection' => 'Nord']), + Collection::make(['value' => 338, 'expectedDirection' => 'North']), + Collection::make(['value' => 293, 'expectedDirection' => 'Northwest']), + Collection::make(['value' => 248, 'expectedDirection' => 'West']), + Collection::make(['value' => 203, 'expectedDirection' => 'Southwest']), + Collection::make(['value' => 158, 'expectedDirection' => 'South']), + Collection::make(['value' => 113, 'expectedDirection' => 'Southeast']), + Collection::make(['value' => 68, 'expectedDirection' => 'East']), + Collection::make(['value' => 23, 'expectedDirection' => 'Northeast']), + Collection::make(['value' => 0, 'expectedDirection' => 'North']), ]); // Test each wind degree. @@ -105,22 +103,22 @@ public function testDirection() : void { // Mocked test data. $mockedData = Collection::make([ - Collection::make(['value' => 'N', 'expectedDirection' => 'Nord']), - Collection::make(['value' => 'S', 'expectedDirection' => 'Syd']), - Collection::make(['value' => 'Ø', 'expectedDirection' => 'Øst']), - Collection::make(['value' => 'V', 'expectedDirection' => 'Vest']), - Collection::make(['value' => 'NØ', 'expectedDirection' => 'Nordøst']), - Collection::make(['value' => 'NV', 'expectedDirection' => 'Nordvest']), - Collection::make(['value' => 'SØ', 'expectedDirection' => 'Sydøst']), - Collection::make(['value' => 'SV', 'expectedDirection' => 'Sydvest']), - Collection::make(['value' => 'NNØ', 'expectedDirection' => 'Nord-nordøst']), - Collection::make(['value' => 'NNV', 'expectedDirection' => 'Nord-nordvest']), - Collection::make(['value' => 'ØNØ', 'expectedDirection' => 'Øst-nordøst']), - Collection::make(['value' => 'ØSØ', 'expectedDirection' => 'Øst-sydøst']), - Collection::make(['value' => 'SSØ', 'expectedDirection' => 'Syd-sydøst']), - Collection::make(['value' => 'SSV', 'expectedDirection' => 'Syd-sydvest']), - Collection::make(['value' => 'VNV', 'expectedDirection' => 'Vest-nordvest']), - Collection::make(['value' => 'VSV', 'expectedDirection' => 'Vest-sydvest']), + Collection::make(['value' => 'N', 'expectedDirection' => 'North']), + Collection::make(['value' => 'S', 'expectedDirection' => 'South']), + Collection::make(['value' => 'E', 'expectedDirection' => 'East']), + Collection::make(['value' => 'W', 'expectedDirection' => 'West']), + Collection::make(['value' => 'NE', 'expectedDirection' => 'Northeast']), + Collection::make(['value' => 'NW', 'expectedDirection' => 'Northwest']), + Collection::make(['value' => 'SE', 'expectedDirection' => 'Southeast']), + Collection::make(['value' => 'SW', 'expectedDirection' => 'Southwest']), + Collection::make(['value' => 'NNE', 'expectedDirection' => 'North-northeast']), + Collection::make(['value' => 'NNW', 'expectedDirection' => 'North-northwest']), + Collection::make(['value' => 'ENE', 'expectedDirection' => 'East-northeast']), + Collection::make(['value' => 'ESE', 'expectedDirection' => 'East-southeast']), + Collection::make(['value' => 'SSE', 'expectedDirection' => 'South-southeast']), + Collection::make(['value' => 'SSW', 'expectedDirection' => 'South-southwest']), + Collection::make(['value' => 'WNW', 'expectedDirection' => 'West-northwest']), + Collection::make(['value' => 'WSW', 'expectedDirection' => 'West-southwest']), ]); // Test each wind direction. @@ -195,13 +193,13 @@ public function testToString() : void $dto = new Direction; // Mocked direction. - $mockedDirection = 'NØ'; + $mockedDirection = 'NE'; // Set direction. $dto->setDirection($mockedDirection); // Assertions. $this->assertIsString((string) $dto); - $this->assertEquals('Nordøst', (string) $dto); + $this->assertEquals('Northeast', (string) $dto); } } \ No newline at end of file diff --git a/tests/DTO/Measurements/WindTest.php b/tests/DTO/Measurements/WindTest.php index 86a03b0..b51e8bf 100644 --- a/tests/DTO/Measurements/WindTest.php +++ b/tests/DTO/Measurements/WindTest.php @@ -102,6 +102,6 @@ public function testToString() : void // Assertions. $this->assertIsString((string) $dto); - $this->assertEquals('2.8 m/s', (string) $dto); + $this->assertEquals('2.9 m/s', (string) $dto); } } \ No newline at end of file diff --git a/tests/Endpoints/LocationTest.php b/tests/Endpoints/LocationTest.php index aa2f591..33c89e8 100644 --- a/tests/Endpoints/LocationTest.php +++ b/tests/Endpoints/LocationTest.php @@ -264,7 +264,7 @@ public function testCurrentlyForecast() : void $this->assertInstanceOf(Wind::class, $currentForecast->getWind()); $this->assertInstanceOf(Speed::class, $currentForecast->getWind()->getSpeed()); $this->assertIsFloat($currentForecast->getWind()->getSpeed()->getValue()); - $this->assertEquals(2.784574942897006, $currentForecast->getWind()->getSpeed()->getValue()); + $this->assertEquals(2.9302678, $currentForecast->getWind()->getSpeed()->getValue()); $this->assertIsFloat($currentForecast->getWind()->getSpeed()->getLowestValue()); $this->assertEquals(2.1742203, $currentForecast->getWind()->getSpeed()->getLowestValue()); $this->assertIsFloat($currentForecast->getWind()->getSpeed()->getHighestValue()); @@ -272,14 +272,14 @@ public function testCurrentlyForecast() : void $this->assertInstanceOf(MetersPerSecond::class, $currentForecast->getWind()->getSpeed()->getUnit()); $this->assertEquals('Meters per second', $currentForecast->getWind()->getSpeed()->getUnit()->getName()); $this->assertEquals('m/s', $currentForecast->getWind()->getSpeed()->getUnit()->getAbbreviation()); - $this->assertEquals('2.8 m/s', (string) $currentForecast->getWind()->getSpeed()); - $this->assertEquals('2.8 m/s', (string) $currentForecast->getWind()); + $this->assertEquals('2.9 m/s', (string) $currentForecast->getWind()->getSpeed()); + $this->assertEquals('2.9 m/s', (string) $currentForecast->getWind()); $this->assertInstanceOf(Direction::class, $currentForecast->getWind()->getDirection()); - $this->assertEquals('Syd', $currentForecast->getWind()->getDirection()->getDirection()); + $this->assertEquals('South', $currentForecast->getWind()->getDirection()->getDirection()); $this->assertEquals('S', $currentForecast->getWind()->getDirection()->getAbbreviation()); $this->assertIsFloat($currentForecast->getWind()->getDirection()->getDegrees()); $this->assertEquals(195.00374211733555, $currentForecast->getWind()->getDirection()->getDegrees()); - $this->assertEquals('Syd', (string) $currentForecast->getWind()->getDirection()); + $this->assertEquals('South', (string) $currentForecast->getWind()->getDirection()); $this->assertInstanceOf(Gust::class, $currentForecast->getWind()->getGust()); $this->assertEquals(7.736926, $currentForecast->getWind()->getGust()->getValue()); $this->assertInstanceOf(MetersPerSecond::class, $currentForecast->getWind()->getGust()->getUnit()); @@ -307,7 +307,7 @@ public function testCurrentlyForecast() : void // Precipitation. $this->assertInstanceOf(Precipitation::class, $currentForecast->getPrecipitation()); - $this->assertEquals('regn', $currentForecast->getPrecipitation()->getType()); + $this->assertEquals('rain', $currentForecast->getPrecipitation()->getType()); $this->assertIsFloat($currentForecast->getPrecipitation()->getValue()); $this->assertEquals(0.0, $currentForecast->getPrecipitation()->getValue()); $this->assertIsFloat($currentForecast->getPrecipitation()->getLowestValue()); @@ -375,7 +375,7 @@ public function testHourlyForecast() : void $this->assertInstanceOf(Wind::class, $hour->getWind()); $this->assertInstanceOf(Speed::class, $hour->getWind()->getSpeed()); $this->assertIsFloat($hour->getWind()->getSpeed()->getValue()); - $this->assertEquals(2.784574942897006, $hour->getWind()->getSpeed()->getValue()); + $this->assertEquals(2.9302678, $hour->getWind()->getSpeed()->getValue()); $this->assertIsFloat($hour->getWind()->getSpeed()->getLowestValue()); $this->assertEquals(2.1742203, $hour->getWind()->getSpeed()->getLowestValue()); $this->assertIsFloat($hour->getWind()->getSpeed()->getHighestValue()); @@ -383,14 +383,14 @@ public function testHourlyForecast() : void $this->assertInstanceOf(MetersPerSecond::class, $hour->getWind()->getSpeed()->getUnit()); $this->assertEquals('Meters per second', $hour->getWind()->getSpeed()->getUnit()->getName()); $this->assertEquals('m/s', $hour->getWind()->getSpeed()->getUnit()->getAbbreviation()); - $this->assertEquals('2.8 m/s', (string) $hour->getWind()->getSpeed()); - $this->assertEquals('2.8 m/s', (string) $hour->getWind()); + $this->assertEquals('2.9 m/s', (string) $hour->getWind()->getSpeed()); + $this->assertEquals('2.9 m/s', (string) $hour->getWind()); $this->assertInstanceOf(Direction::class, $hour->getWind()->getDirection()); - $this->assertEquals('Syd', $hour->getWind()->getDirection()->getDirection()); + $this->assertEquals('South', $hour->getWind()->getDirection()->getDirection()); $this->assertEquals('S', $hour->getWind()->getDirection()->getAbbreviation()); $this->assertIsFloat($hour->getWind()->getDirection()->getDegrees()); $this->assertEquals(195.00374211733555, $hour->getWind()->getDirection()->getDegrees()); - $this->assertEquals('Syd', (string) $hour->getWind()->getDirection()); + $this->assertEquals('South', (string) $hour->getWind()->getDirection()); $this->assertInstanceOf(Gust::class, $hour->getWind()->getGust()); $this->assertEquals(7.736926, $hour->getWind()->getGust()->getValue()); $this->assertInstanceOf(MetersPerSecond::class, $hour->getWind()->getGust()->getUnit()); @@ -418,7 +418,7 @@ public function testHourlyForecast() : void // Precipitation. $this->assertInstanceOf(Precipitation::class, $hour->getPrecipitation()); - $this->assertEquals('regn', $hour->getPrecipitation()->getType()); + $this->assertEquals('rain', $hour->getPrecipitation()->getType()); $this->assertIsFloat($hour->getPrecipitation()->getValue()); $this->assertEquals(0.0, $hour->getPrecipitation()->getValue()); $this->assertIsFloat($hour->getPrecipitation()->getLowestValue()); @@ -486,7 +486,7 @@ public function testDailyForecast() : void $this->assertInstanceOf(Wind::class, $day->getWind()); $this->assertInstanceOf(Speed::class, $day->getWind()->getSpeed()); $this->assertIsFloat($day->getWind()->getSpeed()->getValue()); - $this->assertEquals(4.7881474947600156, $day->getWind()->getSpeed()->getValue()); + $this->assertEquals(4.847289206666667, $day->getWind()->getSpeed()->getValue()); $this->assertIsFloat($day->getWind()->getSpeed()->getLowestValue()); $this->assertEquals(4.04755224, $day->getWind()->getSpeed()->getLowestValue()); $this->assertIsFloat($day->getWind()->getSpeed()->getHighestValue()); @@ -497,11 +497,11 @@ public function testDailyForecast() : void $this->assertEquals('4.8 m/s', (string) $day->getWind()->getSpeed()); $this->assertEquals('4.8 m/s', (string) $day->getWind()); $this->assertInstanceOf(Direction::class, $day->getWind()->getDirection()); - $this->assertEquals('Sydvest', $day->getWind()->getDirection()->getDirection()); - $this->assertEquals('SV', $day->getWind()->getDirection()->getAbbreviation()); + $this->assertEquals('Southwest', $day->getWind()->getDirection()->getDirection()); + $this->assertEquals('SW', $day->getWind()->getDirection()->getAbbreviation()); $this->assertIsFloat($day->getWind()->getDirection()->getDegrees()); $this->assertEquals(245.45667629457967, $day->getWind()->getDirection()->getDegrees()); - $this->assertEquals('Sydvest', (string) $day->getWind()->getDirection()); + $this->assertEquals('Southwest', (string) $day->getWind()->getDirection()); $this->assertInstanceOf(Gust::class, $day->getWind()->getGust()); $this->assertEquals(11.177295293333334, $day->getWind()->getGust()->getValue()); $this->assertInstanceOf(MetersPerSecond::class, $day->getWind()->getGust()->getUnit()); @@ -529,7 +529,7 @@ public function testDailyForecast() : void // Precipitation. $this->assertInstanceOf(Precipitation::class, $day->getPrecipitation()); - $this->assertEquals('regn', $day->getPrecipitation()->getType()); + $this->assertEquals('rain', $day->getPrecipitation()->getType()); $this->assertIsFloat($day->getPrecipitation()->getValue()); $this->assertEquals(0.0, $day->getPrecipitation()->getValue()); $this->assertIsFloat($day->getPrecipitation()->getLowestValue());