sebastianbergmann / php-code-coverage

Library that provides collection, processing, and rendering functionality for PHP code coverage information.
BSD 3-Clause "New" or "Revised" License
8.81k stars 373 forks source link

Coverage ask me to cover uses? #996

Closed steevanb closed 1 year ago

steevanb commented 1 year ago
Q A
php-code-coverage version 10.1.1
PHP version 8.2.5
Driver PCOV / Xdebug (same behavior)
PCOV version (if used) 1.0.11
XDebug version (if used) 3.2.1
Installation Method Composer
Usage Method PHPUnit
PHPUnit version (if used) 10.1.2

When i execute code coverage with PHPUnit 10.1, i have a lower covered percent than i have with exactly the same code but PHPUnit 9.5.

After some research, i've found PHPUnit 9.5 do not found files who contains only an Enum, but PHPUnit 10 found them, so i have to add coverage on my methods in Enum. That's ok.

The problem is with another difference: PHPUnit 10.1 ask me to cover "some" uses (not for all files, and i don't understand why?) 2023-04-26_11h03_54

I've tried with pcov and xdebug, same behavior.

My command to execute PHPUnit (exaclty same command for PHPUnit 9.5 and 10.1):

php \
    bin/ci/phpunit.php \
        --configuration "${ROOT_PATH}"/config/ci/phpunit.xml \
        "${ROOT_PATH}"/tests

bin/ci/phpunit.php:

#!/usr/bin/env php
<?php

declare(strict_types=1);

if (ini_get('date.timezone') === false) {
    ini_set('date.timezone', 'UTC');
}

define('PHPUNIT_COMPOSER_INSTALL', dirname(__DIR__, 2) . '/vendor/autoload.php');
require PHPUNIT_COMPOSER_INSTALL;
exit((new \PHPUnit\TextUI\Application())->run($GLOBALS['argv']));

config/ci/phpunit.xml (for PHPUnit 10.1):

<?xml version="1.0" encoding="UTF-8"?>
<!-- https://phpunit.readthedocs.io/en/latest/configuration.html -->
<phpunit
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd"
    cacheDirectory="../../var/ci/phpunit/"
    colors="true"
    bootstrap="../../tests/bootstrap.php"
    requireCoverageMetadata="true"
    failOnRisky="true"
    failOnWarning="true"
    failOnNotice="true"
    failOnIncomplete="true"
    beStrictAboutTestsThatDoNotTestAnything="true"
>
    <php>
        <ini name="display_errors" value="1"/>
        <ini name="error_reporting" value="-1"/>
        <server name="APP_ENV" value="test" force="true"/>
        <server name="SHELL_VERBOSITY" value="-1"/>
        <server name="SYMFONY_DEPRECATIONS_HELPER" value="disabled"/>
    </php>
    <source>
        <include>
            <directory suffix=".php">../../src</directory>
        </include>
    </source>
</phpunit>
sebastianbergmann commented 1 year ago

Thank you for your report.

Please provide a minimal, self-contained, reproducing test case that shows the problem you are reporting.

Without such a minimal, self-contained, reproducing test case I will not be able to investigate this issue.

steevanb commented 1 year ago

@sebastianbergmann i've created this repository, very simple to use (you just need Docker): https://github.com/steevanb/sebastianbergmann-php-code-coverage-issue-996