Phpunit Code Coverage - 0 Files Analysed when incl

2019-09-15 23:29发布

问题:

I am getting a weird result when trying to create a code coverage report of my test.

I call this:

phpunit --coverage-html report tests/JSONTest.php

And get this:

PHPUnit 3.6.12 by Sebastian Bergmann.
.
Time: 0 seconds, Memory: 6.75Mb
OK (1 test, 1 assertion)
Generating code coverage report in HTML format ... done

My test looks like this:

<?php

require_once dirname(__FILE__) . "/../include/includeAllNecessaryFiles.php";

class JSONTest extends PHPUnit_Framework_TestCase {
    public function testBla() {
        $this->assertEquals("hallo", "hallo");
    }
}

The file includeAllNecessaryFiles.php has this content:

<?php
include '/usr/share/php/PHPUnit/Framework/TestCase.php';

function something(){

}

The report lists all directories of the php-files that have been used, but doesn't list any files. It displays a 100% coverage, 0 of 0 lines have been covered.

When I throw this out:

function something(){

}

The report works properly and shows exactly how many lines the test covers.

Does anybody have an idea?

Thanks in advance!

Ben

回答1:

I have found that the code coverage reports are not always 100% accurate. There could be many reasons. I once asked Derick Rethans (creator of Xdebug) about this. He told me that using Zend Debugger with Xdebug at the same time (something I tend to do) has been know to throw off the line counts.

I know this is not much help, but I just wanted to let you know this is a know issue.