PHP Tutorial Using Travis CI & Github in 15 Minutes

Interested in Travis CI or learning about Continuous Integration in general but don’t know where to start?  You’ve come to the right place, in this tutorial; I will show you how to easily setup a simple PHP project using Travis CI and Github.

First thing you’ll want to do is fork the sample project from my Github repo.  You can learn more about Travis CI and continuous integration in general from the repo’s main page where I’ve noted some recommend links for further reading.  If you’re not familiar with continuous integration, I highly recommend clicking on the first link, Agile in Practice: Continuous Integration.  Don’t worry if it doesn’t make sense after watching the video.  The red lights and green lights confused me at first.  But all will make sense by the end of this tutorial.

When the fork is finished, go ahead and pull down the code base locally onto your computer.

Back up Github, navigate to the marketplace section of the website.  Once you are there, search for Travis CI.  You should be able to signup for an account for free for open source projects.

 

Once Travis CI is linked up with your Github account,  you should be able to see a screen similar to the one below.  And if you don’t see it, you could just navigate to the Travis CI site.  You’ll want to click on screen name and then click on ‘Accounts’ so that you can assign the repo you want to use Travis CI with.

You’ll want to select the sample Travis CI project you forked earlier.  After that, you should be able to get the Travis CI status link.  This status link is what will provide the build notifications.

 

Once you copy the status link, go to your project and open-up the readme.md file.  You’ll want to replace the link that looks like the one below, with your status link.  Most likely, you’ll just have to change the account name.

[![Build Status](https://travis-ci.org/webvolution/example-travis-ci-php.svg?branch=master)](https://travis-ci.org/webvolution/example-travis-ci-php)

Next thing you’ll want to do is to ensure that the test fails.  This is so you can see Travis CI in action.  Go into Tests/HelloWorldTest.php on line 26 and change:

$this->assertEquals('Hello World', $helloWorld->hello());

to something like:

$this->assertEquals(Good Bye World', $helloWorld->hello());

And go ahead and push back up these changes.  After a few minutes after Travis CI builds your project and runs your test, your repo’s about page should have the following status:


On the Travis CI website, you’ll see that the build failed.  And you should be getting an email about the failed built as well.

At this time, lets go ahead and revert our changes so that the test passes.  Once you revert and push the changes back up to Github and wait a few minutes, your build status should change to a pass.

Get a success build on Travis CI’s website:

 

And a success email:

And there you have it, a sample project using Travis CI in 15 minutes!