Fix unittests
This commit is contained in:
parent
15ed2bd846
commit
6b3bfe0908
4
Makefile
4
Makefile
@ -30,9 +30,9 @@ db:
|
||||
php artisan migrate:refresh --seed
|
||||
|
||||
unittest-db:
|
||||
rm -f database/unittest.sqlite
|
||||
-@rm -f database/unittest.sqlite
|
||||
sqlite3 database/unittest.sqlite ""
|
||||
php artisan migrate:refresh --seed --env unittest
|
||||
php artisan migrate:refresh --env unittest
|
||||
|
||||
tests: test
|
||||
|
||||
|
@ -42,8 +42,7 @@ class FareService extends BaseService {
|
||||
*/
|
||||
public function getForAircraft(Aircraft &$aircraft)
|
||||
{
|
||||
$fares = [];
|
||||
foreach($aircraft->fares as $fare) {
|
||||
$fares = $aircraft->fares->map(function($fare) {
|
||||
if(!is_null($fare->pivot->price)) {
|
||||
$fare->price = $fare->pivot->price;
|
||||
}
|
||||
@ -55,8 +54,9 @@ class FareService extends BaseService {
|
||||
if(!is_null($fare->pivot->capacity)) {
|
||||
$fare->capacity = $fare->pivot->capacity;
|
||||
}
|
||||
array_push($fares, $fare);
|
||||
}
|
||||
|
||||
return $fare;
|
||||
});
|
||||
|
||||
return $fares;
|
||||
}
|
||||
|
48
database/seeds/UnittestSeeder.php
Normal file
48
database/seeds/UnittestSeeder.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
1
database/seeds/unittest.yml
Normal file
1
database/seeds/unittest.yml
Normal file
@ -0,0 +1 @@
|
||||
#
|
Loading…
Reference in New Issue
Block a user