Skip to content

PHP code snippet – How to separate test database in laravel unit test?

// In your config/database.php bellow mysql add:

'mysql_testing' => [
'driver' => 'mysql',
'host' => env('TESTING_DB_HOST', 'localhost'),
'database' => env('TESTING_DB_DATABASE', 'forge'),
'username' => env('TESTING_DB_USERNAME', 'forge'),
'password' => env('TESTING_DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],

//And now in your .env add the values for:

TESTING_DB_HOST=localhost
TESTING_DB_DATABASE=homestead_testing
TESTING_DB_USERNAME=homestead
TESTING_DB_PASSWORD=secret

// Now you can run

php artisan migrate —database=mysql_testing
// And the last thing - open your phpunit.xml file in the app folder and add this:

  <env name="DB_CONNECTION" value="mysql_testing"/>

See also  CSS code snippet - How to remove lines from textarea?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.