PHPUnit warning - No filter is configured, code coverage will not be processed
Asked Answered
C

5

22

I'm trying to generate coverage html file with PHPUnit. I get a warning: 'No filter is configured, code coverage will not be processed' and coverage file isn't generated.

This is phpunit.xml file

<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
  <testsuites>
    <testsuite name="Application Test Suite">
      <directory>./phpUnitTutorial</directory>
    </testsuite>
  </testsuites>
</phpunit>

Can anyone help?

Cordeliacordelie answered 17/9, 2020 at 14:54 Comment(1)
Could be worth having a look at some of the other questions about code coverage to see what they use - https://mcmap.net/q/586948/-phpunit-code-coverageMiscall
P
43

I suggest you use the configuration generator (phpunit --generate-configuration). It will ask you a couple of questions and then generate the right configuration for you.

Polyvalent answered 17/9, 2020 at 15:21 Comment(4)
Oh! That's real shame for me to admit that my coverage folder was created before asking question. I was looking for index.html file in root directory and I didn't notice that there was created new directory here. But thank You for your respond anyway. It's good to know this way, especially as I'm still beginner in PHPUnit.Cordeliacordelie
Ok. After few tests (on generating coverage folder) I see that phpunit.xml needs not empty 'coverage' tag with specified valid source directory inside to generate coverage directory. Given solution generates this tag.Cordeliacordelie
Doesn't really answer the question though, does it? Which bit was missing? That would have been the answer to the question. And then maybe a "hey did you know that if you use the configuration generator..." etc as a footnote.Lumbago
Details link: github.com/sebastianbergmann/phpunit/issues/5294Podolsk
Z
19

I added the following to my PHPUnit 9.5 configuration file between the <phpunit> tags:

<coverage>
    <include>
        <directory suffix=".php">src</directory>
    </include>
</coverage>
Ziegfeld answered 31/3, 2022 at 15:33 Comment(0)
T
8

As of PHPUnit 10.x it is:

<?xml version="1.0"?>
<phpunit
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd"
        bootstrap="bootstrap.php"
        colors="true"
        beStrictAboutOutputDuringTests="true"
        cacheDirectory=".phpunit.cache"
        requireCoverageMetadata="true"
>
    ...
    <source>
        <include>
            <directory>../../src</directory>
        </include>
    </source>
</phpunit>
Toadinthehole answered 26/4, 2023 at 6:56 Comment(0)
L
1

Create a file called phpunit.xml, and fill it with the following.

<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd">
  <source>
    <include>
      <directory suffix=".php">src</directory>
    </include>
  </source>
</phpunit>

Replace "src" with the name of the folder that you want to be analyzed.

Leptosome answered 4/4 at 15:55 Comment(0)
G
0

for people like me: I had changed the namespace, but PHPStorm had moved everything in the src/ directory to the root directory of the project. The tests still run, but when trying to generate coverage, I got that message.

Grillparzer answered 17/1 at 7:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.