定制 blar/php-coveralls 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

blar/php-coveralls

最新稳定版本:v0.6.1

Composer 安装命令:

composer require blar/php-coveralls

包简介

PHP client library for Coveralls API

README 文档

README

Build Status Coverage Status Dependency Status

Latest Stable Version Total Downloads

PHP client library for Coveralls.

API doc

API doc is generated by ApiGen

Prerequisites

Installation

To install php-coveralls with Composer, just add the following to your composer.json file:

// composer.json
{
    "require-dev": {
        "satooshi/php-coveralls": "dev-master"
    }
}

Then, you can install the new dependencies by running Composer’s update command from the directory where your composer.json file is located:

# install
$ php composer.phar install --dev
# update
$ php composer.phar update satooshi/php-coveralls --dev

# or you can simply execute composer command if you set it to
# your PATH environment variable
$ composer install --dev
$ composer update satooshi/php-coveralls --dev

You can see this library on Packagist.

Composer installs autoloader at ./vendor/autoloader.php. If you use php-coveralls in your php script, add:

require_once 'vendor/autoload.php';

If you use Symfony2, autoloader has to be detected automatically.

Or you can use git clone command:

# HTTP
$ git clone https://github.com/satooshi/php-coveralls.git
# SSH
$ git clone git@github.com:satooshi/php-coveralls.git

Configuration

Currently support clover style coverage report. php-coveralls collect coverage information from clover.xml.

PHPUnit

Make sure that phpunit.xml.dist is configured to generate "coverage-clover" type log named clover.xml like the following configuration:

<?xml version="1.0" encoding="UTF-8"?>
<phpunit ...>
    <logging>
        ...
        <log type="coverage-clover" target="build/logs/clover.xml"/>
        ...
    </logging>
</phpunit>

You can also use --coverage-clover CLI option.

phpunit --coverage-clover build/logs/clover.xml

phpcov

Above settings are good for almost projects If your test suite is executed once a build and is not devided into several parts. But if your test suite is configured as parallel task or generates multiple coverage reports through a build, you can use either coverage_clover configuration in .coveralls.yml (see below coverage clover configuration section) to specify multiple clover.xml or phpcov for processing coverages reports.

composer.json

phpcov is not ready for Packagist yet but you can install it via PEAR channel:

    "repositories": [
        {
            "type": "package",
            "package": {
                "name": "sebastianbergmann/phpcov",
                "version": "1.1.0",
                "dist": {
                    "url": "https://github.com/sebastianbergmann/phpcov/archive/1.1.0.zip",
                    "type": "zip"
                },
                "source": {
                    "url": "https://github.com/sebastianbergmann/phpcov.git",
                    "type": "git",
                    "reference": "1.1.0"
                },
                "bin": [
                    "phpcov.php"
                ]
            }
        }
    ],
    …
    "require-dev": {
        "satooshi/php-coveralls": "dev-master",
        "sebastianbergmann/phpcov": "1.1.0"
    },
phpunit configuration

Make sure that phpunit.xml.dist is configured to generate "coverage-php" type log:

<?xml version="1.0" encoding="UTF-8"?>
<phpunit ...>
    <logging>
        ...
        <log type="coverage-php" target="build/cov/coverage.cov"/>
        ...
    </logging>
</phpunit>

You can also use --coverage-php CLI option.

# use --coverage-php option instead of --coverage-clover
phpunit --coverage-php build/cov/coverage-${component_name}.cov
phpcov configuration

And then, execute phpcov.php to merge coverage.cov logs.

# get information
php vendor/bin/phpcov.php --help

# merge coverage.cov logs under build/cov
php vendor/bin/phpcov.php --merge --clover build/logs/clover.xml --whitelist /path/to/src build/cov

# in case of memory exhausting error
php -d memory_limit=-1 vendor/bin/phpcov.php ...

clover.xml

php-coveralls collects count attribute in a line tag from clover.xml if its type attribute equals to stmt. When type attribute equals to method, php-coveralls excludes its count attribute from coverage collection because abstract method in an abstract class is never counted though subclasses implement that method which is executed in test cases.

<!-- this one is counted as code coverage -->
<line num="37" type="stmt" count="1"/>
<!-- this one is not counted -->
<line num="43" type="method" name="getCommandName" crap="1" count="1"/>

Travis CI

Add php vendor/bin/coveralls to your .travis.yml at after_script.

# .travis.yml
language: php
php:
  - 5.5
  - 5.4
  - 5.3

matrix:
  allow_failures:
    - php: 5.5

before_script:
  - curl -s http://getcomposer.org/installer | php
  - php composer.phar install --dev --no-interaction

script:
  - mkdir -p build/logs
  - php vendor/bin/phpunit -c phpunit.xml.dist

