Wrong coverage when a testcase is run multiple times
When a TestCase is run multiple times within a test suite, code coverage information is wrong. We are doing this in our project to test the same code under different configuration such as db, db+memcached, db+memcached+sphinx, master slave database. Both html and clover reports are affected by this bug.
As soon as a test is run multiple times, all the uncovered code is treated as a comment. This result as everything appears as 100% covered. This was not happening with phpunit 3.4
I've managed to create a minimal test case reproducing this issue. I've put the test case in this gist https://gist.github.com/609633
I have created a temporary fix by modifying the append function in CodeCoverage.php to suffix the test id by a uniq identifier so that coverage information from multiple runs of the same TestCase doesn't colide in the report.
public function append(array $data, $id = NULL, array $filterGroups = array('DEFAULT'))
{
[.............]
if (!empty($data)) {
if ($id instanceof PHPUnit_Framework_TestCase) {
$status = $id->getStatus();
$id = get_class($id) . '::' . $id->getName() . '::' . uniqid('hack_');
$this->tests[$id] = $status;
}
[.....]
}
Is there any chance you can test this with the master and/or report-refactoring branch(es) of PHP_CodeCoverage? If not, no worries. I will investigate the issue ASAP.
BTW: A better way to implement what you want would be
abstract class FooTestCase extends PHPUnit_Framework_TestCase
{
public function testSomething()
{
}
}
class BarTest extends FooTestCase
{
}
class BazTest extends FooTestCase
{
}
BarTest and BazTest would then get their tests from FooTestCase but could, for instance, set up different database connections using their respective setUp() methods.
I've tested the same testcase against master and the issue is still there. I've tried against the report-refactoring branch but I had an issue loading this file "File/Iterator/Autoload.php" which doesn't exist.
It exists, it just is in another package. No worries, I'll look into it.
Won't fix, please refactor your test case(s) like outlined in my earlier comment.