March 27, 2014Reynald Mandel3 min read
Wanna kick start a project? Wanna get straight to the code as fast as possible, without spending too much time on the overheads (creating tests environments and so on...)? Well, let's build a quick ready-to-go Travis environment with a mysql database for your tests! 3 minutes starting now!
Travis automatically builds virtual machines to run your tests upon request. It has been designed for developers: their virtual machines already come with a good base configuration, leaving you very few work to do to customize it to your needs.
First, log in to Travis with your GitHub account. Travis' services are free for open source projects, but you will have to pay for private repositories. To automate your tests each time you push a commit to GitHub, you will need to activate the hook between these two services: go to your Travis' repository list and activate the switch button for the project you want. You do not have anything to configure, everything is done automatically.
There you have a handy link to the GitHub repository's service hooks authorization. On this page, you can see a list of services that can hook to GitHub. Scroll down and click on "Travis". I advise you to check that the hook is effectively triggered by pressing the test button, it's fun and it's free ;)
Now that Travis is notified every time you push a commit, it will look for your instructions in the .travis.yml file at the root of the project. Among other things, this file describes what you want to test, how, and what Travis must do before and after the tests. Here is a base ready-to-go Travis configuration file for Symfony2 projects:
php: - 5.5
notifications: email: - email@example.com ;)
The first lines are self-explanatory, just note that you can specify more PHP versions than only 5.5. After that, you can see the commands we ask Travis to run before it launches his tests:
Under the 'script' section, you can define which command(s) should be used to launch the tests. If you do not specify any, Travis default will be 'phpunit' without arguments. But in general for Symfony2 projects, your PHPUnit configuration files are in app/.
The last line is used to tell Travis which emails should receive his success/failure notifications for this repository. Pretty useful when you deal with many projects!
For reference, here is what your parameters.yml.travis file should look like:
parameters: database_user: travis database_password: ~ # Other parameters
Here it is! The 3-minute explanation is now ending and I hope that it has set your tests on track!
No more excuses for not having an up-and-running continuous integration ;)
Web Developer at Theodo