* 391 Notification refactorings (#441) * Refactor notifications to allow easier plugins * Notification refactoring * Formatting * Move news to NewsService; cleanup of events * More refactoring; added send email out for news item and the template * Formatting * Formatting * Fix missing newsRepo (#445) * Refactor and add importer to Installer module #443 (#444) * Refactor and add importer to Installer module #443 * Refactor for finances to use in import * Import groups into roles * Formatting * Formatting * Add interface in installer for import * Notes about importing * Check for installer folder * Formatting * Fix pirep->user mapping * Unused import * Formatting * Replace importer with AJAX powered; better error handling #443 (#447) * Replace importer with AJAX powered; better error handling #443 * Formatting * Fix command line importer * Remove bootstrap cache (#448) * Cleanup the bootstrap/cache directory when packaging * Fix removal of bootstrap cache * Formatting * Stricter checks on ACARS API data (#451) * Stricter checks on ACARS API data * More checks * Fix for flight_number check forcing to exist * Allow nullable on flight_id * Avoid proc_open use #455 (#456) * Use PhpExecutableFinder() closes #457 #458 (#460) * Use DateTimeZone instead of int for creating datetime closes #461 * Fix CSV imports giving Storage class not found #454 (#462) * Fix CSV imports giving Storage class not found #454 * Update yarn files for security alert * Add PHP 7.4 support (#464) * Add PHP 7.4 to build matrix * DB fix * YAML parser fix in test data * Show versions * Package updates * Track used ICAOs * 7.4 METAR parsing fix * METAR parser fix * Formatting * Add meters to response units * Call instance for unit conversion * Return value * Catch exception for unknown quantity * Comment fix * Formatting * METAR parsing fixes on PHP 7.4 * Package updates * More random airport ID * More random airport ID * Properly disable toolbar * Semver written out to version file * Use dev as default identifier * Fix BindingResolutionError when debug toolbar isn't present (#465) * Fix BindingResolutionError when debug toolbar isn't present * Formatting * Split the importer module out from the installer module (#468) * Split the importer module out from the installer module * Cleanup of unused imports * Move updater into separate module #453 * Remove unused imports/formatting * Disable the install and importer modules at the end of the setup * Unused imports; update IJ style * test explicit stage for php+mysql * add more to matrix * Add different MariaDB versions * undo * Cleanup Model doc * Pilots cannot use the dashboard or flights without admin rights (#481) * Use auth middleware instead of specific groups for logged in state * Auth check for admin access * Check user admin access for updates * Formatting * Allow nullable field and calculate distance if nulled for flight import #478 (#482) * Check for no roles being attached #480 (#483) * Return the flight fares if there are no subfleet fares #488 (#489) * Return the flight fares if there are no subfleet fares #488 * Formatting * Formatting * Account for units when entering fuel amounts #493 * Search for ICAO not working properly (#496) * /flights and /flights/search direct to the same endpoint * Properly set the distance/planned_distance on save (#497) * 491 Installation Error (#495) * Disable CSRF token * Add error handling around looking up the theme and set a default * Note about logs in issue template * Formatting * Fix GeoService errors when viewing PIREP #498 (#499) * Add new command to export a specific PIREP for debugging (#501) * Set a default model value for airports on PIREP (#500) * Set a default model value for airports on PIREP * Fix airport icao reference * Default airport models * Catch broader exception writing out config files #491 * style * Add reference to docs on doc site (#502) * Properly create/update rows importing #486 (#503) * Add base Dockerfile for Dockerhub builds (#504) * New subfleet not being attached to an airline on import #479 (#505) * Fix subfleet not being attached to an airline on creation in import #479 * Call airline name with optional() around subfleet * Minor cleanup * Search flights by subfleet #484 (#506) * API level search of flights #484 * Add Subfleet to flights page for search * Make the fuel used optional (#512) * Add make to Docker container * Add getRootDomain() to Utils (#514) * Show admin dropdown for admin-access ability (#515) * Show admin dropdown for admin-access ability closes #509 * Formatting * Check user permissions on the routes #508 (#516) * Check user permissions on the routes #508 * Formatting * Return default value on exception for setting() * Correct text for no subfleets #507 (#518) * Add a public_url() helper #513 (#519) * Reduce number of queries for update check (#520) * Try to clear caches before updating (#522) * Try to clear caches before updating * Add clear-compiled to maintenance cache list * Formatting * Set PIREPs page to public (#526) Set PIREPs page to public * Fix live and route map errors #527 (#528) * Add menu bar for mobile (#529) * Format all blade templates to 2 spaces #530 (#531) * Fix PIREP edit endpoint closes #533 (#534) * Fix import during flight cron #532 (#535) * PIREPS resource except for show (#536) * Use optional() around the airport fields (#537) * Use optional() around the airport fields * Add null-coalesce around full_name * Add link to download ACARS config from profile (#539) * Add link to download ACARS config from profile * Formatting * Update xml config file template (#540)
189 lines
6.5 KiB
PHP
189 lines
6.5 KiB
PHP
<?php
|
|
|
|
use App\Repositories\SettingRepository;
|
|
use App\Services\AirportService;
|
|
use App\Support\Metar;
|
|
use GuzzleHttp\Client;
|
|
use GuzzleHttp\Handler\MockHandler;
|
|
use GuzzleHttp\HandlerStack;
|
|
use GuzzleHttp\Psr7\Response;
|
|
|
|
/**
|
|
* Test the parsing/support class of the metar
|
|
*/
|
|
class MetarTest extends TestCase
|
|
{
|
|
private $settingsRepo;
|
|
|
|
public function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
$this->settingsRepo = app(SettingRepository::class);
|
|
}
|
|
|
|
/**
|
|
* @param string $filename
|
|
*/
|
|
private function mockXmlResponse($filename)
|
|
{
|
|
$mock = new MockHandler([
|
|
new Response(200,
|
|
[
|
|
'Content-Type' => 'text/xml',
|
|
],
|
|
$this->readDataFile($filename)
|
|
),
|
|
]);
|
|
|
|
$handler = HandlerStack::create($mock);
|
|
$guzzleClient = new Client(['handler' => $handler]);
|
|
app()->instance(Client::class, $guzzleClient);
|
|
}
|
|
|
|
/**
|
|
* Make sure a blank metar doesn't give problems
|
|
*/
|
|
public function testBlankMetar()
|
|
{
|
|
$metar = '';
|
|
$parsed = Metar::parse($metar);
|
|
$this->assertEquals('', $parsed['raw']);
|
|
}
|
|
|
|
/**
|
|
* Test adding/subtracting a percentage
|
|
*/
|
|
public function testMetar1()
|
|
{
|
|
$metar =
|
|
'KJFK 042151Z 28026G39KT 10SM FEW055 SCT095 BKN110 BKN230 12/M04 A2958 RMK AO2 PK WND 27045/2128 PRESRR SLP018 T01221044';
|
|
|
|
//$m = new Metar($metar);
|
|
//$parsed = $m->result;
|
|
$parsed = Metar::parse($metar);
|
|
|
|
/*
|
|
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
|
|
*/
|
|
$this->assertEquals('KJFK', $parsed['station']);
|
|
$this->assertEquals(4, $parsed['observed_day']);
|
|
$this->assertEquals('21:51 UTC', $parsed['observed_time']);
|
|
$this->assertEquals(26, $parsed['wind_speed']['knots']);
|
|
$this->assertEquals(39, $parsed['wind_gust_speed']['knots']);
|
|
$this->assertEquals(280, $parsed['wind_direction']);
|
|
$this->assertEquals('W', $parsed['wind_direction_label']);
|
|
$this->assertEquals(false, $parsed['wind_direction_varies']);
|
|
$this->assertEquals(16093.44, $parsed['visibility']['m']);
|
|
$this->assertEquals('Dry', $parsed['present_weather_report']);
|
|
|
|
$this->assertCount(4, $parsed['clouds']);
|
|
$this->assertEquals(
|
|
'A few at 1676 meters; scattered at 2896 meters; broken sky at 3353 meters; broken sky at 7010 meters',
|
|
$parsed['clouds_report']);
|
|
$this->assertEquals(1676.4, $parsed['cloud_height']['m']);
|
|
$this->assertEquals(false, $parsed['cavok']);
|
|
|
|
$this->assertEquals(12, $parsed['temperature']['c']);
|
|
$this->assertEquals(53.6, $parsed['temperature']['f']);
|
|
|
|
$this->assertEquals(-4, $parsed['dew_point']['c']);
|
|
$this->assertEquals(24.8, $parsed['dew_point']['f']);
|
|
|
|
$this->assertEquals(33, $parsed['humidity']);
|
|
$this->assertEquals(29.58, $parsed['barometer']['hPa']);
|
|
|
|
$this->assertEquals('AO2 PK WND 27045/2128 PRESRR SLP018 T01221044', $parsed['remarks']);
|
|
}
|
|
|
|
public function testMetar2()
|
|
{
|
|
$metar = 'EGLL 261250Z AUTO 17014KT 8000 -RA BKN010/// '
|
|
.'BKN016/// OVC040/// //////TCU 13/12 Q1008 TEMPO 4000 RA';
|
|
|
|
$parsed = Metar::parse($metar);
|
|
|
|
$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']);
|
|
$this->assertNull($parsed['clouds'][3]['height']);
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
public function testMetarTrends()
|
|
{
|
|
$metar =
|
|
'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);
|
|
}
|
|
|
|
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']);
|
|
$this->assertEquals(18, $parsed['wind_speed']['knots']);
|
|
$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']);
|
|
}
|
|
|
|
public function testMetar4Clouds()
|
|
{
|
|
$metar = 'KAUS 171153Z 18006KT 9SM FEW015 FEW250 26/24 A3003 RMK AO2 SLP156 T02560244 10267 20239 $';
|
|
$metar = Metar::parse($metar);
|
|
|
|
$this->assertEquals(2, count($metar['clouds']));
|
|
$this->assertEquals('A few at 457 meters; a few at 7620 meters', $metar['clouds_report']);
|
|
$this->assertEquals('A few at 1500 feet; a few at 25000 feet', $metar['clouds_report_ft']);
|
|
}
|
|
|
|
public function testHttpCallSuccess()
|
|
{
|
|
$this->mockXmlResponse('aviationweather/kjfk.xml');
|
|
$airportSvc = app(AirportService::class);
|
|
|
|
$this->assertInstanceOf(Metar::class, $airportSvc->getMetar('kjfk'));
|
|
}
|
|
|
|
public function testHttpCallEmpty()
|
|
{
|
|
$this->mockXmlResponse('aviationweather/empty.xml');
|
|
$airportSvc = app(AirportService::class);
|
|
|
|
$this->assertNull($airportSvc->getMetar('idk'));
|
|
}
|
|
}
|