From 0fa00206cea2d819a5abf0c8c7199f916f7651c4 Mon Sep 17 00:00:00 2001 From: Nabeel Shahzad Date: Thu, 29 Oct 2020 12:38:40 -0400 Subject: [PATCH] Make sure stdclass is returned in flight fields --- app/Http/Resources/Flight.php | 8 ++++---- tests/FlightTest.php | 8 ++++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/Http/Resources/Flight.php b/app/Http/Resources/Flight.php index 06d17c6e..76b0d0e9 100644 --- a/app/Http/Resources/Flight.php +++ b/app/Http/Resources/Flight.php @@ -18,17 +18,17 @@ class Flight extends Resource private function setFields() { /** @var \Illuminate\Support\Collection $field_values */ + $return_values = new stdClass(); $field_values = $this->field_values; if (empty($field_values) || $field_values->count() === 0) { - return new stdClass(); + return $return_values; } - $fields = []; foreach ($field_values as $field) { - $fields[$field->name] = $field->value; + $return_values->{$field->name} = $field->value; } - return $fields; + return $return_values; } /** diff --git a/tests/FlightTest.php b/tests/FlightTest.php index 3bab4c2a..bc721175 100644 --- a/tests/FlightTest.php +++ b/tests/FlightTest.php @@ -113,12 +113,20 @@ class FlightTest extends TestCase */ public function testSearchFlight() { + /** @var \App\Models\User user */ $this->user = factory(User::class)->create(); $flight = $this->addFlight($this->user); + /** @var \App\Services\FlightService $flightSvc */ + $flightSvc = app(FlightService::class); + $flightSvc->updateCustomFields($flight, [ + ['name' => '0', 'value' => 'value'], + ]); + // search specifically for a flight ID $query = 'flight_id='.$flight->id; $req = $this->get('/api/flights/search?'.$query); + $body = $req->json(['data']); $req->assertStatus(200); }