Setting up Coveralls.io (with Travis CI and PHPUnit)

Step 1)

Register you GitHub repo with Travis CI and Coveralls.IO.

Step 2)

In your .travis.yml file, add:

before_install:
- composer require phpunit/phpunit:4.8.* satooshi/php-coveralls:dev-master
- composer install --dev

script:
- ./vendor/bin/phpunit --coverage-clover ./tests/logs/clover.xml

after_script:
- php vendor/bin/coveralls -v

Where:

  • before_install: Calls composer and installs PHPUnit 4.8.* + satooshi/php-coveralls.
  • script: Calls the installed version of PHPUnit and generates a clover.xml file in ./tests/logs/clover.xml. (This XML file will be used by PHP-Coveralls.)
  • after_script: Launches satooshi/php-coveralls in verbose mode.

Step 3)

Create a .coveralls.yml file that looks like:

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

Where:

  • coverage_clover: Is the path to the PHPUnit generated clover.xml.
  • json_path: Is where to output a json_file that will be uploaded to the Coveralls API.
  • service_name: Use either travis-ci or travis-pro.

Step 4)

Add badges to your GitHub README.md file.

[![Build Status](https://travis-ci.org/NAMESPACE/REPO.svg?branch=master)](https://travis-ci.org/NAMESPACE/REPO)
[![Coverage Status](https://coveralls.io/repos/NAMESPACE/REPO/badge.svg?branch=master&service=github)](https://coveralls.io/github/NAMESPACE/REPO?branch=master)

Replace NAMESPACE and REPO to match your GitHub repo.

2 thoughts on “Setting up Coveralls.io (with Travis CI and PHPUnit)”

Leave a Reply

Your email address will not be published. Required fields are marked *