Reputation: 1219
For some reason my application can't use :memory:
as the database while testing is printing the error: SQLSTATE[HY000] [1049] Unknown database ':memory:'
How can I get my test to use database in memory? I have looked on Stack Overflow, LaraCast, and Reddit but haven't found a solution. Is there an alternative way to do this?
PhpUnit.xml
<php>
<server name="APP_ENV" value="testing"/>
<server name="BCRYPT_ROUNDS" value="4"/>
<server name="CACHE_DRIVER" value="array"/>
<server name="DB_CONNECTION" value="sqlite"/>
<server name="DB_DATABASE" value=":memory:"/>
<server name="MAIL_DRIVER" value="array"/>
<server name="QUEUE_CONNECTION" value="sync"/>
<server name="SESSION_DRIVER" value="array"/>
<server name="TELESCOPE_ENABLED" value="false"/>
</php>
config/database.php
'sqlite' => [
'driver' => 'sqlite',
'url' => env('DATABASE_URL'),
'database' => env('DB_DATABASE', database_path('database.sqlite')),
//'database' => database_path('database.sqlite'),
'prefix' => '',
'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
],
I have run php artisan config:clear
& cache:clear
.
Upvotes: 0
Views: 933
Reputation: 1219
So eventually decided to remove the <server name="DB_DATABASE" value=":memory:"/>
which kind of worked but still gave misc errors, but it made me realize that my phpunit.xml
was not overriding my database connection.
So the long and short of the story is I ended up creating a testing connection that uses the :memory:
database which worked.
'testing' => [
'driver' => 'sqlite',
'database' => ':memory:',
],
As to what was initially preventing it from working the standard way of doing it I still don't know. but this resolved my issue.
Upvotes: 1