skip to Main Content

I can successfully seed records to my normal database. Now I am focusing on tests and the first step is to add ‘test database’.
How can I seed to that specific database other than the normal database?

    `<server name="APP_ENV" value="testing"/>
    <server name="BCRYPT_ROUNDS" value="4"/>
    <server name="CACHE_DRIVER" value="array"/>
     <server name="DB_CONNECTION" value="testing"/>
    <!-- <server name="DB_DATABASE" value=":memory:"/> -->
    <server name="MAIL_MAILER" value="array"/>
    <server name="QUEUE_CONNECTION" value="sync"/>
    <server name="SESSION_DRIVER" value="array"/>
    <server name="TELESCOPE_ENABLED" value="false"/>`

Above is my phpunit configuration file, I also have env.testing file holding my testing configurations.
I already have daatabase called database_testing which is up

2

Answers


  1. Copy your .env and rename to .env.testing. Change:

    DB_DATABASE=database_testing
    APP_ENV=testing
    

    Inside the new .env.testing file.

    Login or Signup to reply.
  2. on your .env file, change the name of database which you want to launch seed again:

    DB_DATABASE=your_db_name
    

    if not in local environment, change also the name of actual environment :

    APP_ENV=actual_env_name
    

    save modifications and enter command to allow use new env data :

    php artisan config:cache
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search