PHPUnit 9.x coverage reporting

Posted: 2020-11-24 13:25:46 by Alasdair Keyes

Direct Link | RSS feed


PHPUnit 9.x coverage reporting

I started a new Laravel project today and used the latest Laravel 8.x release. After installation I go through and update a few things such as adding in phpmd, phpcs, laravel-debugbar and also setup PHPUnit code coverage reports that I can hook into gitlab's code coverage reporting tools.

After making the changes to my phpunit.xml file I was greeted with the following error

PHPUnit 9.4.3 by Sebastian Bergmann and contributors.

  Warning - The configuration file did not pass validation!
  The following problems have been detected:

  Line 29:
  - Element 'log': This element is not expected.

  Test results may not be as expected.


..                                                                  2 / 2 (100%)

Time: 00:00.386, Memory: 30.00 MB

OK (2 tests, 2 assertions)

Line 29 is part of the <logging> block I added in for coverage reporting.

<phpunit ....>
    <logging>
        <log type="coverage-text" target="php://stdout" showUncoveredFiles="true"/>
        <log type="coverage-html" target="build/logs/html/" showUncoveredFiles="true"/>
    </logging>
</phpunit>

After reading through the documentation for PHPUnit 9 (which is what is pulled in with Composer for Laravel 8) this is changed from logging to report and is now under the testsuites tag and has an changed syntax.

<phpunit ....>
    <testsuites processUncoveredFiles="true">
        ...
        <report>
            <text outputFile="php://stdout"/ showUncoveredFiles="true">
            <html outputDirectory="build/logs/html/"/>
        </report>
    <testsuites>
</phpunit>

I'm probably not going to be the only one caught out by this, so I thought it warranted a post.


If you found this useful, please feel free to donate via bitcoin to 1NT2ErDzLDBPB8CDLk6j1qUdT6FmxkMmNz

© Alasdair Keyes

IT Consultancy Services

I'm now available for IT consultancy and software development services - Cloudee LTD.



Happy user of Digital Ocean (Affiliate link)


Version:master-3093fcc3d4


Validate HTML 5