1

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.

12
  • 1
    --coverage-html requires an argument -- the directory to store the coverage report in. Commented Nov 8, 2017 at 19:17
  • I tried using directory name as argument phpunit --coverage-html tests Commented Nov 8, 2017 at 19:18
  • 1
    Post your command line. Commented Nov 8, 2017 at 19:19
  • @AlexHowansky phpunit --coverage-html tests Commented Nov 8, 2017 at 19:20
  • 1
    It's all in the docs. Commented Nov 8, 2017 at 19:29

1 Answer 1

1

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)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.