From e65edc5709410389aee2a28461139e944bb416d7 Mon Sep 17 00:00:00 2001 From: Nabeel Shahzad Date: Thu, 28 Dec 2017 16:09:49 -0600 Subject: [PATCH] Fix error if there are no points in the ACARS route --- app/Services/GeoService.php | 13 ++++++++----- tests/AcarsTest.php | 4 ++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/app/Services/GeoService.php b/app/Services/GeoService.php index 84ff8ffe..e8788a30 100644 --- a/app/Services/GeoService.php +++ b/app/Services/GeoService.php @@ -174,7 +174,6 @@ class GeoService extends BaseService { $route_line = []; $route_points = []; - #$route_line[] = [$pirep->dpt_airport->lon, $pirep->dpt_airport->lat]; /** * @var $point \App\Models\Acars @@ -191,12 +190,16 @@ class GeoService extends BaseService ++$counter; } - # Arrival - #$route_line[] = [$pirep->arr_airport->lon, $pirep->arr_airport->lat]; - $route_line = new Feature(new LineString($route_line)); + + if(\count($route_line) >= 2) { + $route_line = new Feature(new LineString($route_line)); + $route_line = new FeatureCollection([$route_line]); + } else { + $route_line = new FeatureCollection([]); + } return [ - 'line' => new FeatureCollection([$route_line]), + 'line' => $route_line, 'points' => new FeatureCollection($route_points) ]; } diff --git a/tests/AcarsTest.php b/tests/AcarsTest.php index a3bf10c0..2109fece 100644 --- a/tests/AcarsTest.php +++ b/tests/AcarsTest.php @@ -69,11 +69,11 @@ class AcarsTest extends TestCase $this->assertEquals(PirepState::IN_PROGRESS, $pirep['state']); $this->assertEquals(PirepStatus::ENROUTE, $pirep['status']); - /*$uri = '/api/pireps/' . $pirep_id . '/acars'; + $uri = '/api/pireps/' . $pirep_id . '/acars'; $response = $this->withHeaders($this->apiHeaders())->get($uri); $response->assertStatus(200); - $body = $response->json(); + /*$body = $response->json(); $this->assertEquals(1, $this->count($body)); $this->assertEquals($pirep_id, $body[0]['pirep_id']);*/ }