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.


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.

About the author

Danyal Ali Butt

I'm working as programmer since 2002. Born, grew up, studied and worked in Pakistan now Im located in Denmark since 2006.

View all posts