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:
@@ -1,7 +1,12 @@
|
||||
<?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
|
||||
@@ -16,6 +21,25 @@ class MetarTest extends TestCase
|
||||
$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
|
||||
*/
|
||||
@@ -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 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>
|
||||
Reference in New Issue
Block a user