how to separate test database in laravel unit test

Solutions on MaxInterview for how to separate test database in laravel unit test by the best coders in the world

showing results for - "how to separate test database in laravel unit test"
Matteo
07 Apr 2019
1// In your config/database.php bellow mysql add:
2
3'mysql_testing' => [
4'driver' => 'mysql',
5'host' => env('TESTING_DB_HOST', 'localhost'),
6'database' => env('TESTING_DB_DATABASE', 'forge'),
7'username' => env('TESTING_DB_USERNAME', 'forge'),
8'password' => env('TESTING_DB_PASSWORD', ''),
9'charset' => 'utf8',
10'collation' => 'utf8_unicode_ci',
11'prefix' => '',
12'strict' => false,
13],
14
15//And now in your .env add the values for:
16
17TESTING_DB_HOST=localhost
18TESTING_DB_DATABASE=homestead_testing
19TESTING_DB_USERNAME=homestead
20TESTING_DB_PASSWORD=secret
21
22// Now you can run
23
24php artisan migrate —database=mysql_testing
25// And the last thing - open your phpunit.xml file in the app folder and add this:
26
27  <env name="DB_CONNECTION" value="mysql_testing"/>
28
29