Skip to content

Commit dc73abb

Browse files
Respect coverage data's own filter when merging another source
1 parent 5ee1456 commit dc73abb

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

src/CodeCoverage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ public function merge(PHP_CodeCoverage $that)
349349
{
350350
foreach ($that->getData() as $file => $lines) {
351351
if (!isset($this->data[$file])) {
352-
if (!$that->filter()->isFiltered($file)) {
352+
if (!$that->filter()->isFiltered($file) && !$this->filter->isFiltered($file)) {
353353
$this->data[$file] = $lines;
354354
}
355355

tests/PHP/CodeCoverageTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,25 @@ public function testMerge2()
317317
);
318318
}
319319

320+
/**
321+
* @covers PHP_CodeCoverage::getData
322+
* @covers PHP_CodeCoverage::merge
323+
*/
324+
public function testMergeRespectsTargetFilter()
325+
{
326+
$filter = new PHP_CodeCoverage_Filter;
327+
$filter->addFileToWhitelist(TEST_FILES_PATH . 'BankAccount.php');
328+
329+
$coverage = $this->getCoverageForBankAccount($filter);
330+
331+
$coverage->merge($this->getCoverageForClassWithAnonymousFunction());
332+
333+
$this->assertEquals(
334+
$this->getExpectedDataArrayForBankAccount(),
335+
$coverage->getData()
336+
);
337+
}
338+
320339
/**
321340
* @covers PHP_CodeCoverage::getLinesToBeIgnored
322341
*/

tests/TestCase.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ protected function getXdebugDataForBankAccount()
7474
);
7575
}
7676

77-
protected function getCoverageForBankAccount()
77+
protected function getCoverageForBankAccount(PHP_CodeCoverage_Filter $filter = null)
7878
{
7979
$data = $this->getXdebugDataForBankAccount();
8080

@@ -88,7 +88,7 @@ protected function getCoverageForBankAccount()
8888
$data[3]
8989
));
9090

91-
$coverage = new PHP_CodeCoverage($stub, new PHP_CodeCoverage_Filter);
91+
$coverage = new PHP_CodeCoverage($stub, $filter ?: new PHP_CodeCoverage_Filter);
9292

9393
$coverage->start(
9494
new BankAccountTest('testBalanceIsInitiallyZero'),

0 commit comments

Comments
 (0)