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 a skilled programmer specializing in Vue.js/Nuxt.js for front-end development and PHP Laravel for back-end solutions. I have a strong focus on API design and development, complemented by experience in web server setup and maintenance. My versatile expertise ensures seamless creation and maintenance of web applications, covering everything from intuitive user interfaces to robust server-side functionality. Passionate about coding and driven by a lifelong learning mindset, I invite you to explore more at danyal.dk.