Skip to content

Uncovered line with array_merge() and require() in PHP 7.4 #719

@BluePsyduck

Description

@BluePsyduck
Q A
php-code-coverage version 7.0.10
PHP version 7.4.1
Driver Xdebug
Xdebug version (if used) 2.9.0
Installation Method Composer
Usage Method PHPUnit
PHPUnit version (if used) 8.5.2

I found an issue with the coverage reports when array_merging some configuration files.

<?php
declare(strict_types=1);
namespace FancyNamespace;

class ConfigProvider
{
    public function __invoke(): array
    {
        return array_merge(
            require(__DIR__ . '/foo.php'), 
            require(__DIR__ . '/bar.php'),
        );
    }
}

Note that the files included have simple contents like <?php return ['foo' => 'bar']; each, i.e. the array_merge() can properly do its work.

The coverage report shows that the line with require(foo) is not covered:
coverage

Some observations of the issue:

  • There must be at least two files included. A single file is correctly covered, more files have only the last require line covered respectively.
  • This issue started appearing with PHP 7.4, reports under PHP 7.3 do not show this problem.

It would be nice if you could look into it.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions