I would like to use PHPUnit to create code coverage reports. I have tried a lot of installation setups found on the web. But nothing seems to work out.
I use the latest version of Laravel 5 (>5.2) and PHPUnit v. 5.0.10. Further, I use MAMP on Mac OS X 10.9.5 running PHP 7.
When I run PHPUnit that is integrated in my Laravel distribution, I receive the following error.
$ 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`
My composer file looks like:
"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.*"
},
I have also tried the following command:
/Applications/MAMP/bin/php/php7.0.0/bin/phpdbg -qrr ../../../htdocs/myProject/vendor/bin/phpunit -v
This seems to set up the code coverage driver well, but it ends up in an exception:
$ /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:
...
The phpunit.xml looks as follows:
<?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>
Is it possible to use PHPUnit that comes with the Laravel framework together with code coverage? How should I set it up and use it?
Thanks a lot for your help.
It seems like you are missing the Xdebug extension. If you're using homebrew you can install it like:
brew install php70-xdebug
After that, don't forget to edit your php.ini file to enable the extension.
php -i | grep xdebug
After checking that xdebug is enabled you should be able to do code coverage