phpvms/tests/PIREPTest.php

65 lines
1.9 KiB
PHP
Raw Normal View History

2017-06-09 12:00:30 +08:00
<?php
2017-07-04 14:05:23 +08:00
use App\Models\Pirep;
2017-06-09 12:00:30 +08:00
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
class PIREPTest extends TestCase
{
2017-07-04 14:05:23 +08:00
use WithoutMiddleware;
2017-07-05 02:09:44 +08:00
#use DatabaseMigrations;
2017-07-04 14:05:23 +08:00
protected $pirepSvc;
protected $SAMPLE_PIREP
= [
'user_id' => 1,
'flight_id' => 1,
'aircraft_id' => 1,
'dpt_airport_id' => 1,
'arr_airport_id' => 2,
'flight_time' => 21600, # 6 hours
'level' => 320,
'source' => 0, # manual
'notes' => 'just a pilot report',
];
public function setUp()
2017-06-09 12:00:30 +08:00
{
2017-07-04 14:05:23 +08:00
parent::setUp(); // TODO: Change the autogenerated stub
$this->addData('base');
$this->pirepSvc = app('App\Services\PIREPService');
}
public function testAddPirep()
{
$pirep = new Pirep($this->SAMPLE_PIREP);
$pirep->save();
$pirep = $this->pirepSvc->create($pirep, []);
/**
* Check the initial status info
*/
$this->assertEquals($pirep->pilot->flights, 0);
$this->assertEquals($pirep->status, VMSEnums::$pirep_status['PENDING']);
/**
* Now set the PIREP state to ACCEPTED
*/
$this->pirepSvc->changeStatus($pirep, VMSEnums::$pirep_status['ACCEPTED']);
$this->assertEquals(1, $pirep->pilot->flights);
$this->assertEquals(21600, $pirep->pilot->flight_time);
$this->assertEquals(1, $pirep->pilot->rank_id);
/**
* Now go from ACCEPTED to REJECTED
*/
$this->pirepSvc->changeStatus($pirep, VMSEnums::$pirep_status['REJECTED']);
$this->assertEquals(0, $pirep->pilot->flights);
$this->assertEquals(0, $pirep->pilot->flight_time);
$this->assertEquals(1, $pirep->pilot->rank_id);
2017-06-09 12:00:30 +08:00
}
}