markdown [代码覆盖率Phpunit]安装Xdebug并使用Phpunit运行代码覆盖率#xdebug #phpunit #code #coverage

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown [代码覆盖率Phpunit]安装Xdebug并使用Phpunit运行代码覆盖率#xdebug #phpunit #code #coverage相关的知识,希望对你有一定的参考价值。

# Phpunit Code Coverage

### Install Xdebug

Install Xdebug and copy the line in the output that will need to be copied in the php.ini (`zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20180731/xdebug.so`).

```bash
pecl install xdebug
```


Create the php.ini file and set Xdebug

```
# You can run `php --ini` inside terminal to see which files are used by PHP in CLI mode.

cp /usr/local/etc/php/php.ini-development /usr/local/etc/php/php.ini

apt-get install vim -y
vi /usr/local/etc/php/php.ini
```

Insert this line in the php.ini file: 

```
zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20180731/xdebug.so
```
Note: it could be a different path, so use the one returned by the installation of Xdebug.

### Run Code Coverage

Copy this in the phpunit.xml file:

```xml
    <filter>
        <whitelist processUncoveredFilesFromWhitelist="true">
            <directory suffix=".php">./app</directory>
        </whitelist>
    </filter>
```

Finally run:

```bash
# Copy the filters in the build folder
php vendor/bin/phpunit --dump-xdebug-filter build/xdebug-filter.php

# Run the coverage report
php vendor/bin/phpunit --prepend build/xdebug-filter.php --coverage-html build/coverage-report
```

以上是关于markdown [代码覆盖率Phpunit]安装Xdebug并使用Phpunit运行代码覆盖率#xdebug #phpunit #code #coverage的主要内容,如果未能解决你的问题,请参考以下文章

phpunit 单元测试之代码覆盖率

xdebug : phpunit 代码覆盖的致命错误

Laravel 5:PHPUnit 和没有可用的代码覆盖驱动程序

markdown [漂亮的打印机] Phpunit Pretty Printer安装#phpunit #laravel #prettyprinter #intsall #php

Symfony3.4:PHPUnit并且没有可用的代码覆盖驱动程序[关闭]

如何更新 phpunit 6 和代码覆盖率 5