Skip to content

Commit 4c73cc3

Browse files
Merge branch 'master' into report-refactoring
2 parents 10c9365 + 171113e commit 4c73cc3

File tree

3 files changed

+36
-15
lines changed

3 files changed

+36
-15
lines changed

PHP/CodeCoverage.php

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ class PHP_CodeCoverage
8787
*/
8888
protected $currentId;
8989

90+
/**
91+
* @var array
92+
*/
93+
protected $currentFilterGroups = array('DEFAULT');
94+
9095
/**
9196
* Code coverage data.
9297
*
@@ -199,9 +204,10 @@ public function getReport()
199204
*/
200205
public function clear()
201206
{
202-
$this->currentId = NULL;
203-
$this->data = array();
204-
$this->tests = array();
207+
$this->currentId = NULL;
208+
$this->currentFilterGroups = array('DEFAULT');
209+
$this->data = array();
210+
$this->tests = array();
205211
}
206212

207213
/**
@@ -244,10 +250,11 @@ public function getTests()
244250
* Start collection of code coverage information.
245251
*
246252
* @param mixed $id
253+
* @param array $filterGroups
247254
* @param boolean $clear
248255
* @throws InvalidArgumentException
249256
*/
250-
public function start($id, $clear = FALSE)
257+
public function start($id, array $filterGroups = array('DEFAULT'), $clear = FALSE)
251258
{
252259
if (!is_bool($clear)) {
253260
throw new InvalidArgumentException;
@@ -257,7 +264,8 @@ public function start($id, $clear = FALSE)
257264
$this->clear();
258265
}
259266

260-
$this->currentId = $id;
267+
$this->currentId = $id;
268+
$this->currentFilterGroups = $filterGroups;
261269

262270
$this->driver->start();
263271
}
@@ -293,7 +301,7 @@ public function stop($append = TRUE)
293301
* @param mixed $id
294302
* @param array $filterGroups
295303
*/
296-
public function append(array $data, $id = NULL, array $filterGroups = array('DEFAULT'))
304+
public function append(array $data, $id = NULL, array $filterGroups = NULL)
297305
{
298306
if ($id === NULL) {
299307
$id = $this->currentId;
@@ -303,6 +311,10 @@ public function append(array $data, $id = NULL, array $filterGroups = array('DEF
303311
throw new InvalidArgumentException;
304312
}
305313

314+
if ($filterGroups === NULL) {
315+
$filterGroups = $this->currentFilterGroups;
316+
}
317+
306318
$this->applySelfFilter($data);
307319
$this->applyListsFilter($data, $filterGroups);
308320
$this->initializeFilesThatAreSeenTheFirstTime($data);
@@ -343,18 +355,27 @@ public function merge(PHP_CodeCoverage $that)
343355
{
344356
foreach ($that->data as $file => $lines) {
345357
if (!isset($this->data[$file])) {
346-
$this->data[$file] = $lines;
358+
if (!$this->filter->isFiltered($file, $this->currentFilterGroups)) {
359+
$this->data[$file] = $lines;
360+
}
361+
347362
continue;
348363
}
349364

350365
foreach ($lines as $line => $data) {
351366
if ($data !== NULL) {
352-
$this->data[$file][$line] = array_unique(
353-
array_merge($this->data[$file][$line], $data)
354-
);
367+
if (!isset($this->data[$file][$line])) {
368+
$this->data[$file][$line] = $data;
369+
} else {
370+
$this->data[$file][$line] = array_unique(
371+
array_merge($this->data[$file][$line], $data)
372+
);
373+
}
355374
}
356375
}
357376
}
377+
378+
$this->tests = array_merge($this->tests, $that->getTests());
358379
}
359380

360381
/**

Tests/PHP/CodeCoverageTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public function testFactory()
121121
public function testStartThrowsExceptionForInvalidArgument()
122122
{
123123
$coverage = new PHP_CodeCoverage;
124-
$coverage->start(NULL, NULL);
124+
$coverage->start(NULL, array(), NULL);
125125
}
126126

127127
/**

Tests/TestCase.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ protected function getCoverageForBankAccount()
126126
$coverage = new PHP_CodeCoverage($stub, new PHP_CodeCoverage_Filter);
127127

128128
$coverage->start(
129-
new BankAccountTest('testBalanceIsInitiallyZero'), TRUE
129+
new BankAccountTest('testBalanceIsInitiallyZero'), array('DEFAULT'), TRUE
130130
);
131131
$coverage->stop();
132132

@@ -163,7 +163,7 @@ protected function getCoverageForBankAccountForFirstTwoTests()
163163
$coverage = new PHP_CodeCoverage($stub, new PHP_CodeCoverage_Filter);
164164

165165
$coverage->start(
166-
new BankAccountTest('testBalanceIsInitiallyZero'), TRUE
166+
new BankAccountTest('testBalanceIsInitiallyZero'), array('DEFAULT'), TRUE
167167
);
168168
$coverage->stop();
169169

@@ -189,7 +189,7 @@ protected function getCoverageForBankAccountForLastTwoTests()
189189
$coverage = new PHP_CodeCoverage($stub, new PHP_CodeCoverage_Filter);
190190

191191
$coverage->start(
192-
new BankAccountTest('testBalanceCannotBecomeNegative2'), TRUE
192+
new BankAccountTest('testBalanceCannotBecomeNegative2'), array('DEFAULT'), TRUE
193193
);
194194
$coverage->stop();
195195

@@ -242,7 +242,7 @@ protected function getCoverageForFileWithIgnoredLines()
242242
new PHP_CodeCoverage_Filter
243243
);
244244

245-
$coverage->start('FileWithIgnoredLines', TRUE);
245+
$coverage->start('FileWithIgnoredLines', array('DEFAULT'), TRUE);
246246
$coverage->stop();
247247

248248
return $coverage;

0 commit comments

Comments
 (0)