Skip to content

Instantly share code, notes, and snippets.

Last active Aug 20, 2016
What would you like to do?
Use in-memory database when running tests for a Laravel application.

Configuring the database and PHPUnit was described on the Laracasts Forum. How to use Artisan commands instead of Laravel's database migration trait to reset the database after each test was described on the ScriptScoop Forum.

Laravel 5.1's database migration trait crashes on migration rollback during test tear-down since the in-memory database is already destroyed at that point.

Directory structure:

'connections' => [
'sqlite_testing' => [
'driver' => 'sqlite',
'database' => ':memory:',
'prefix' => '',
use Illuminate\Support\Facades\Artisan;
class MemoryDbTest extends \TestCase
public function setUp()
// optional: Artisan::call('db:seed', ['--class' => 'TestSeeder'])
<env name="DB_CONNECTION" value="sqlite_testing"/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment