Laravel ignores test database connection

I am using Laravel 5.3.22 and want to do unit testing of my application using a sqlite database in memory that migrates / rolls back for each test, as said here . This is the connections section of my config.php database:

'mysql' => [ 'driver' => 'mysql', 'host' => env('DB_HOST', 'localhost'), 'database' => env('DB_DATABASE', 'forge'), 'username' => env('DB_USERNAME', 'forge'), 'password' => env('DB_PASSWORD', ''), ... ], 'testing' => [ 'driver' => 'sqlite', 'database' => ':memory:', 'prefix' => '', ], 

This is the phpunit env config:

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

The phpunit configuration implies that laravel shoud uses the "test" sqlite connection for testing, but it does not matter and continues with the main mysql connection. This is not an option, I have a large and complex scheme, and it cannot be used for unit testing with MySQL. How do I proceed? I can’t scoff at the query creator because I need to validate the results on it.

+7
source share
2 answers

I figured out this problem, I used configuration caching in my local environment, and this prevents Laravel from being used in phpunit configuration. the config: clear artisan command helped. I also changed the file cache driver to an array, one for my local env.

+5
source

Since my reputation is currently low, adding an answer confirming Sergey’s answer above is actually correct and easily overlooked. Very easy to miss.

Link for anyone interested here: https://laravel.com/docs/5.8/configuration#configuration-caching

0
source

Source: https://habr.com/ru/post/1260453/


All Articles