@@ -92,6 +92,13 @@ class PHP_CodeCoverage
92
92
*/
93
93
protected $ currentId ;
94
94
95
+ /**
96
+ * SHA1 checksum of covered files.
97
+ *
98
+ * @var array
99
+ */
100
+ protected $ checksums = array ();
101
+
95
102
/**
96
103
* Code coverage data.
97
104
*
@@ -310,9 +317,16 @@ public function append(array $data, $id = NULL)
310
317
* Merges the data from another instance of PHP_CodeCoverage.
311
318
*
312
319
* @param PHP_CodeCoverage $that
320
+ * @param boolean $matchPaths
313
321
*/
314
- public function merge (PHP_CodeCoverage $ that )
322
+ public function merge (PHP_CodeCoverage $ that, $ matchPaths = FALSE )
315
323
{
324
+ if ($ matchPaths ) {
325
+ $ thatData = $ this ->matchPaths ($ that ->checksums , $ that ->data );
326
+ } else {
327
+ $ thatData = $ that ->data ;
328
+ }
329
+
316
330
foreach ($ that ->data as $ file => $ lines ) {
317
331
if (!isset ($ this ->data [$ file ])) {
318
332
if (!$ this ->filter ->isFiltered ($ file )) {
@@ -469,7 +483,8 @@ protected function initializeFilesThatAreSeenTheFirstTime($data)
469
483
{
470
484
foreach ($ data as $ file => $ lines ) {
471
485
if (!isset ($ this ->data [$ file ])) {
472
- $ this ->data [$ file ] = array ();
486
+ $ this ->checksums [$ file ] = sha1_file ($ file );
487
+ $ this ->data [$ file ] = array ();
473
488
474
489
foreach ($ lines as $ k => $ v ) {
475
490
$ this ->data [$ file ][$ k ] = $ v == -2 ? NULL : array ();
@@ -546,4 +561,37 @@ protected function processUncoveredFilesFromWhitelist()
546
561
547
562
$ this ->append ($ data , 'UNCOVERED_FILES_FROM_WHITELIST ' );
548
563
}
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
+ }
549
597
}
0 commit comments