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