title: Use in-memory SQLite in Laravel PHPUnit test
body: <p>I'm trying to get a Laravel project running at my new work. The developer who left didn't specify how to get the code up and running in the handover document and no-one else knows either.</p>
  
  <p>The SQLite database is created with <code>:memory:</code>, and <code>php artisan migrate</code> works without errors.</p>
  
  <pre><code>...
  Migrating: 2016_06_01_000004_create_oauth_clients_table
  Migrated:  2016_06_01_000004_create_oauth_clients_table
  ...
  </code></pre>
  
  <p>The method <code>beginDatabaseTransaction()</code> in the trait (standard Laravel code) is being executed, but none of the tables exist afterwards. It's as if the database is being created but the migration is not being executed.</p>
  
  <pre><code>&lt;?php
  
  namespace Illuminate\Foundation\Testing;
  
  trait DatabaseTransactions
  {
      /**
       * Handle database transactions on the specified connections.
       *
       * @return void
       */
      public function beginDatabaseTransaction()
      {
          $database = $this-&gt;app-&gt;make('db');
  
          foreach ($this-&gt;connectionsToTransact() as $name) {
              $database-&gt;connection($name)-&gt;beginTransaction();
          }
  
          $this-&gt;beforeApplicationDestroyed(function () use ($database) {
              foreach ($this-&gt;connectionsToTransact() as $name) {
                  $connection = $database-&gt;connection($name);
  
                  $connection-&gt;rollBack();
                  $connection-&gt;disconnect();
              }
          });
      }
  </code></pre>
  
  <p>Test code (the last shown instruction fails):</p>
  
  <pre><code>&lt;?php
  namespace Tests\Feature;
  use Tests\TestCase;
  use Illuminate\Foundation\Testing\DatabaseTransactions;
  use Laravel\Passport\ClientRepository;
  
  class PassportTest extends TestCase
  {
      use DatabaseTransactions;
  
      public function test_basic_oauth_token_authentication(){
        $clientRepository = new ClientRepository();
        $client = $clientRepository-&gt;createPersonalAccessClient(
            null, 'Test Personal Access Client', $this-&gt;baseUrl
        );
  </code></pre>
  
  <p>Command line:</p>
  
  <pre><code>vendor/bin/phpunit tests/Feature/PassPortTest
  </code></pre>
  
  <p>Error message:</p>
  
  <blockquote>
  <pre><code>Illuminate\Database\QueryException: SQLSTATE[HY000]: General error: 1 no such table: oauth_clients
  Caused by  
  Doctrine\DBAL\Driver\PDOException: SQLSTATE[HY000]: General error: 1 no such table: oauth_clients
  Caused by
  PDOException: SQLSTATE[HY000]: General error: 1 no such table: oauth_clients
  </code></pre>
  </blockquote>
  
  <p>How can I ensure that the tables have been created as part of each test?</p>