2017-06-10 03:47:02 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
class AircraftTest extends TestCase
|
|
|
|
{
|
2017-06-11 07:27:19 +08:00
|
|
|
protected $ac_svc,
|
|
|
|
$ICAO = 'B777';
|
2017-06-10 03:47:02 +08:00
|
|
|
|
2017-06-11 07:27:19 +08:00
|
|
|
public function setUp()
|
|
|
|
{
|
2017-06-10 03:47:02 +08:00
|
|
|
parent::setUp();
|
2017-07-05 02:09:44 +08:00
|
|
|
$this->addData('aircraft');
|
2017-06-10 14:50:00 +08:00
|
|
|
}
|
|
|
|
|
2017-06-11 07:41:35 +08:00
|
|
|
protected function getAircraftClass()
|
2017-06-11 07:27:19 +08:00
|
|
|
{
|
|
|
|
return app('App\Repositories\AircraftClassRepository')
|
|
|
|
->findByField('code', 'H')->first();
|
|
|
|
}
|
2017-06-10 14:50:00 +08:00
|
|
|
|
2017-06-11 07:41:35 +08:00
|
|
|
protected function findByICAO($icao)
|
2017-06-11 07:27:19 +08:00
|
|
|
{
|
2017-06-24 06:33:18 +08:00
|
|
|
$ac_repo = app('App\Repositories\SubfleetRepository');
|
2017-06-11 07:27:19 +08:00
|
|
|
return $ac_repo->findByICAO($icao);
|
2017-06-10 03:47:02 +08:00
|
|
|
}
|
2017-06-10 11:19:17 +08:00
|
|
|
|
2017-06-11 07:41:35 +08:00
|
|
|
protected function getFareByCode($code)
|
2017-06-10 03:47:02 +08:00
|
|
|
{
|
2017-06-11 07:27:19 +08:00
|
|
|
return app('App\Repositories\FareRepository')->findByCode($code);
|
|
|
|
}
|
2017-06-10 11:19:17 +08:00
|
|
|
|
2017-06-11 07:27:19 +08:00
|
|
|
/**
|
|
|
|
* Check the association of the aircraft class to an aircraft
|
|
|
|
* Mostly to experiment with the ORM type stuff. This isn't
|
|
|
|
* where most of the testing, etc is required.
|
|
|
|
*/
|
2017-06-11 07:41:35 +08:00
|
|
|
protected function addAircraft()
|
2017-06-11 07:27:19 +08:00
|
|
|
{
|
2017-06-24 06:33:18 +08:00
|
|
|
$mdl = new App\Models\Aircraft;
|
|
|
|
$mdl->icao = $this->ICAO;
|
|
|
|
$mdl->name = 'Boeing 777';
|
|
|
|
$mdl->save();
|
2017-06-11 07:27:19 +08:00
|
|
|
|
2017-06-11 07:41:35 +08:00
|
|
|
return $this->findByICAO($this->ICAO);
|
2017-06-11 07:27:19 +08:00
|
|
|
}
|
|
|
|
|
2017-11-24 00:10:27 +08:00
|
|
|
public function testAircraftFaresNoOverride()
|
2017-06-11 07:27:19 +08:00
|
|
|
{
|
2017-07-04 14:12:55 +08:00
|
|
|
$this->markTestIncomplete(
|
|
|
|
'This test has not been implemented yet.'
|
|
|
|
);
|
|
|
|
|
2017-07-04 14:05:23 +08:00
|
|
|
return true;
|
2017-06-11 07:27:19 +08:00
|
|
|
$fare_svc = app('App\Services\FareService');
|
|
|
|
|
2017-06-11 07:41:35 +08:00
|
|
|
$aircraft = $this->addAircraft();
|
|
|
|
$fare = $this->getFareByCode('Y');
|
2017-06-11 07:27:19 +08:00
|
|
|
|
2017-06-11 07:41:35 +08:00
|
|
|
$fare_svc->setForAircraft($aircraft, $fare);
|
|
|
|
$ac_fares = $fare_svc->getForAircraft($aircraft);
|
2017-06-11 07:27:19 +08:00
|
|
|
|
|
|
|
$this->assertCount(1, $ac_fares);
|
|
|
|
$this->assertEquals($fare->price, $ac_fares[0]->price);
|
|
|
|
$this->assertEquals($fare->capacity, $ac_fares[0]->capacity);
|
|
|
|
|
|
|
|
#
|
|
|
|
# set an override now
|
|
|
|
#
|
2017-06-11 07:41:35 +08:00
|
|
|
$fare_svc->setForAircraft($aircraft, $fare, [
|
2017-06-11 07:27:19 +08:00
|
|
|
'price' => 50, 'capacity' => 400
|
|
|
|
]);
|
|
|
|
|
|
|
|
# look for them again
|
2017-06-11 07:41:35 +08:00
|
|
|
$ac_fares = $fare_svc->getForAircraft($aircraft);
|
2017-06-11 07:27:19 +08:00
|
|
|
|
|
|
|
$this->assertCount(1, $ac_fares);
|
|
|
|
$this->assertEquals(50, $ac_fares[0]->price);
|
|
|
|
$this->assertEquals(400, $ac_fares[0]->capacity);
|
|
|
|
|
|
|
|
# delete
|
2017-06-11 07:41:35 +08:00
|
|
|
$fare_svc->delFromAircraft($aircraft, $fare);
|
|
|
|
$this->assertCount(0, $fare_svc->getForAircraft($aircraft));
|
2017-06-11 07:27:19 +08:00
|
|
|
}
|
|
|
|
|
2017-11-24 00:10:27 +08:00
|
|
|
public function testAircraftFaresOverride()
|
2017-06-11 07:27:19 +08:00
|
|
|
{
|
2017-07-04 14:12:55 +08:00
|
|
|
$this->markTestSkipped(
|
|
|
|
'This test has not been implemented yet.'
|
|
|
|
);
|
|
|
|
|
2017-06-11 07:27:19 +08:00
|
|
|
$fare_svc = app('App\Services\FareService');
|
|
|
|
|
2017-06-11 07:41:35 +08:00
|
|
|
$aircraft = $this->addAircraft();
|
|
|
|
$fare = $this->getFareByCode('Y');
|
2017-06-11 07:27:19 +08:00
|
|
|
|
2017-06-11 07:41:35 +08:00
|
|
|
$fare_svc->setForAircraft($aircraft, $fare, [
|
2017-06-11 07:27:19 +08:00
|
|
|
'price' => 50, 'capacity' => 400
|
|
|
|
]);
|
|
|
|
|
2017-06-11 07:41:35 +08:00
|
|
|
$ac_fares = $fare_svc->getForAircraft($aircraft);
|
2017-06-11 07:27:19 +08:00
|
|
|
|
|
|
|
$this->assertCount(1, $ac_fares);
|
|
|
|
$this->assertEquals(50, $ac_fares[0]->price);
|
|
|
|
$this->assertEquals(400, $ac_fares[0]->capacity);
|
|
|
|
|
|
|
|
#
|
|
|
|
# update the override to a different amount and make sure it updates
|
|
|
|
#
|
|
|
|
|
2017-06-11 07:41:35 +08:00
|
|
|
$fare_svc->setForAircraft($aircraft, $fare, [
|
2017-06-11 07:27:19 +08:00
|
|
|
'price' => 150, 'capacity' => 50
|
2017-06-10 11:19:17 +08:00
|
|
|
]);
|
|
|
|
|
2017-06-11 07:41:35 +08:00
|
|
|
$ac_fares = $fare_svc->getForAircraft($aircraft);
|
2017-06-11 07:27:19 +08:00
|
|
|
|
|
|
|
$this->assertCount(1, $ac_fares);
|
|
|
|
$this->assertEquals(150, $ac_fares[0]->price);
|
|
|
|
$this->assertEquals(50, $ac_fares[0]->capacity);
|
2017-06-10 14:50:00 +08:00
|
|
|
|
2017-06-11 07:27:19 +08:00
|
|
|
# delete
|
2017-06-11 07:41:35 +08:00
|
|
|
$fare_svc->delFromAircraft($aircraft, $fare);
|
|
|
|
$this->assertCount(0, $fare_svc->getForAircraft($aircraft));
|
2017-06-11 07:27:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @expectedException Exception
|
|
|
|
*/
|
2017-11-24 00:10:27 +08:00
|
|
|
public function testAircraftMissingField()
|
2017-06-11 07:27:19 +08:00
|
|
|
{
|
2017-07-04 14:12:55 +08:00
|
|
|
$this->markTestSkipped(
|
|
|
|
'This test has not been implemented yet.'
|
|
|
|
);
|
2017-07-04 14:05:23 +08:00
|
|
|
return true;
|
2017-06-11 07:27:19 +08:00
|
|
|
# missing the name field
|
|
|
|
$svc = app('App\Services\AircraftService');
|
|
|
|
$svc->create(['icao' => $this->ICAO]);
|
2017-06-10 03:47:02 +08:00
|
|
|
}
|
|
|
|
}
|