whateverthing.com

Portfolio and Technology Blog
by Kevin Boyd

UpThing part 5.1, Travis CI

If you've been following open source development for the last little while, you may have heard of Travis, the free continuous integration service for open source projects. I've been interested in trying it out, but I haven't had a project I thought was suitable for testing with it.

Until now! As luck would have it, the most recent UpThing installment added a PHPUnit-based functional test. This means that I've got something I can send to Travis. :)

Travis CI's documentation is a great starting point, with guides for many different types of projects. This post is a glimpse of how easy it can be to get started with Travis integration.

Adding the YAML

Travis follows your project's build criteria from a file called ".travis.yml". In the case of UpThing, I only needed to add a brief one:

    # .travis.yml
    language: php
    php:
      - "5.4"
      - "5.5"
    before_script:
      - composer install.

Travis detects that the project uses PHPunit, so I don't even need to specify the test command.

It's possible to manually specify the test script (for example, if you want to run a collection of tests - phpunit plus php code sniffer plus php mess detector) with the "script:" setting:

    script: bin/my_tests.sh

As long as the script returns exit code "0", Travis will say the build passed.

Badges? We don't got no stinkin' badges!

Now, the fun part: exposing the test badge. With it, you can proudly say "Build Passed" (or less proudly, Build Failed) on the GitHub project page or project website.

The Travis website actually has a tool for generating a badge image link in various formats (HTML, Markdown, etc), but I only needed the Github version:

[![Build Status](https://www.travisci.org/beryllium/UpThing.png)](https://www.travisci.org/beryllium/UpThing)

I plunked this into the Readme file at an appropriate place and crossed my fingers that it would go green on the first try.

Hook, Line, and Sinker

Once I pushed the .travis.yml and Readme changes to Github, I kicked myself.

I'd neglected to follow the docs, so my service hook wasn't set up - a quick authentication on travis-ci.org followed by hitting the "Test Hook" button on the Github service hook page took care of this, and within a few minutes my test ran and I received an email notification of the result:

Build Passed! Yay!

All told, this took me about 30 minutes to set up, and it would've gone even faster if I had followed the docs properly.

The next part in the UpThing series will explore database functionality, which will help clean up a few of the remaining problem areas in the project. I'll make sure to add a few more unit and functional tests to the project as part of that improvement, as well.

Thanks for checking in, and stay tuned for more! :)

« Back to Quick Web Apps: Part Five (PHPUnit)
View the Source on GitHub »

Published: November 4, 2013

Categories: howto, upthing

Tags: coding, dev, development, howto, quick-web-apps, upthing

comments powered by Disqus