Laravel

PHPUnit test environment with Laravel 5.5

Laravel provides fully covered online documentation.
But if you are still wondering, how to run PHPUnit tests in Laravel 5.5 with testing environment config.

 

It’s quite simple:
The proper way is to create testing environment file name it .env.testing. In this file you can define testing configuration including database settings.

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=db_testing
DB_USERNAME=testing_user
DB_PASSWORD=testing_user_password

Then run following commands:

  • php artisan config:cache –env=testing
    (clear config cache for testing)
  • php artisan migrate:refresh –env=”testing”
    (prepare test database)
  • php artisan migrate:refresh –seed –env=”testing”
    (prepare test database & run seeder if you have created any seeders)

Laravel 5.5 official documentation link.

Author: Danyal
I'm skilled programmer with expertise in Vue.js/Nux.js for front-end development and PHP Laravel for back-end development. I excel in building APIs and services, and also have experience in web server setup & maintenance. My versatile skill set allows you to develop and maintain web applications effectively, from the user interface to the server-side functionality. I love coding with never ending learning attitude, thanks for visiting danya.dk