Created
March 4, 2016 21:24
-
-
Save joecohens/fc969d629828f5e8a3bb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Illuminate\Foundation\Testing\DatabaseTransactions; | |
use Illuminate\Support\Facades\Artisan; | |
abstract class AbstractTestCase extends TestCase | |
{ | |
use DatabaseTransactions; | |
/** | |
* The setup database status. | |
* | |
* @var bool | |
*/ | |
public static $setupDatabase = true; | |
/** | |
* Default preparation for each test. | |
*/ | |
public function setUp() | |
{ | |
if (!$this->app) { | |
$this->refreshApplication(); | |
} | |
if (self::$setupDatabase) { | |
$this->setupDatabase(); | |
} | |
$this->setUpTraits(); | |
foreach ($this->afterApplicationCreatedCallbacks as $callback) { | |
call_user_func($callback); | |
} | |
$this->setUpHasRun = true; | |
} | |
/** | |
* Migrates the database once. | |
* This will cause the tests to run quickly. | |
* | |
* @return void | |
*/ | |
public function setupDatabase() | |
{ | |
Artisan::call('migrate:refresh', [ | |
'--force' => true, | |
'--quiet' => true, | |
]); | |
self::$setupDatabase = false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment