Let us promote youWe accept Sponsored PostAdvertise here

Travis CI: Continuous Integration for PHP Project

While the last article was "Get Started With Test Driven Development: Unit Testing With PHPUnit?. ", this article will help to getting started with Travis, which make collaboration with your team breeze.

Travis CI is an automation tool which allows team to commit and build project easily. Once you have configured your GITHUB project, whenever there is a new commit, Travis CI will sync code from GITHUB repository and initialize the build process. This way developer don't need to worry about running PHPUnit every time. Travis builds & deploy your software rapidly. I personally like Travis CI as an automation tool because it is easy to integrate, clean UI, plenty of features whereas getting started with other automation tool little tricky.

Travis CI supports multiple programming languages, you just need to define in your .travis.yml file (in root directory of the project) that which language project written and remaining Travis will take care. I will not be able to explain all language and environment they support, you can find from their documentation. In this article we will focus on "How to integrate Travis CI (continuous integration) tool with PHP project on GITHUB repository."

Get Started With Travis CI:

Below are neat steps for Integrating Travis CI in your GITHUB projects.

Step1: Travis UI- Sign in:

Sign in into Travis CI Tool using your GITHUB account.

Step2: Travis Setup- Activating for the repository:

Setting up Travis is very simple and straight forward. Once you logged into Travis, go to profile page and you can see your entire GITHUB repositories already synchronized and displaying into the page. Choose which repository you want to build, activate/deactivate it using simple "on"/"off" button as below screenshot.

If you have created a new repository into GITHUB under the same account and it is not displaying into Travis profile page, then simply click on "Sync" button as highlighted in above screenshot. Once you activate Travis for your repository every time you commit into the repository Travis will trigger build process.

Step3: Travis Aware- Add a .travis.yml file into your Repository

Different project will different environment setup. To inform Travis CI under what environment you require to build and test your project, you need to add a configuration file named .travis.yml in root directory of your GITHUB project. Below sample example,

Above .travis.yml configuration file informs Travis that it is PHP based project, Travis should run tests against 4 different versions of PHP as well as in HVVM. It also tells that project will accept failure in PHP v7.0, before build it should update the composer version. It will run all our tests suits located into tests directory.

By default on every Build Failure Travis will notify you via email. However you can stop notification by changing the notification flag as "false" as above screenshot.

To verify yml config file use http://lint.travis-ci.org/.

A great way to learn about .travis.yml is browse through various open source projects in GITHUB repositories that are uses Travis CI for build process. Here some example below,

Step4: Adding Travis CI Service into GITHUB:

Goto your Travis profile page by clicking Account, find token left hand side. This token will be used to identify your github project by Travis CI. See screenshot below,

Copy the token and while adding a service paste into the box, goto your repository settings, under "Webhooks & Services". sample screenshot below to find location.

Step5: Travis Build- Triggering Build Process:

Now Travis is ready to build our awesome project, every time we push into GITHUB repository Travis will start building the project. You can see the build process or status in your travis page, under your githubu-username/repository-name. For example below.


See the build status on same page. You can see below screenshot as all tests passes for Cygnite it shows green, else it will display as red.

You can manually restart the build by clicking a button as above screenshot.

Build History:

Click on Build history tab to see history of builds it processed. Sample screenshot below.

Learn More:

Post a comment