Skip to content

Instantly share code, notes, and snippets.

@joecohens
Created March 4, 2016 21:24
Show Gist options
  • Save joecohens/fc969d629828f5e8a3bb to your computer and use it in GitHub Desktop.
Save joecohens/fc969d629828f5e8a3bb to your computer and use it in GitHub Desktop.
<?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