devonblzx's avatar

DatabaseMigrations has stopped working all of a sudden

All of a sudden our tests started failing today, but yesterday were working fine. Pretty much all of them were reporting that the users table does not exist.

I have narrowed it down to the migrations not being run before the test cases start even though all of the classes are using the DatabaseMigrations trait.

The odd thing is migrate:rollback seems to work since changing it to a file instead of in-memory database and migrating beforehand works for the first test case.

Continuing with this (file sqlite and running a migration before testing) and removing the DatabaseMigrations works. Running php artisan migrate --database=testing and running Artisan::call('migrate') from tinker works fine.

Anyone else experienced this? What can I do to see why the migration is failing before the tests?

For obvious reasons, I'd prefer to keep using DatabaseMigrations in a memory database.

phpunit.xml

        <env name="DB_CONNECTION" value="testing"/>

config/database.php

        'testing' => [
            'driver' => 'sqlite',
            'database' => ':memory:',
//            'database' => database_path('testing.sqlite'),
            'prefix' => '',
        ],
0 likes
1 reply
kylevorster's avatar

Have you tried setting the database in your phpunit.xml file instead of referencing to your database.php config file.

    <php>
        <env name="APP_ENV" value="testing"/>
        <env name="DB_CONNECTION" value="sqlite"/>
        <env name="DB_DATABASE" value=":memory:"/>
        <env name="CACHE_DRIVER" value="array"/>
        <env name="SESSION_DRIVER" value="array"/>
        <env name="QUEUE_DRIVER" value="sync"/>
    </php>

Please or to participate in this conversation.