archived-codacy / php-codacy-coverage

Phar for uploading PHP code coverage to Codacy
https://www.codacy.com
MIT License
44 stars 18 forks source link

Deprecated

This repository is no longer maintained. As an alternative, check codacy-coverage-reporter to send your test coverage results to your Codacy dashboard.

Codacy Badge Codacy Badge Circle CI Latest Stable Version

Codacy PHP Coverage Reporter

Codacy coverage support for PHP. Get coverage reporting and code analysis for PHP from Codacy.

Prerequisites

Installation

Setup codacy-coverage with Composer, just add the following to your composer.json:

// composer.json
{
    "require-dev": {
        "codacy/coverage": "dev-master"
    }
}

Download the dependencies by running Composer in the directory of your composer.json:

# install
$ php composer.phar install --dev
# update
$ php composer.phar update codacy/coverage --dev

codacy-coverage library is available on Packagist.

Add the autoloader to your php script:

require_once 'vendor/autoload.php';

Note: We have php5-curl dependency, if you have issues related to curl_init() please install it with:

sudo apt-get install php5-curl

Alternative Installation (using phar)

Setup codacy-coverage as phar, you can simply download a pre-compiled and ready-to-use version as a phar to any directory. Simply download the latest codacy-coverage.phar file from our releases page:

Latest release

That's it already.

Updating Codacy

To update Codacy, you will need your project API token. You can find the token in Project -> Settings -> Integrations -> Project API.

Then set it in your terminal, replacing %Project_Token% with your own token:

export CODACY_PROJECT_TOKEN=%Project_Token%

Note: You should keep your API token well protected, as it grants owner permissions to your projects.

To send coverage in the enterprise version you should:

export CODACY_API_BASE_URL=<Codacy_instance_URL>:16006

Usage

Run vendor/bin/codacycoverage to see a list of commands.

Basic usage for Clover format:

vendor/bin/codacycoverage clover

Basic usage for PHPUnit XML format:

php vendor/bin/codacycoverage phpunit

By default we assume that

Optional parameters:

You can specify the path to your report with the second parameter:

Even more control:

Circle CI

This project sends its own coverage during the build in circleCI. Feel free to check our circle.yml, and send your coverage as a step of your build process.

Travis CI

Add codacycoverage to your .travis.yml:

# .travis.yml
language: php

# Do not forget to provide your CODACY_PROJECT_TOKEN as described in https://docs.travis-ci.com/user/environment-variables/#Defining-Variables-in-Repository-Settings

php:
  - 5.3
  - 5.4
  - 5.5
  - 5.6
  - hhvm

# In case of timeouts and build failures you may want to prepend 'travis_retry' to the following commands:
before_script:
  - curl -s http://getcomposer.org/installer | php
  - php composer.phar install -n

script:
  - php vendor/bin/phpunit --coverage-clover build/coverage/xml

after_script:
  - php vendor/bin/codacycoverage clover build/coverage/xml

Troubleshooting

If you have a fatal error regarding curl_init():

PHP Fatal error:  Uncaught Error: Call to undefined function Codacy\Coverage\Util\curl_init() in /src/Codacy/Coverage/Util/CodacyApiClient.php:30

Run: sudo apt-get install php5-curl

What is Codacy?

Codacy is an Automated Code Review Tool that monitors your technical debt, helps you improve your code quality, teaches best practices to your developers, and helps you save time in Code Reviews.

Among Codacy’s features:

Codacy also helps keep track of Code Coverage, Code Duplication, and Code Complexity.

Codacy supports PHP, Python, Ruby, Java, JavaScript, and Scala, among others.

Free for Open Source

Codacy is free for Open Source projects.

License

MIT