/** * This method takes a coverage report and then rebuilds the raw coverage * data based on the report data and the change history of the covered files. * * @param PHP_ChangeCoverage_Report $report The coverage report data. * * @return PHP_CodeCoverage */ protected function rebuildCoverageData(PHP_ChangeCoverage_Report $report) { $codeCoverage = new PHP_CodeCoverage(); $factory = new PHP_ChangeCoverage_ChangeSet_Factory(); vcsCache::initialize($this->tempDirectory); $this->writeLine(); $this->writeLine('Collecting commits and meta data, this may take a moment.'); $this->writeLine(); $xdebug = new PHP_ChangeCoverage_Xdebug(); if ($this->unmodifiedAsCovered) { $xdebug->setUnmodifiedAsCovered(); } foreach ($report->getFiles() as $file) { $changeSet = $factory->create($file); $changeSet->setStartDate($this->modifiedSince); foreach ($xdebug->generateData($changeSet->calculate()) as $data) { $codeCoverage->append($data, md5(microtime())); } } return $codeCoverage; }
/** * testGeneratedDataContainsXdebugArrayForEachPossibleExecution * * @return void * @covers PHP_ChangeCoverage_Xdebug * @group unittest */ public function testGeneratedDataContainsXdebugArrayForEachPossibleExecution() { $file = new PHP_ChangeCoverage_Source_File('/tmp/foo.php', array(new PHP_ChangeCoverage_Source_Line(13, 4, true), new PHP_ChangeCoverage_Source_Line(17, 2, true), new PHP_ChangeCoverage_Source_Line(23, 0, true), new PHP_ChangeCoverage_Source_Line(42, 3, false))); $xdebug = new PHP_ChangeCoverage_Xdebug(); $actual = iterator_to_array($xdebug->generateData($file)); $this->assertEquals(array(array('/tmp/foo.php' => array(13 => 1, 17 => 1, 23 => -1, 42 => -2)), array('/tmp/foo.php' => array(13 => 1, 17 => 1, 23 => -1, 42 => -2)), array('/tmp/foo.php' => array(13 => 1, 17 => -1, 23 => -1, 42 => -2)), array('/tmp/foo.php' => array(13 => 1, 17 => -1, 23 => -1, 42 => -2))), $actual); }