计算机科学中所说的代码覆盖率是一种用于衡量特定测试套件对程序源代码测试程度的指标。拥有高代码覆盖率的程序相较于低代码低概率的程序而言测试的更加彻底、包含软件 bug 的可能性更低。
前几天给自己的项目弄了一大堆的图标,看起来是不是很厉害233,这里来说说怎么获得这些图标,当然主要还是标题说的 持续集成和代码覆盖率
https://github.com/huanl-php/container
持续集成 Travis CI
注册和开通Travis CI
首先需要去这个网站注册一个账号,可以直接用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/
配置
需要安装几个依赖 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"/>
其他图标获取
你将你的项目上传到https://packagist.org/后可以在https://poser.pugx.org/这个页面搜索自己的项目获取
关于怎么吧自己的项目提交到packagist下次在写 ┓( ´∀` )┏
文章评论