Skip to content

Commit 6ae0dcd

Browse files
Merge branch 'master' into report-refactoring
2 parents d76ae24 + 73a3434 commit 6ae0dcd

File tree

5 files changed

+38
-99
lines changed

5 files changed

+38
-99
lines changed

ChangeLog.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ PHP_CodeCoverage 1.1.0
1010
* Added support for traits.
1111
* Refactored the collection and processing of code coverage data improving code readability and performance.
1212
* Refactored the generation of Clover XML and HTML reports improving code readability and testability.
13+
* Removed the support for multiple blacklist groups.

PHP/CodeCoverage.php

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

90-
/**
91-
* @var array
92-
*/
93-
protected $currentFilterGroups = array('DEFAULT');
94-
9590
/**
9691
* Code coverage data.
9792
*
@@ -204,10 +199,9 @@ public function getReport()
204199
*/
205200
public function clear()
206201
{
207-
$this->currentId = NULL;
208-
$this->currentFilterGroups = array('DEFAULT');
209-
$this->data = array();
210-
$this->tests = array();
202+
$this->currentId = NULL;
203+
$this->data = array();
204+
$this->tests = array();
211205
}
212206

213207
/**
@@ -250,11 +244,10 @@ public function getTests()
250244
* Start collection of code coverage information.
251245
*
252246
* @param mixed $id
253-
* @param array $filterGroups
254247
* @param boolean $clear
255248
* @throws InvalidArgumentException
256249
*/
257-
public function start($id, array $filterGroups = array('DEFAULT'), $clear = FALSE)
250+
public function start($id, $clear = FALSE)
258251
{
259252
if (!is_bool($clear)) {
260253
throw new InvalidArgumentException;
@@ -264,8 +257,7 @@ public function start($id, array $filterGroups = array('DEFAULT'), $clear = FALS
264257
$this->clear();
265258
}
266259

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

270262
$this->driver->start();
271263
}
@@ -299,9 +291,8 @@ public function stop($append = TRUE)
299291
*
300292
* @param array $data
301293
* @param mixed $id
302-
* @param array $filterGroups
303294
*/
304-
public function append(array $data, $id = NULL, array $filterGroups = NULL)
295+
public function append(array $data, $id = NULL)
305296
{
306297
if ($id === NULL) {
307298
$id = $this->currentId;
@@ -311,12 +302,8 @@ public function append(array $data, $id = NULL, array $filterGroups = NULL)
311302
throw new InvalidArgumentException;
312303
}
313304

314-
if ($filterGroups === NULL) {
315-
$filterGroups = $this->currentFilterGroups;
316-
}
317-
318305
$this->applySelfFilter($data);
319-
$this->applyListsFilter($data, $filterGroups);
306+
$this->applyListsFilter($data);
320307
$this->initializeFilesThatAreSeenTheFirstTime($data);
321308
$this->applyCoversAnnotationFilter($data, $id);
322309

@@ -355,7 +342,7 @@ public function merge(PHP_CodeCoverage $that)
355342
{
356343
foreach ($that->data as $file => $lines) {
357344
if (!isset($this->data[$file])) {
358-
if (!$this->filter->isFiltered($file, $this->currentFilterGroups)) {
345+
if (!$this->filter->isFiltered($file)) {
359346
$this->data[$file] = $lines;
360347
}
361348

@@ -468,12 +455,11 @@ protected function applyCoversAnnotationFilter(&$data, $id)
468455
* Applies the blacklist/whitelist filtering.
469456
*
470457
* @param array $data
471-
* @param array $filterGroups
472458
*/
473-
protected function applyListsFilter(&$data, $filterGroups)
459+
protected function applyListsFilter(&$data)
474460
{
475461
foreach (array_keys($data) as $filename) {
476-
if ($this->filter->isFiltered($filename, $filterGroups)) {
462+
if ($this->filter->isFiltered($filename)) {
477463
unset($data[$filename]);
478464
}
479465
}

PHP/CodeCoverage/Filter.php

Lines changed: 16 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,7 @@ class PHP_CodeCoverage_Filter
6262
*
6363
* @var array
6464
*/
65-
protected $blacklistedFiles = array(
66-
'DEFAULT' => array()
67-
);
65+
protected $blacklistedFiles = array();
6866

6967
/**
7068
* Source files that are whitelisted.
@@ -102,40 +100,37 @@ public static function getInstance()
102100
* @param string $directory
103101
* @param string $suffix
104102
* @param string $prefix
105-
* @param string $group
106103
*/
107-
public function addDirectoryToBlacklist($directory, $suffix = '.php', $prefix = '', $group = 'DEFAULT')
104+
public function addDirectoryToBlacklist($directory, $suffix = '.php', $prefix = '')
108105
{
109106
$files = File_Iterator_Factory::getFileIterator(
110107
$directory, $suffix, $prefix
111108
);
112109

113110
foreach ($files as $file) {
114-
$this->addFileToBlacklist($file->getPathName(), $group, FALSE);
111+
$this->addFileToBlacklist($file->getPathName());
115112
}
116113
}
117114

118115
/**
119116
* Adds a file to the blacklist.
120117
*
121118
* @param string $filename
122-
* @param string $group
123119
*/
124-
public function addFileToBlacklist($filename, $group = 'DEFAULT')
120+
public function addFileToBlacklist($filename)
125121
{
126-
$this->blacklistedFiles[$group][realpath($filename)] = TRUE;
122+
$this->blacklistedFiles[realpath($filename)] = TRUE;
127123
}
128124

129125
/**
130126
* Adds files to the blacklist.
131127
*
132-
* @param array $files
133-
* @param string $group
128+
* @param array $files
134129
*/
135-
public function addFilesToBlacklist(array $files, $group = 'DEFAULT')
130+
public function addFilesToBlacklist(array $files)
136131
{
137132
foreach ($files as $file) {
138-
$this->addFileToBlacklist($file, $group);
133+
$this->addFileToBlacklist($file);
139134
}
140135
}
141136

@@ -145,31 +140,29 @@ public function addFilesToBlacklist(array $files, $group = 'DEFAULT')
145140
* @param string $directory
146141
* @param string $suffix
147142
* @param string $prefix
148-
* @param string $group
149143
*/
150-
public function removeDirectoryFromBlacklist($directory, $suffix = '.php', $prefix = '', $group = 'DEFAULT')
144+
public function removeDirectoryFromBlacklist($directory, $suffix = '.php', $prefix = '')
151145
{
152146
$files = File_Iterator_Factory::getFileIterator(
153147
$directory, $suffix, $prefix
154148
);
155149

156150
foreach ($files as $file) {
157-
$this->removeFileFromBlacklist($file->getPathName(), $group);
151+
$this->removeFileFromBlacklist($file->getPathName());
158152
}
159153
}
160154

161155
/**
162156
* Removes a file from the blacklist.
163157
*
164158
* @param string $filename
165-
* @param string $group
166159
*/
167-
public function removeFileFromBlacklist($filename, $group = 'DEFAULT')
160+
public function removeFileFromBlacklist($filename)
168161
{
169162
$filename = realpath($filename);
170163

171-
if (isset($this->blacklistedFiles[$group][$filename])) {
172-
unset($this->blacklistedFiles[$group][$filename]);
164+
if (isset($this->blacklistedFiles[$filename])) {
165+
unset($this->blacklistedFiles[$filename]);
173166
}
174167
}
175168

@@ -273,12 +266,11 @@ public static function isFile($filename)
273266
* When the whitelist is not empty, whitelisting is used.
274267
*
275268
* @param string $filename
276-
* @param array $groups
277269
* @param boolean $ignoreWhitelist
278270
* @return boolean
279271
* @throws InvalidArgumentException
280272
*/
281-
public function isFiltered($filename, array $groups = array('DEFAULT'), $ignoreWhitelist = FALSE)
273+
public function isFiltered($filename, $ignoreWhitelist = FALSE)
282274
{
283275
if (!is_bool($ignoreWhitelist)) {
284276
throw new InvalidArgumentException;
@@ -292,16 +284,7 @@ public function isFiltered($filename, array $groups = array('DEFAULT'), $ignoreW
292284

293285
$blacklistedFiles = array();
294286

295-
foreach ($groups as $group) {
296-
if (isset($this->blacklistedFiles[$group])) {
297-
$blacklistedFiles = array_merge(
298-
$blacklistedFiles,
299-
$this->blacklistedFiles[$group]
300-
);
301-
}
302-
}
303-
304-
return isset($blacklistedFiles[$filename]);
287+
return isset($this->blacklistedFiles[$filename]);
305288
}
306289

307290
/**
@@ -311,13 +294,7 @@ public function isFiltered($filename, array $groups = array('DEFAULT'), $ignoreW
311294
*/
312295
public function getBlacklist()
313296
{
314-
$blacklistedFiles = array();
315-
316-
foreach ($this->blacklistedFiles as $group => $list) {
317-
$blacklistedFiles[$group] = array_keys($list);
318-
}
319-
320-
return $blacklistedFiles;
297+
return array_keys($this->blacklistedFiles);
321298
}
322299

323300
/**

Tests/PHP/CodeCoverage/FilterTest.php

Lines changed: 7 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -126,22 +126,7 @@ public function testAddingAFileToTheBlacklistWorks()
126126
$this->filter->addFileToBlacklist($this->files[0]);
127127

128128
$this->assertEquals(
129-
array('DEFAULT' => array($this->files[0])),
130-
$this->filter->getBlacklist()
131-
);
132-
}
133-
134-
/**
135-
* @covers PHP_CodeCoverage_Filter::addFileToBlacklist
136-
* @covers PHP_CodeCoverage_Filter::getBlacklist
137-
*/
138-
public function testAddingAFileToTheBlacklistWorks2()
139-
{
140-
$this->filter->addFileToBlacklist($this->files[0], 'group');
141-
142-
$this->assertEquals(
143-
array('DEFAULT' => array(), 'group' => array($this->files[0])),
144-
$this->filter->getBlacklist()
129+
array($this->files[0]), $this->filter->getBlacklist()
145130
);
146131
}
147132

@@ -154,9 +139,7 @@ public function testRemovingAFileFromTheBlacklistWorks()
154139
$this->filter->addFileToBlacklist($this->files[0]);
155140
$this->filter->removeFileFromBlacklist($this->files[0]);
156141

157-
$this->assertEquals(
158-
array('DEFAULT' => array()), $this->filter->getBlacklist()
159-
);
142+
$this->assertEquals(array(), $this->filter->getBlacklist());
160143
}
161144

162145
/**
@@ -169,12 +152,9 @@ public function testAddingADirectoryToTheBlacklistWorks()
169152
$this->filter->addDirectoryToBlacklist(TEST_FILES_PATH);
170153

171154
$blacklist = $this->filter->getBlacklist();
155+
sort($blacklist);
172156

173-
foreach (array_keys($blacklist) as $group) {
174-
sort($blacklist[$group]);
175-
}
176-
177-
$this->assertEquals(array('DEFAULT' => $this->files), $blacklist);
157+
$this->assertEquals($this->files, $blacklist);
178158
}
179159

180160
/**
@@ -190,12 +170,9 @@ public function testAddingFilesToTheBlacklistWorks()
190170
);
191171

192172
$blacklist = $this->filter->getBlacklist();
173+
sort($blacklist);
193174

194-
foreach (array_keys($blacklist) as $group) {
195-
sort($blacklist[$group]);
196-
}
197-
198-
$this->assertEquals(array('DEFAULT' => $this->files), $blacklist);
175+
$this->assertEquals($this->files, $blacklist);
199176
}
200177

201178
/**
@@ -208,9 +185,7 @@ public function testRemovingADirectoryFromTheBlacklistWorks()
208185
$this->filter->addDirectoryToBlacklist(TEST_FILES_PATH);
209186
$this->filter->removeDirectoryFromBlacklist(TEST_FILES_PATH);
210187

211-
$this->assertEquals(
212-
array('DEFAULT' => array()), $this->filter->getBlacklist()
213-
);
188+
$this->assertEquals(array(), $this->filter->getBlacklist());
214189
}
215190

216191
/**

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'), array('DEFAULT'), TRUE
129+
new BankAccountTest('testBalanceIsInitiallyZero'), 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'), array('DEFAULT'), TRUE
166+
new BankAccountTest('testBalanceIsInitiallyZero'), 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'), array('DEFAULT'), TRUE
192+
new BankAccountTest('testBalanceCannotBecomeNegative2'), TRUE
193193
);
194194
$coverage->stop();
195195

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

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

248248
return $coverage;

0 commit comments

Comments
 (0)