Display Build Status and Test Coverage Badges for a Laravel Project

A guide I wished I had

Nwachukwu Chibuike
Dec 8, 2020 · 3 min read

In search of a new developer role, I found myself building various projects just to scale through multiple interviews. One, in particular, was a Laravel project that included a specific instruction to display both build status and code coverage report as badges in my readme.md file.

I searched for help online but couldn’t find any that gave the full guide to solving this problem, most only provided solutions for build status while ignoring the code coverage aspect. I had to figure this out and time was running out.

This below is what I intended to achieve and I would be showing how I accomplished this

Setup repo with Travis CI and Coveralls

If you haven’t already, the first thing you need to do is to move over to Travis and log in using your GitHub account. Once logged in hit the “Add New Repository” button to activate your repo. Repeat this procedure at Coveralls.io.

Configure PHPUnit and Coveralls

Luckily for us, Laravel comes shipped with PHPUnit. This tutorial assumes you have some tests written already. If not, it’s as simple as checking out the Laravel docs for writing tests.

We’re also going to install Coveralls, which we’ll use to host the coverage report by simply require it:

composer require php-coveralls/php-coveralls

Or by adding the following line to the require block of your composer.json file.

"php-coveralls/php-coveralls": "^1.1"

This would add it to our composer.json file as a dependency.

Create a .travis.yml and .coveralls.yml

We would now proceed to create a Travis configuration file(.travis.yml) at the root of our Laravel project to get Travis CI set up. Also we would be creating a .coveralls.yml which would be used to set up the path to our clover.xml

Here’s what my .travis.yml looks like: I’m setting the language, the version of php, and telling it which additional script to run.

Here’s what my .coveralls.yml looks like: I’m assuming your phpunit.xml saves its clover.xml at the build/logs path.

coverage_clover: build/logs/clover.xml
json_path: build/logs/coveralls-upload.json
service_name: travis-ci

For the benefit of doubt, this is how my phpunit.xml and .env.example files looks like:

Deploy code and display badges

Here’s the code for both of the badges I used in my readme.md file. Both Travis and Coveralls will supply embed links for these.

Travis CI Build Badge

[![Build Status](https://travis-ci.com/chyke007/credible.svg?branch=master)](https://travis-ci.com/chyke007/credible)

Coveralls Code Coverage Badge

[![Coverage Status](https://coveralls.io/repos/github/chyke007/credible/badge.svg?branch=master)](https://coveralls.io/github/chyke007/credible?branch=master)

Now once we push our code to GitHub with this setup it should send the build off to Travis, and Travis should send the coverage off to Coveralls.

That is all, in general it was an exciting adventure, hopefully this serves as a guide to someone, a guide I wish I had!

Geek Culture

Proud to geek out.

Sign up for Geek Culture Hits

By Geek Culture

Subscribe to receive top 10 most read stories of Geek Culture — delivered straight into your inbox, once a week. Take a look.

By signing up, you will create a Medium account if you don’t already have one. Review our Privacy Policy for more information about our privacy practices.

Check your inbox
Medium sent you an email at to complete your subscription.

Geek Culture

A new tech publication by Start it up (https://medium.com/swlh).

Nwachukwu Chibuike

Written by

Full-stack developer, technical writer and lover of Jamstack. Passionate about lifelong learning.

Geek Culture

A new tech publication by Start it up (https://medium.com/swlh).

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store