after_script:
  - php vendor/bin/coveralls
  # or enable logging
  - php vendor/bin/coveralls -v

CircleCI

Add pecl install xdebug to your circle.yml at dependencies section since currently Xdebug extension is not pre-installed. composer and phpunit are pre-installed but you can install them manually in this dependencies section. The following sample uses default ones.

machine:
  php:
    version: 5.4.10

## Customize dependencies
dependencies:
  override:
    - mkdir -p build/logs
    - composer install --dev --no-interaction
    - pecl install xdebug
    - cat ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini | sed -e "s/;//" > xdebug.ini
    - mv xdebug.ini ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini

## Customize test commands
test:
  override:
    - phpunit -c phpunit.xml.dist

Add php vendor/bin/coveralls to the "Test commands" textarea on Web UI (Edit settings > Tests > Test commands textarea).

COVERALLS_REPO_TOKEN=your_token php vendor/bin/coveralls

Please note that COVERALLS_REPO_TOKEN should be set in the same line before coveralls command execution. You can not export this variable before coveralls command execution in other command since each command runs in its own shell and does not share environment variables (see reference on CircleCI).

Codeship

You can configure CI process for Coveralls by adding the following commands to the textarea on Web UI (Project settings > Test tab).

In the "Modify your Setup Commands" section:

curl -s http://getcomposer.org/installer | php
php composer.phar install --dev --no-interaction
mkdir -p build/logs

In the "Modify your Test Commands" section:

php vendor/bin/phpunit -c phpunit.xml.dist
php vendor/bin/coveralls

Next, open Project settings > Environment tab, you can set COVERALLS_REPO_TOKEN environment variable.

In the "Configure your environment variables" section:

COVERALLS_REPO_TOKEN=your_token

From local environment

If you would like to call Coveralls API from your local environment, you can set COVERALLS_RUN_LOCALLY envrionment variable. This configuration requires repo_token to specify which project on Coveralls your project maps to. This can be done by configuring .coveralls.yml or COVERALLS_REPO_TOKEN environment variable.

$ export COVERALLS_RUN_LOCALLY=1

# either env var
$ export COVERALLS_REPO_TOKEN=your_token

# or .coveralls.yml configuration
$ vi .coveralls.yml
repo_token: your_token # should be kept secret!

php-coveralls set the following properties to json_file which is sent to Coveralls API (same behaviour as the Ruby library will do except for the service name).

  • service_name: php-coveralls
  • service_event_type: manual

CLI options

You can get help information for coveralls with the --help (-h) option.

php vendor/bin/coveralls --help
  • --config (-c): Used to specify the path to .coveralls.yml. Default is .coveralls.yml
  • --verbose (-v): Used to show logs.
  • --dry-run: Used not to send json_file to Coveralls Jobs API.
  • --exclude-no-stmt: Used to exclude source files that have no executable statements.

.coveralls.yml

php-coveralls can use optional .coveralls.yml file to configure options. This configuration file is usually at the root level of your repository, but you can specify other path by --config (or -c) CLI option. Following options are the same as Ruby library (see reference on coveralls.io).

  • repo_token: Used to specify which project on Coveralls your project maps to. This is only needed for repos not using CI and should be kept secret
  • service_name: Allows you to specify where Coveralls should look to find additional information about your builds. This can be any string, but using travis-ci or travis-pro will allow Coveralls to fetch branch data, comment on pull requests, and more.

Following options can be used for php-coveralls.

  • src_dir: Used to specify where the root level of your source files directory is. Default is src.
  • coverage_clover: Used to specify the path to clover.xml. Default is build/logs/clover.xml
  • json_path: Used to specify where to output json_file that will be uploaded to Coveralls API. Default is build/logs/coveralls-upload.json.
# .coveralls.yml example configuration

# same as Ruby lib
repo_token: your_token # should be kept secret!
service_name: travis-pro # travis-ci or travis-pro

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

coverage clover configuration

You can specify multiple clover.xml logs at coverage_clover. This is useful for a project that has more than two test suites if all of the test results should be merged into one json_file.

#.coveralls.yml

# single file
coverage_clover: build/logs/clover.xml

# glob
coverage_clover: build/logs/clover-*.xml

# array
# specify files
coverage_clover: 
  - build/logs/clover-Auth.xml
  - build/logs/clover-Db.xml
  - build/logs/clover-Validator.xml

Change log

See changelog

Wiki

See wiki

blar/php-coveralls 适用场景与选型建议

blar/php-coveralls 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 192 次下载、GitHub Stars 达 0, 最近一次更新时间为 2015 年 04 月 19 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「test」 「github」 「ci」 「coverage」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 blar/php-coveralls 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 blar/php-coveralls 我们能提供哪些服务?
定制开发 / 二次开发

基于 blar/php-coveralls 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 192
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 13
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 67
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-04-19