some refactoring for tests and adding some tables

This commit is contained in:
Nabeel Shahzad
2017-06-09 22:19:17 -05:00
parent 88f6730a8d
commit 7a79a8558e
32 changed files with 671 additions and 148 deletions

View File

@@ -1,26 +1,33 @@
<?php
use App\Models\Aircraft;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class AircraftTest extends TestCase
{
protected $repo;
protected $aircraft,
$aircraft_class;
public function setUp() {
parent::setUp();
$this->repo = $this->createRepository('AircraftRepository');
$this->aircraft = $this->createRepository('AircraftRepository');
$this->aircraft_class = $this->createRepository('AircraftClassRepository');
}
/**
* A basic test example.
*
* @return void
*/
public function testRepository()
public function testAircraftClasses()
{
print_r($this->repo->model());
factory(App\Models\AircraftClass::class)->create();
$this->aircraft->create([
'aircraft_class_id' => 1,
'icao' => 'B744',
'name' => 'Boeing 747',
]);
$aircraft = App\Models\Aircraft::where('icao', 'B744')->first();
$this->assertEquals('B744', $aircraft->icao, 'ICAO matching');
$this->assertEquals('H', $aircraft->class->code, 'Check belongsTo relationship');
}
}

View File

@@ -9,11 +9,25 @@ abstract class TestCase extends Illuminate\Foundation\Testing\TestCase
*/
protected $app;
protected $baseUrl = 'http://localhost';
protected $connectionsToTransact = ['testing'];
public function __construct($name = null, array $data = [], $dataName = '') {
parent::__construct($name, $data, $dataName);
}
protected function reset_db(){
exec('make -f ' . __DIR__ . '/../Makefile unittest-db');
}
public function setUp() {
parent::setUp();
$this->reset_db();
/*
Artisan::call('migrate');
Artisan::call('db:seed');
*/
}
/**
* Creates the application.
*
@@ -23,11 +37,12 @@ abstract class TestCase extends Illuminate\Foundation\Testing\TestCase
{
$app = require __DIR__.'/../bootstrap/app.php';
$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
//$app['config']->set('database.default','testing');
return $app;
}
public function createRepository($repo_name) {
$app = $this->createApplication();
return $app->make('App\Repositories\\' + $repo_name);
return $app->make('App\Repositories\\' . $repo_name);
}
}