some test changes

This commit is contained in:
Nabeel Shahzad
2017-06-19 11:30:39 -05:00
parent 96887bd9c6
commit 6ef83084d1
9 changed files with 128 additions and 52 deletions

View File

@@ -0,0 +1,10 @@
<?php
$factory->define(App\Models\Flight::class, function (Faker\Generator $faker) {
return [
'code' => 'Y',
'name' => 'Economy',
'price' => '100',
'capacity' => '200',
];
});

View File

@@ -1,48 +0,0 @@
<?php
use Carbon\Carbon;
use Illuminate\Database\Seeder;
class DevelopmentSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
//$this->seed_from_yaml();
}
protected function time(): string
{
return Carbon::now('UTC')->format('Y-m-d H:i:s');
}
protected function seed_from_yaml(): void
{
$time_fields = ['created_at', 'updated_at'];
$yml = Yaml::parse(file_get_contents(database_path('seeds/unittest.yml')));
foreach ($yml as $table => $rows) {
foreach ($rows as $row) {
# encrypt any password fields
if(array_key_exists('password', $row)) {
$row['password'] = bcrypt($row['password']);
}
# if any time fields are == to "now", then insert the right time
foreach($time_fields as $tf) {
if(array_key_exists($tf, $row) && $row[$tf] === 'now') {
$row[$tf] = $this->time();
}
}
DB::table($table)->insert($row);
}
}
}
}

View File

@@ -30,21 +30,25 @@ airlines:
updated_at: now
airports:
- icao: KAUS
- id: 1
icao: KAUS
name: Austin-Bergstrom
location: Austin, Texas, USA
lat: 30.1945278
lon: -97.6698889
- icao: KJFK
- id: 2
icao: KJFK
name: John F Kennedy
location: New York, New York, USA
lat: 40.6399257
lon: -73.7786950
- icao: EGLL
- id: 3
icao: EGLL
name: London Heathrow
location: London, England
lat: 51.4775
lon: -0.4614
#
aircraft_classes:
- id: 1
@@ -112,3 +116,10 @@ aircraft_fare:
- aircraft_id: 2
fare_id: 3
capacity: 10
flights:
- airline_id: 1
flight_number: 100
dpt_airport_id: 1
arr_airport_id: 2
route: KAUS KJFK

View File

@@ -1 +0,0 @@
#