Continuous integration testing is awesome and if you build software with a team you really should have it up and running. Travis CI is a free (for public repos) service which connects to your GitHub repositories and automatically runs your tests whenever someone pushes to your repo (all configurable of course). This means you can see at a glance if a PR is failing your tests, and therefore probably breaking your code.
Today, for the first time, I tried setting up a Laravel 5 project in Travis CI and ran into a few issues with the database config. So I thought I’d share how I ended up tweaking my project to get things working properly with Travis.
I wanted to use a different database for testing so I had already set that up. Here is what I had to do to get it to work:
- I created an .env.travis file which correctly sets the environment and holds the Travis database connection info.
- In my .travis.yml I added a few extra before_script’s. One to rename the .env.travis file (cp .env.travis .env) and one to create the testing database (mysql -e ‘create database homestead_test;’).
- Finally in my phpunit.xml I added a line to set the correct database connection <env name=”DB_CONNECTION” value=”testing”/>.