Reputation: 21
I am using PHP 7.0 and executing tests cases with PHPunit. those are working fine. but when trying to run PHPUnit with --coverage-html option using PHPUnit 6.3.0 or 5.7.23, but it just displays available options rather than generating code coverage report.
I am not using any phpunit.xml file, is that mandatory and if yes then how to put my directory. I have two folders in my project - one for lib (core php class files) and another one for tests which has unit test cases.
Upvotes: 1
Views: 6864
Reputation: 2466
Supposing your code is inside standard directories (e.g. src
for code and tests
for tests), use the following phpuni.xml.dist file
<?xml version="1.0" encoding="UTF-8"?>
<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/7.0/phpunit.xsd"
backupGlobals="false"
colors="true"
bootstrap="vendor/autoload.php"
>
<testsuites>
<testsuite name="Project Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>src</directory>
</whitelist>
</filter>
</phpunit>
then you can run phpunit
to get tests without coverage and phpunit coverage-html build
to get tests with coverage (feel free to replace build
with any directory name you like)
Upvotes: 1