最佳答案
我想使用 PHPUnit 来创建代码覆盖率报告。我已经尝试了很多在网上找到的安装设置。但似乎一切都不顺利。
我使用的是 Laravel 5(> 5.2)和 PHPUnit v. 5.0.10的最新版本。此外,我在运行 PHP 7的 Mac OS X 10.9.5上使用 MAMP。
当我运行集成在 Laravel 发行版中的 PHPUnit 时,会收到以下错误。
$ vendor/bin/phpunit -v
PHPUnit 5.0.10 by Sebastian Bergmann and contributors.
Runtime: PHP 7.0.0
Configuration: /Applications/MAMP/htdocs/myProject/phpunit.xml
Error: No code coverage driver is available`
我的作曲家档案是这样的:
"require-dev": {
"fzaninotto/faker": "~1.4",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": "5.0.*",
"phpunit/php-code-coverage": "^3",
"symfony/css-selector": "2.8.*|3.0.*",
"symfony/dom-crawler": "2.8.*|3.0.*"
},
我还尝试了以下命令:
/Applications/MAMP/bin/php/php7.0.0/bin/phpdbg -qrr ../../../htdocs/myProject/vendor/bin/phpunit -v
这似乎很好地设置了代码覆盖率驱动程序,但结果却是一个例外:
$ /Applications/MAMP/bin/php/php7.0.0/bin/phpdbg -qrr ../../../htdocs/myProject/vendor/bin/phpunit -v
PHPUnit 5.0.10 by Sebastian Bergmann and contributors.
Runtime: PHPDBG 7.0.0
Configuration: /Applications/MAMP/htdocs/myProject/phpunit.xml
[PHP Fatal error: Uncaught ErrorException: include(/Applications/MAMP/htdocs/myProject/app/Exceptions/Handler.php): failed to open stream: Too many open files in /Applications/MAMP/htdocs/myProject/vendor/composer/ClassLoader.php:412
Stack trace:
...
Xml 看起来如下:
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="bootstrap/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Application Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<logging>
<log type="coverage-html" target="./tests/codeCoverage" charset="UTF-8"/>
</logging>
<filter>
<whitelist>
<directory suffix=".php">app/</directory>
</whitelist>
</filter>
<php>
<env name="APP_ENV" value="testing"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
</php>
</phpunit>
有没有可能使用伴随 Laravel 框架的 PHPUnit 以及代码覆盖率?我应该如何设置和使用它?
非常感谢你的帮助。