As mentioned earlier, you must first establish a connection in each model. Thus, you configure the connections in the database configuration file, set the values ββin the .env file and use them in the model constructors.
You can also do this for testing. Add a test connection to the config/database.php file, and then use the override env file.
Create an additional env file, name it something like .env.testing .
So in your .env file you will have:
CONNECTION_MYSQL=mysql CONNECTION_POSTGRESS=postgress
Then in the .env.testing file you can:
CONNECTION_MYSQL=test_sqlite CONNECTION_POSTGRESS=test_sqlite
Finally, to download this env file for testing, go to the CreatesApplication sign and update it to the following value:
public function createApplication() { $app = require __DIR__.'/../bootstrap/app.php'; $app->loadEnvironmentFrom('.env.testing'); $app->make(Kernel::class)->bootstrap(); return $app; }
Using the loadEnvironemtFrom() method, all tests that use this attribute download the .env.testing file and use the connections defined there.
achillesp
source share