爱编码的Farmer

  • 主页
  • 编程开发
  • 运营维护
  • 随心笔记
  • 留言页面
  • 打赏
爱编码的Farmer
我是Farmer,我为自己代言
  1. 首页
  2. 编程开发
  3. 教程笔记
  4. 正文

php持续集成 + 代码覆盖率

2018年4月23日 5297点热度 2人点赞 0条评论

计算机科学中所说的代码覆盖率是一种用于衡量特定测试套件对程序源代码测试程度的指标。拥有高代码覆盖率的程序相较于低代码低概率的程序而言测试的更加彻底、包含软件 bug 的可能性更低。


前几天给自己的项目弄了一大堆的图标,看起来是不是很厉害233,这里来说说怎么获得这些图标,当然主要还是标题说的 持续集成和代码覆盖率

https://github.com/huanl-php/container

持续集成 Travis CI

注册和开通Travis CI

https://travis-ci.org/

首先需要去这个网站注册一个账号,可以直接用github注册(最好也是用github注册,可以直接检测到你的项目)

鼠标移动到头像的位置点击profile,进入自己的主页,会显示你的项目

还可以绑定Organizations 组织

很显然,我们想持续集成一个项目,就点那个开关,吧开关打开,这第一步算是完成了

配置CI

然后在项目下面新建一个.travis.yml文件,这里的Travis CI的配置文件

这是我的项目的配置文件

language: php
php:
  - '7.1'
  - '7.2'

install:
  - mkdir -p build/logs
  - composer install

script:
  - phpunit

after_success:
  - travis_retry php vendor/bin/php-coveralls

然后push我们就可以获得这个图标(然后构建成功就可以有这个图标了,失败也有的,但是图标是失败的图标了)

图标代码在项目里面获取

代码覆盖率 Coveralls

注册和开通 Coveralls

这里是获取这个图标的

首先也需要去注册一个账号 https://coveralls.io/

和Travis CI一样的操作

配置

需要安装几个依赖 phpcov和php-coveralls,当然也要安装phpunit

这个是我的依赖配置

  "require-dev": {
    "phpunit/phpunit": "^7.1",
    "phpunit/phpcov": "^5.0",
    "php-coveralls/php-coveralls": "^2.0"
  },

phpunit.xml

<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
         backupStaticAttributes="false"
         bootstrap="vendor/autoload.php"
         colors="true"
         convertErrorsToExceptions="true"
         convertNoticesToExceptions="true"
         convertWarningsToExceptions="true"
         processIsolation="false"
         beStrictAboutTestsThatDoNotTestAnything="true"
         stopOnFailure="false">
    <testsuites>
        <testsuite name="Test">
            <directory>./tests</directory>
        </testsuite>
    </testsuites>
    <filter>
        <whitelist>
            <directory>./</directory>
            <exclude>
                <directory>./build</directory>
                <directory>./tests</directory>
                <directory>./vendor</directory>
            </exclude>
        </whitelist>
    </filter>
    <logging>
        <log type="coverage-clover" target="build/logs/clover.xml"/>
        <log type="junit" target="build/logs/junit.xml" logIncompleteSkipped="false"/>
    </logging>
</phpunit>

配置项目主要是

    <filter>
        <whitelist>
            <directory>./</directory>   //需要测试的目录
            <exclude>   //例外
                <directory>./build</directory>
                <directory>./tests</directory>
                <directory>./vendor</directory>
            </exclude>
        </whitelist>
    </filter>
    <log type="coverage-clover" target="build/logs/clover.xml"/>

然后push可以在项目页面获取图标

其他图标获取

你将你的项目上传到https://packagist.org/后可以在https://poser.pugx.org/这个页面搜索自己的项目获取

关于怎么吧自己的项目提交到packagist下次在写 ┓( ´∀` )┏

标签: github PHP phpunit
最后更新:2018年4月23日

Farmer

不敢说什么

点赞
< 上一篇
下一篇 >

文章评论

取消回复

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据。

COPYRIGHT © 2021 icodef.com. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang

湘ICP备19008073号