So I jumped in to get it running for Ushahidi 3.0
We’ve been running some tests through Jenkins already, but I’ve largely been doing manual runs locally. Travis-CI integrates with Github automatically, so I figured that was the easiest path to integration.
First impression: its really really easy to get started, and the docs were great.
- Log in with Github, turn on builds for the repo
- Add .travis.yml file, configure the language, and PHP version to use
- Push to github
- Wait for builds to run
Installing Behat, Mink and Guzzle.
Running PHPUnit and Behat
By default Travis-CI would just run PHPUnit. We use both PHPUnit and Behat so we have to run both. That’s as simple 2 extra lines in the config
The next steps get little trickier.
Bootstrapping the DB wasn’t too bad. Add mysql to ‘services’ and add a couples of ‘before_script’ steps:
We’re running API tests by hitting a web server with Guzzle. This means I need a web server running in my Travis-CI build. Theres a few docs on doing this for other projects but not so much PHP, and the examples I found were ugly at best.
In the end I’m running the built in PHP dev server, and restricting builds to PHP 5.4.
A few other bits of bootstrapping and I had working builds:
Not quite done..
I quickly realised that my code actually had some issues:
I’ve been building on PHP 5.3, so immediatey hit a bunch of ‘Array to string conversion’ bugs in PHP 5.4. The main culprit for this was a bug in Kohana 3.3, so I’ve ported a rough fix from the develop branch.
I develop on OS X using a Vagrant box that mounts project code over NFS. The side effect of this is that my filesystem isn’t really case sensitive. Kohana uses PSR-0 autoloading, so the filename and class names need to match. The Travis builds run on a standard Ubuntu box: I suddenly hit errors about missing classes, etc.
Fixing this was a bit slow and painful but actually a win in the long run. The first linux user to fire up the code base would have hit these issues immediately!
In the end getting this set up took longer than expected, but I’m pretty pleased with the result. I’ve merged these changes into all my work-in-progress branches and fixed a few bugs as a result already. I’ll call that success.