Fix/metar reading (#354)
* Account for empty ICAO; added tests * Fix null returns * Fix typo in volume units display * Add version field for bug report template * Some more changes to the bug report template
This commit is contained in:
parent
5cafebe4d6
commit
47be7507f0
10
.github/ISSUE_TEMPLATE/bug_report.md
vendored
10
.github/ISSUE_TEMPLATE/bug_report.md
vendored
@ -10,6 +10,9 @@ assignees: ''
|
|||||||
**Describe the bug**
|
**Describe the bug**
|
||||||
A clear and concise description of what the bug is.
|
A clear and concise description of what the bug is.
|
||||||
|
|
||||||
|
**Version**
|
||||||
|
Please enter the version
|
||||||
|
|
||||||
**To Reproduce**
|
**To Reproduce**
|
||||||
Steps to reproduce the behavior:
|
Steps to reproduce the behavior:
|
||||||
1. Go to '...'
|
1. Go to '...'
|
||||||
@ -23,10 +26,5 @@ A clear and concise description of what you expected to happen.
|
|||||||
**Screenshots**
|
**Screenshots**
|
||||||
If applicable, add screenshots to help explain your problem.
|
If applicable, add screenshots to help explain your problem.
|
||||||
|
|
||||||
**Desktop (please complete the following information):**
|
|
||||||
- OS: [e.g. iOS]
|
|
||||||
- Browser [e.g. chrome, safari]
|
|
||||||
- Version [e.g. 22]
|
|
||||||
|
|
||||||
**Additional context**
|
**Additional context**
|
||||||
Add any other context about the problem here.
|
Add any other context and attach logs (from `storage/logs/laravel-<date>.log`)
|
||||||
|
@ -60,7 +60,7 @@
|
|||||||
value: gallons
|
value: gallons
|
||||||
options: 'gallons,l=liters'
|
options: 'gallons,l=liters'
|
||||||
type: select
|
type: select
|
||||||
description: 'The units for fuel for display'
|
description: 'The units of volume for display'
|
||||||
- key: units.temperature
|
- key: units.temperature
|
||||||
name: 'Temperature Units'
|
name: 'Temperature Units'
|
||||||
group: units
|
group: units
|
||||||
|
@ -26,16 +26,16 @@ class AirportService extends Service
|
|||||||
*
|
*
|
||||||
* @return Metar|null
|
* @return Metar|null
|
||||||
*/
|
*/
|
||||||
public function getMetar($icao): Metar
|
public function getMetar($icao)
|
||||||
{
|
{
|
||||||
$metar = null;
|
$icao = trim($icao);
|
||||||
$wind = null;
|
if ($icao === '') {
|
||||||
$raw_metar = $this->metarProvider->get_metar($icao);
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$raw_metar = $this->metarProvider->get_metar($icao);
|
||||||
if ($raw_metar && $raw_metar !== '') {
|
if ($raw_metar && $raw_metar !== '') {
|
||||||
return new Metar($raw_metar);
|
return new Metar($raw_metar);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,10 @@ class AviationWeather extends Metar
|
|||||||
*/
|
*/
|
||||||
protected function metar($icao): string
|
protected function metar($icao): string
|
||||||
{
|
{
|
||||||
|
if ($icao === '') {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
$url = static::METAR_URL.$icao;
|
$url = static::METAR_URL.$icao;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -1,7 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use App\Repositories\SettingRepository;
|
use App\Repositories\SettingRepository;
|
||||||
|
use App\Services\AirportService;
|
||||||
use App\Support\Metar;
|
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
|
* Test the parsing/support class of the metar
|
||||||
@ -16,6 +21,25 @@ class MetarTest extends TestCase
|
|||||||
$this->settingsRepo = app(SettingRepository::class);
|
$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
|
* Make sure a blank metar doesn't give problems
|
||||||
*/
|
*/
|
||||||
@ -145,4 +169,20 @@ class MetarTest extends TestCase
|
|||||||
$this->assertEquals('A few at 457 meters; a few at 7620 meters', $metar['clouds_report']);
|
$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']);
|
$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'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
13
tests/data/aviationweather/empty.xml
Normal file
13
tests/data/aviationweather/empty.xml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<response xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XML-Schema-instance" version="1.2"
|
||||||
|
xsi:noNamespaceSchemaLocation="http://aviationweather.gov/adds/schema/metar1_2.xsd">
|
||||||
|
<request_index>26064774</request_index>
|
||||||
|
<data_source name="metars"/>
|
||||||
|
<request type="retrieve"/>
|
||||||
|
<errors>
|
||||||
|
<error>Invalid station string: station string cannot be empty</error>
|
||||||
|
</errors>
|
||||||
|
<warnings/>
|
||||||
|
<time_taken_ms>0</time_taken_ms>
|
||||||
|
</response>
|
18
tests/data/aviationweather/kjfk.xml
Normal file
18
tests/data/aviationweather/kjfk.xml
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<response xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XML-Schema-instance" version="1.2"
|
||||||
|
xsi:noNamespaceSchemaLocation="http://aviationweather.gov/adds/schema/metar1_2.xsd">
|
||||||
|
<request_index>24902199</request_index>
|
||||||
|
<data_source name="metars"/>
|
||||||
|
<request type="retrieve"/>
|
||||||
|
<errors/>
|
||||||
|
<warnings/>
|
||||||
|
<time_taken_ms>250</time_taken_ms>
|
||||||
|
<data num_results="1">
|
||||||
|
<METAR>
|
||||||
|
<raw_text>KJFK 042151Z 28026G39KT 10SM FEW055 SCT095 BKN110 BKN230 12/M04 A2958 RMK AO2
|
||||||
|
PK WND 27045/2128 PRESRR SLP018 T01221044
|
||||||
|
</raw_text>
|
||||||
|
</METAR>
|
||||||
|
</data>
|
||||||
|
</response>
|
Loading…
Reference in New Issue
Block a user