Published
danyal.dk
Published
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)