fix serialization of converter classes #189

This commit is contained in:
Nabeel Shahzad 2018-02-10 22:30:42 -06:00
parent 9b9a20b437
commit 0700c96901
4 changed files with 10 additions and 14 deletions

View File

@ -12,10 +12,8 @@ class Flight extends Resource
$flight = parent::toArray($request);
// Return multiple measures so the client can pick what they want
if(\in_array('distance', $flight, true)
&& $flight['distance'] instanceof Distance)
{
$flight['distance'] = $flight['distance']->toObject();
if(filled($this->distance) && $this->distance instanceof Distance) {
$flight['distance'] = $this->distance->toObject();
}
$flight['airline'] = new Airline($this->airline);

View File

@ -17,16 +17,12 @@ class Pirep extends Resource
{
$pirep = parent::toArray($request);
if (\in_array('distance', $pirep, true)
&& $pirep['distance'] instanceof Distance)
{
$pirep['distance'] = $pirep['distance']->toObject();
if (filled($this->distance) && $this->distance instanceof Distance) {
$pirep['distance'] = $this->distance->toObject();
}
if (\in_array('planned_distance', $pirep, true)
&& $pirep['planned_distance'] instanceof Distance)
{
$pirep['planned_distance'] = $pirep['planned_distance']->toObject();
if (filled($this->planned_distance) && $this->planned_distance instanceof Distance) {
$pirep['planned_distance'] = $this->planned_distance->toObject();
}
$pirep['airline'] = new Airline($this->airline);

View File

@ -155,9 +155,9 @@ class Pirep extends BaseModel
public function setPlannedDistanceAttribute($value)
{
if ($value instanceof Distance) {
$this->attributes['distance'] = $value->toUnit(Distance::STORAGE_UNIT);
$this->attributes['planned_distance'] = $value->toUnit(Distance::STORAGE_UNIT);
} else {
$this->attributes['distance'] = $value;
$this->attributes['planned_distance'] = $value;
}
}

View File

@ -134,6 +134,8 @@ class AcarsTest extends TestCase
$this->assertEquals('custom_field', $pirep['fields'][0]['name']);
$this->assertEquals('custom_value', $pirep['fields'][0]['value']);
$this->assertHasKeys($pirep['distance'], ['mi', 'nmi', 'km']);
/**
* Update the custom field
*/