Skip to content

Instantly share code, notes, and snippets.

@hxtree
Last active June 20, 2020 02:32
Show Gist options
  • Save hxtree/6b003d7b1ef144df301074aaad656fd6 to your computer and use it in GitHub Desktop.
Save hxtree/6b003d7b1ef144df301074aaad656fd6 to your computer and use it in GitHub Desktop.
PHP code coverage badge

In PHP, the coverage stats are easily provided by PHPUnit. But adding a badge to your repo is another matter.

Coveralls.io

I found this solution to have network outages (e.g. 6/19/2020 10:25pm) and ended up with saying the branch was in a dettached head, which wasn't the case. This made the badge useless as each time the URL needed to be manually updated. The badges look nice, they don't have an icon and say simply coverage.

.coveralls.yml

src_dir: .
service_name: travis-pro

# for php-coveralls
coverage_clover: build/logs/clover.xml
json_path: build/logs/coveralls-upload.json

Codecov

This solution is pretty sketchy as it has you add a bash shell script that is obtained from a get request to work. Talk about security vunerability. Because it's just running on a Travis container I was okay with using this in an open source project. The badge doesn't look good. It has a logo and rather than stating "Coverage" it stats "Codecov 94%" which is unclear to people who do not know about the product.

Add this line to travis YAML

  - bash <(curl -s https://codecov.io/bash)

Overall I'm pretty dissatisfied. I'll probably end up taking the PHPUnit output and generating a GD file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment