Skip to content

Commit 4d93372

Browse files
Merge branch 'report-refactoring' of github.com:sebastianbergmann/php-code-coverage into report-refactoring
2 parents bf1e53b + 55925b8 commit 4d93372

File tree

3 files changed

+59
-6
lines changed

3 files changed

+59
-6
lines changed

PHP/CodeCoverage.php

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,13 @@ class PHP_CodeCoverage
9292
*/
9393
protected $currentId;
9494

95+
/**
96+
* SHA1 checksum of covered files.
97+
*
98+
* @var array
99+
*/
100+
protected $checksums = array();
101+
95102
/**
96103
* Code coverage data.
97104
*
@@ -310,9 +317,16 @@ public function append(array $data, $id = NULL)
310317
* Merges the data from another instance of PHP_CodeCoverage.
311318
*
312319
* @param PHP_CodeCoverage $that
320+
* @param boolean $matchPaths
313321
*/
314-
public function merge(PHP_CodeCoverage $that)
322+
public function merge(PHP_CodeCoverage $that, $matchPaths = FALSE)
315323
{
324+
if ($matchPaths) {
325+
$thatData = $this->matchPaths($that->checksums, $that->data);
326+
} else {
327+
$thatData = $that->data;
328+
}
329+
316330
foreach ($that->data as $file => $lines) {
317331
if (!isset($this->data[$file])) {
318332
if (!$this->filter->isFiltered($file)) {
@@ -469,7 +483,8 @@ protected function initializeFilesThatAreSeenTheFirstTime($data)
469483
{
470484
foreach ($data as $file => $lines) {
471485
if (!isset($this->data[$file])) {
472-
$this->data[$file] = array();
486+
$this->checksums[$file] = sha1_file($file);
487+
$this->data[$file] = array();
473488

474489
foreach ($lines as $k => $v) {
475490
$this->data[$file][$k] = $v == -2 ? NULL : array();
@@ -546,4 +561,37 @@ protected function processUncoveredFilesFromWhitelist()
546561

547562
$this->append($data, 'UNCOVERED_FILES_FROM_WHITELIST');
548563
}
564+
565+
/**
566+
* @param array $checksums
567+
* @param array $data
568+
* @return array
569+
* @since Method available since Release 1.1.0
570+
*/
571+
protected function matchPaths(array $checksums, array $data)
572+
{
573+
$coverageWithLocalPaths = array();
574+
575+
foreach ($data as $originalRemotePath => $coverage) {
576+
$remotePath = $originalRemotePath;
577+
578+
if (strpos($path, '/') !== FALSE) {
579+
$separator = '/';
580+
} else {
581+
$separator = '\\';
582+
}
583+
584+
while (!($localPath = PHPUnit_Util_Filesystem::fileExistsInIncludePath($remotePath)) &&
585+
strpos($remotePath, $separator) !== FALSE) {
586+
$remotePath = substr($remotePath, strpos($remotePath, $separator) + 1);
587+
}
588+
589+
if ($localPath &&
590+
sha1_file($localPath) == $checksums[$originalRemotePath]) {
591+
$coverageWithLocalPaths[$localPath] = $coverage;
592+
}
593+
}
594+
595+
return $coverageWithLocalPaths;
596+
}
549597
}

PHP/CodeCoverage/Report/Node/File.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@
4343
* @since File available since Release 1.1.0
4444
*/
4545

46-
if (!defined('T_NAMESPACE')) {
47-
define('T_NAMESPACE', 377);
48-
}
49-
5046
/**
5147
* Represents a file in the code coverage information tree.
5248
*

package.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,15 @@
160160
<channel>components.ez.no</channel>
161161
<min>1.6</min>
162162
</package>
163+
<extension>
164+
<name>dom</name>
165+
</extension>
166+
<extension>
167+
<name>reflection</name>
168+
</extension>
169+
<extension>
170+
<name>spl</name>
171+
</extension>
163172
<extension>
164173
<name>xdebug</name>
165174
<min>2.0.5</min>

0 commit comments

Comments
 (0)