Answer the question
In order to leave comments, you need to log in
How to setup phpunit database with migrations in Laravel?
Hello everyone :)
I'm trying to run tests based on SQLite, but it says that there is no data in the database. How to run migrations to the test database, can you tell me?
This is how PHPunit configs are now.
<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>
Answer the question
In order to leave comments, you need to log in
Added to config/database.php
'testing' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'test_laravel-chat'),
'username' => env('DB_USERNAME', 'homestead'),
'password' => env('DB_PASSWORD', 'secret'),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
]
<php>
<env name="APP_ENV" value="testing"/>
<env name="DB_CONNECTION" value="testing"/>
<env name="DB_DATABASE" value="test_laravel-chat"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
</php>
php artisan config:cache --env=testing
php artisan migrate --database testing
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question