Fix unittests

This commit is contained in:
Nabeel Shahzad
2017-06-13 19:53:02 -05:00
parent 15ed2bd846
commit 6b3bfe0908
4 changed files with 55 additions and 6 deletions
+2 -2
View File
@@ -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
+4 -4
View File
@@ -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;
} }
+48
View 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
View File
@@ -0,0 +1 @@
#