2018-04-05 06:14:46 +08:00
|
|
|
<?php
|
|
|
|
|
2020-05-23 23:43:29 +08:00
|
|
|
namespace Tests;
|
|
|
|
|
2018-04-05 09:59:52 +08:00
|
|
|
use App\Repositories\SettingRepository;
|
2019-08-09 05:41:53 +08:00
|
|
|
use App\Services\AirportService;
|
2018-04-05 09:59:52 +08:00
|
|
|
use App\Support\Metar;
|
2018-04-05 06:14:46 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test the parsing/support class of the metar
|
|
|
|
*/
|
|
|
|
class MetarTest extends TestCase
|
|
|
|
{
|
2020-05-23 23:43:29 +08:00
|
|
|
/** @var SettingRepository */
|
2018-04-05 09:59:52 +08:00
|
|
|
private $settingsRepo;
|
|
|
|
|
2019-05-12 23:50:38 +08:00
|
|
|
public function setUp(): void
|
2018-04-05 09:59:52 +08:00
|
|
|
{
|
2019-05-12 23:50:38 +08:00
|
|
|
parent::setUp();
|
2018-04-05 09:59:52 +08:00
|
|
|
$this->settingsRepo = app(SettingRepository::class);
|
|
|
|
}
|
|
|
|
|
2018-05-15 00:20:38 +08:00
|
|
|
/**
|
|
|
|
* Make sure a blank metar doesn't give problems
|
|
|
|
*/
|
|
|
|
public function testBlankMetar()
|
|
|
|
{
|
|
|
|
$metar = '';
|
|
|
|
$parsed = Metar::parse($metar);
|
|
|
|
$this->assertEquals('', $parsed['raw']);
|
|
|
|
}
|
|
|
|
|
2018-04-05 06:14:46 +08:00
|
|
|
/**
|
|
|
|
* Test adding/subtracting a percentage
|
|
|
|
*/
|
|
|
|
public function testMetar1()
|
|
|
|
{
|
|
|
|
$metar =
|
2018-04-05 09:59:52 +08:00
|
|
|
'KJFK 042151Z 28026G39KT 10SM FEW055 SCT095 BKN110 BKN230 12/M04 A2958 RMK AO2 PK WND 27045/2128 PRESRR SLP018 T01221044';
|
2018-04-05 06:14:46 +08:00
|
|
|
|
2018-08-27 00:40:04 +08:00
|
|
|
//$m = new Metar($metar);
|
|
|
|
//$parsed = $m->result;
|
2018-04-05 09:59:52 +08:00
|
|
|
$parsed = Metar::parse($metar);
|
2018-04-05 06:14:46 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
Conditions VFR visibility 10NM
|
|
|
|
Barometer 1001.58 Hg / 29.58 MB
|
|
|
|
Clouds FEW @ 5500 ft
|
|
|
|
SCT @ 9500 ft
|
|
|
|
BKN @ 11000 ft
|
|
|
|
BKN @ 23000 ft
|
|
|
|
Wind 26 kts @ 280° gusts to 39
|
|
|
|
*/
|
2018-04-05 09:59:52 +08:00
|
|
|
$this->assertEquals('KJFK', $parsed['station']);
|
|
|
|
$this->assertEquals(4, $parsed['observed_day']);
|
|
|
|
$this->assertEquals('21:51 UTC', $parsed['observed_time']);
|
2019-07-16 03:14:40 +08:00
|
|
|
$this->assertEquals(26, $parsed['wind_speed']['knots']);
|
|
|
|
$this->assertEquals(39, $parsed['wind_gust_speed']['knots']);
|
2018-04-05 09:59:52 +08:00
|
|
|
$this->assertEquals(280, $parsed['wind_direction']);
|
|
|
|
$this->assertEquals('W', $parsed['wind_direction_label']);
|
|
|
|
$this->assertEquals(false, $parsed['wind_direction_varies']);
|
2018-04-08 09:52:12 +08:00
|
|
|
$this->assertEquals(16093.44, $parsed['visibility']['m']);
|
2018-04-05 09:59:52 +08:00
|
|
|
$this->assertEquals('Dry', $parsed['present_weather_report']);
|
|
|
|
|
|
|
|
$this->assertCount(4, $parsed['clouds']);
|
|
|
|
$this->assertEquals(
|
2020-12-05 01:47:42 +08:00
|
|
|
'Few at 1676 meters; scattered at 2896 meters; broken sky at 3353 meters; broken sky at 7010 meters',
|
2020-03-06 09:19:12 +08:00
|
|
|
$parsed['clouds_report']
|
|
|
|
);
|
2018-04-08 09:52:12 +08:00
|
|
|
$this->assertEquals(1676.4, $parsed['cloud_height']['m']);
|
2018-04-05 09:59:52 +08:00
|
|
|
$this->assertEquals(false, $parsed['cavok']);
|
|
|
|
|
2018-04-08 09:52:12 +08:00
|
|
|
$this->assertEquals(12, $parsed['temperature']['c']);
|
|
|
|
$this->assertEquals(53.6, $parsed['temperature']['f']);
|
2018-04-05 09:59:52 +08:00
|
|
|
|
2018-04-08 09:52:12 +08:00
|
|
|
$this->assertEquals(-4, $parsed['dew_point']['c']);
|
|
|
|
$this->assertEquals(24.8, $parsed['dew_point']['f']);
|
2018-04-05 09:59:52 +08:00
|
|
|
|
|
|
|
$this->assertEquals(33, $parsed['humidity']);
|
2020-12-21 23:53:50 +08:00
|
|
|
$this->assertEquals(29.58, $parsed['barometer']['inHg']);
|
2018-04-05 09:59:52 +08:00
|
|
|
|
|
|
|
$this->assertEquals('AO2 PK WND 27045/2128 PRESRR SLP018 T01221044', $parsed['remarks']);
|
2018-04-05 06:14:46 +08:00
|
|
|
}
|
|
|
|
|
2018-08-27 01:25:51 +08:00
|
|
|
public function testMetar2()
|
|
|
|
{
|
|
|
|
$metar = 'EGLL 261250Z AUTO 17014KT 8000 -RA BKN010/// '
|
|
|
|
.'BKN016/// OVC040/// //////TCU 13/12 Q1008 TEMPO 4000 RA';
|
2018-08-29 07:27:53 +08:00
|
|
|
|
|
|
|
$parsed = Metar::parse($metar);
|
2018-08-29 07:58:57 +08:00
|
|
|
|
|
|
|
$this->assertCount(4, $parsed['clouds']);
|
|
|
|
$this->assertEquals(1000, $parsed['clouds'][0]['height']['ft']);
|
|
|
|
$this->assertEquals(1600, $parsed['clouds'][1]['height']['ft']);
|
|
|
|
$this->assertEquals(4000, $parsed['clouds'][2]['height']['ft']);
|
2019-12-12 01:57:18 +08:00
|
|
|
$this->assertNull($parsed['clouds'][3]['height']);
|
2018-08-27 01:25:51 +08:00
|
|
|
}
|
|
|
|
|
2018-09-02 04:58:38 +08:00
|
|
|
public function testMetar3()
|
|
|
|
{
|
|
|
|
$metar = 'LEBL 310337Z 24006G18KT 210V320 1000 '
|
|
|
|
.'R25R/P2000 R07L/1900N R07R/1700D R25L/1900N '
|
|
|
|
.'+TSRA SCT006 BKN015 SCT030CB 22/21 Q1018 NOSIG';
|
|
|
|
|
|
|
|
$parsed = Metar::parse($metar);
|
|
|
|
}
|
|
|
|
|
2018-04-16 03:14:40 +08:00
|
|
|
public function testMetarTrends()
|
2018-04-05 06:14:46 +08:00
|
|
|
{
|
|
|
|
$metar =
|
2018-04-07 22:05:06 +08:00
|
|
|
'KJFK 070151Z 20005KT 10SM BKN100 08/07 A2970 RMK AO2 SLP056 T00780067';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* John F.Kennedy International, New York, NY (KJFK). Apr 7, 0151Z. Wind from 200° at 5 knots,
|
|
|
|
* 10 statute miles visibility, Ceiling is Broken at 10,000 feet, Temperature 8°C, Dewpoint 7°C,
|
|
|
|
* Altimeter is 29.70. Remarks: automated station with precipitation discriminator sea level
|
|
|
|
* pressure 1005.6 hectopascals hourly temp 7.8°C dewpoint 6.7°C
|
|
|
|
*/
|
|
|
|
$parsed = Metar::parse($metar);
|
2018-04-05 06:14:46 +08:00
|
|
|
}
|
2018-04-16 03:14:40 +08:00
|
|
|
|
|
|
|
public function testMetarTrends2()
|
|
|
|
{
|
|
|
|
$metar = 'KAUS 092135Z 26018G25KT 8SM -TSRA BR SCT045CB BKN060 OVC080 30/21 A2992 RMK FQT LTGICCCCG OHD-W MOVG E RAB25 TSB32 CB ALQDS SLP132 P0035 T03020210 =';
|
|
|
|
$parsed = Metar::parse($metar);
|
|
|
|
|
|
|
|
$this->assertEquals('VFR', $parsed['category']);
|
2019-07-16 03:14:40 +08:00
|
|
|
$this->assertEquals(18, $parsed['wind_speed']['knots']);
|
2018-04-16 03:14:40 +08:00
|
|
|
$this->assertEquals(8, $parsed['visibility']['mi']);
|
|
|
|
$this->assertEquals(
|
|
|
|
'Scattered at 4500 feet, cumulonimbus; broken sky at 6000 feet; overcast sky at 8000 feet',
|
|
|
|
$parsed['clouds_report_ft']
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testMetarTrends3()
|
|
|
|
{
|
|
|
|
$metar = 'EHAM 041455Z 13012KT 9999 FEW034CB BKN040 05/01 Q1007 TEMPO 14017G28K 4000 SHRA =';
|
|
|
|
$metar = Metar::parse($metar);
|
|
|
|
|
|
|
|
$this->assertEquals('VFR', $metar['category']);
|
|
|
|
}
|
2019-07-17 20:57:45 +08:00
|
|
|
|
|
|
|
public function testMetar4Clouds()
|
|
|
|
{
|
|
|
|
$metar = 'KAUS 171153Z 18006KT 9SM FEW015 FEW250 26/24 A3003 RMK AO2 SLP156 T02560244 10267 20239 $';
|
|
|
|
$metar = Metar::parse($metar);
|
|
|
|
|
2019-07-17 21:56:16 +08:00
|
|
|
$this->assertEquals(2, count($metar['clouds']));
|
2020-12-05 01:47:42 +08:00
|
|
|
$this->assertEquals('Few at 457 meters; few at 7620 meters', $metar['clouds_report']);
|
|
|
|
$this->assertEquals('Few at 1500 feet; few at 25000 feet', $metar['clouds_report_ft']);
|
2019-07-17 20:57:45 +08:00
|
|
|
}
|
2019-08-09 05:41:53 +08:00
|
|
|
|
2020-05-03 23:06:49 +08:00
|
|
|
/**
|
|
|
|
* Visibility in KM not parsed
|
|
|
|
*
|
|
|
|
* https://github.com/nabeelio/phpvms/issues/680
|
|
|
|
*/
|
|
|
|
public function testMetar5()
|
|
|
|
{
|
|
|
|
$metar = 'NZOH 031300Z 04004KT 38KM SCT075 BKN090 15/14 Q1002 RMK AUTO NZPM VATSIM USE ONL';
|
|
|
|
$metar = Metar::parse($metar);
|
|
|
|
|
|
|
|
$this->assertEquals(38, $metar['visibility']['km']);
|
|
|
|
$this->assertEquals('38 km', $metar['visibility_report']);
|
|
|
|
}
|
|
|
|
|
2019-08-09 05:41:53 +08:00
|
|
|
public function testHttpCallSuccess()
|
|
|
|
{
|
|
|
|
$this->mockXmlResponse('aviationweather/kjfk.xml');
|
2021-02-20 01:45:39 +08:00
|
|
|
|
|
|
|
/** @var AirportService $airportSvc */
|
2019-08-09 05:41:53 +08:00
|
|
|
$airportSvc = app(AirportService::class);
|
|
|
|
|
|
|
|
$this->assertInstanceOf(Metar::class, $airportSvc->getMetar('kjfk'));
|
|
|
|
}
|
|
|
|
|
2020-10-11 02:55:12 +08:00
|
|
|
/**
|
|
|
|
* TEMPO and trend causing issue with values being overwritten
|
|
|
|
* https://github.com/nabeelio/phpvms/issues/861
|
|
|
|
*/
|
|
|
|
public function testLFRSCall()
|
|
|
|
{
|
|
|
|
$this->mockXmlResponse('aviationweather/lfrs.xml');
|
|
|
|
|
|
|
|
/** @var AirportService $airportSvc */
|
|
|
|
$airportSvc = app(AirportService::class);
|
|
|
|
|
|
|
|
$metar = $airportSvc->getMetar('lfrs');
|
|
|
|
$this->assertInstanceOf(Metar::class, $metar);
|
|
|
|
$this->assertTrue($metar['cavok']);
|
|
|
|
}
|
|
|
|
|
2020-06-04 18:30:35 +08:00
|
|
|
public function testHttpCallSuccessFullResponse()
|
|
|
|
{
|
|
|
|
$this->mockXmlResponse('aviationweather/kphx.xml');
|
|
|
|
$airportSvc = app(AirportService::class);
|
|
|
|
|
|
|
|
$this->assertInstanceOf(Metar::class, $airportSvc->getMetar('kphx'));
|
|
|
|
}
|
|
|
|
|
2019-08-09 05:41:53 +08:00
|
|
|
public function testHttpCallEmpty()
|
|
|
|
{
|
|
|
|
$this->mockXmlResponse('aviationweather/empty.xml');
|
|
|
|
$airportSvc = app(AirportService::class);
|
|
|
|
|
|
|
|
$this->assertNull($airportSvc->getMetar('idk'));
|
|
|
|
}
|
2020-02-29 11:50:41 +08:00
|
|
|
|
|
|
|
public function testHttpCallUnknown()
|
|
|
|
{
|
|
|
|
$this->mockXmlResponse('aviationweather/unknown.xml');
|
|
|
|
|
|
|
|
/** @var AirportService $airportSvc */
|
|
|
|
$airportSvc = app(AirportService::class);
|
|
|
|
|
|
|
|
$metar = $airportSvc->getMetar('7AK4');
|
|
|
|
$this->assertNull($metar);
|
|
|
|
}
|
2018-04-05 06:14:46 +08:00
|
|
|
}
|