Laravel 5.8 does not use sqlite for testing I've tried many of the solutions I've come across, all of them were for older versions of laravel.
but none of them worked, laravel always uses mysql database even when setting the default database to sqlite (as a solution!).
So please, how to set up sqlite for testing in laravel 5.8?
Have you defined DB_CONNECTION within your phpunit.xml file?
Make your phpunit.xml look like this
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
printerClass="Codedungeon\PHPUnitPrettyResultPrinter\Printer">
<testsuites>
<testsuite name="Feature">
<directory suffix="Test.php">./tests/Feature</directory>
</testsuite>
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./app</directory>
</whitelist>
</filter>
<php>
<env name="APP_ENV" value="testing"/>
<env name="TELESCOPE_ENABLED" value="false" />
<env name="BCRYPT_ROUNDS" value="4"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
<env name="MAIL_DRIVER" value="array"/>
<env name="DB_CONNECTION" value="sqlite"/>
<env name="DB_DATABASE" value=":memory:"/>
</php>
</phpunit>
@Tray2 the tag "env" does not exist, instead, there is "server" tag, I did your proposal and it didn't work (with server tag not env) as I've said it uses MySQL instead sqlite.
Change the server tag to env and it should work again.
@Tray2
this is sqlite config in database.php
'sqlite' => [
'driver' => 'sqlite',
'url' => env('DATABASE_URL'),
'database' => env('DB_DATABASE', database_path('database.sqlite')),
'prefix' => '',
'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true),
],
iive tried that with both tags, but still same results!
Did you install Laravel Telescope? If so, you need to be sure you have the line below in your phpunit.xml:
<env name="TELESCOPE_ENABLED" value="false" />
Somehow having telescope enabled while running tests causes an .env problem.
@MTHOMAS - i don't have telescope installed
@joe -inz do you have sqlite3 and pdo_sqlite extensions enabled in php.ini?
and you use in your test:
use Illuminate\Foundation\Testing\DatabaseMigrations;
@SEBRAPONI - i think it might be the problem that those two exts are not installed, currently, I couldn't install "pdo_sqlite" because i'm using ubuntu it gonna be really frustrating.
well thanks anyway
You can just find and open php.ini and uncomment these lines, then you have them or am I missing something.
In my case, I had specified DATABASE_URL in my .env file, and it was overriding the DB_CONNECTION and DB_DATABASE in my phpunit.xml.
I solved it by using the DB_* variables instead of DATABASE_URL in my .env file.
@adriaanzon good to know that was a solution, but in my case, the solution was by running php artisan cache:clear before running tests.
I just ran into this issue myself now, and I think you meant php artisan config:clear.
Please sign in or create an account to participate in this conversation.