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:
Nabeel S
2019-08-08 17:41:53 -04:00
committed by GitHub
parent 5cafebe4d6
commit 47be7507f0
7 changed files with 86 additions and 13 deletions

View File

@@ -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'));
}
}

View 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>

View 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>