Why doesn't Laravel in-memory testing work when seeding is enabled?

85 Views Asked by At

I recently upgraded an application to Laravel 9, and have in-memory testing set up for the unit and feature tests.

<env name="DB_CONNECTION" value="inmemory"/>
<env name="DB_DATABASE" value=":memory:"/>

'connections' => [

    'inmemory' => [
        'driver' => 'sqlite',
        'database' => ':memory:',
        'prefix' => '',
    ],

    ...

Inside of each test, I'm using the following to seed the database, as recommended by the documentation:

protected $seeder = ExampleSeederClass::class;

When I run the tests with php artisan test --parallel (with or without the --parallel switch) all tests requiring a seeder fail with:

Failed asserting that null matches expected ...

When I simply replace the in-memory database with an on-disk SQlite in my .testing.env file, the tests pass as expected (after some initial time to seed the database):

DB_CONNECTION=sqlite
DB_DATABASE=testing.sqlite
DB_USERNAME=root
DB_PASSWORD=

Is this a Laravel bug, and if not, what could be happening here?

Here is an example of one of my failing tests:

/**
 * @dataProvider idList
 *
 * @return void
 */
public function test_id_verification_method($request, $output)
{
    $user = new User;
    $request = Request::create('/', 'GET');
    $request->merge(['id' => $this->dataName()]);
    $request->setLaravelSession(session());
    $this->assertEquals($output, $user->verify_id($request, $user));
} 
0

There are 0 best solutions below