I would like to know if it is possible to set up the testing environment in laravel with a database that is not existing in your pc, for example i have mysql datbase, and i want to set up the test to be in mysqllite is that possible if not, how can i set up the testing environment in laravel with mysql database ?
when i try this :
'sqlite_testing' => [
'driver' => 'sqlite',
'database' => ":memory:",
],
i get this error :
IlluminateDatabaseQueryException: could not find driver (Connection: sqlite_testing, SQL: select * from sqlite_master where
type = 'table' and name = migrations)
2
Answers
i want to the database.php file and set up the mysql environment like this and created a database called testing_db in phpmyadmin and it worked, turns out you can't run a test on databse that is not in your local environment
I don’t know how you came to this conclusion, but there does have ways to use another testing only database when executing unit tests, and you don’t have to create a new driver config for testing.
Creating a
.env.testing
in your project root, it also allow you using different host, username or database for testing, it’s simple just as you set a normal.env
.Laravel already set done PHPUnit xml config, it will trying to load
.env.testing
when running test, if there is no.env.tesing
, it will load the.env
, you can find more details from hereļ¼https://laravel.com/docs/10.x/testing#the-env-testing-environment-file