Skip to content

Commit 9a05d1f

Browse files
dvdougsebastianbergmann
authored andcommitted
Tidy up how uncovered files are handled
1 parent eca5b04 commit 9a05d1f

File tree

2 files changed

+29
-46
lines changed

2 files changed

+29
-46
lines changed

src/CodeCoverage.php

+29-42
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
*/
2727
final class CodeCoverage
2828
{
29+
private const UNCOVERED_FILES_FROM_WHITELIST = 'UNCOVERED_FILES_FROM_WHITELIST';
30+
2931
/**
3032
* @var Driver
3133
*/
@@ -288,49 +290,50 @@ public function append(RawCodeCoverageData $rawData, $id = null, bool $append =
288290

289291
$this->applyWhitelistFilter($rawData);
290292
$this->applyIgnoredLinesFilter($rawData);
293+
291294
$this->data->initializeFilesThatAreSeenTheFirstTime($rawData);
292295

293296
if (!$append) {
294297
return;
295298
}
296299

297-
if ($id !== 'UNCOVERED_FILES_FROM_WHITELIST') {
300+
if ($id !== self::UNCOVERED_FILES_FROM_WHITELIST) {
298301
$this->applyCoversAnnotationFilter(
299302
$rawData,
300303
$linesToBeCovered,
301304
$linesToBeUsed,
302305
$ignoreForceCoversAnnotation
303306
);
304-
}
305307

306-
if (empty($rawData->getLineCoverage())) {
307-
return;
308-
}
308+
if (empty($rawData->getLineCoverage())) {
309+
return;
310+
}
309311

310-
$size = 'unknown';
311-
$status = -1;
312+
$size = 'unknown';
313+
$status = -1;
312314

313-
if ($id instanceof TestCase) {
314-
$_size = $id->getSize();
315+
if ($id instanceof TestCase) {
316+
$_size = $id->getSize();
315317

316-
if ($_size === Test::SMALL) {
317-
$size = 'small';
318-
} elseif ($_size === Test::MEDIUM) {
319-
$size = 'medium';
320-
} elseif ($_size === Test::LARGE) {
318+
if ($_size === Test::SMALL) {
319+
$size = 'small';
320+
} elseif ($_size === Test::MEDIUM) {
321+
$size = 'medium';
322+
} elseif ($_size === Test::LARGE) {
323+
$size = 'large';
324+
}
325+
326+
$status = $id->getStatus();
327+
$id = \get_class($id) . '::' . $id->getName();
328+
} elseif ($id instanceof PhptTestCase) {
321329
$size = 'large';
330+
$id = $id->getName();
322331
}
323332

324-
$status = $id->getStatus();
325-
$id = \get_class($id) . '::' . $id->getName();
326-
} elseif ($id instanceof PhptTestCase) {
327-
$size = 'large';
328-
$id = $id->getName();
329-
}
333+
$this->tests[$id] = ['size' => $size, 'status' => $status];
330334

331-
$this->tests[$id] = ['size' => $size, 'status' => $status];
332-
333-
$this->data->markCodeAsExecutedByTestCase($id, $rawData);
335+
$this->data->markCodeAsExecutedByTestCase($id, $rawData);
336+
}
334337

335338
$this->report = null;
336339
}
@@ -513,7 +516,7 @@ private function addUncoveredFilesFromWhitelist(): void
513516
}
514517
}
515518

516-
$this->append(RawCodeCoverageData::fromXdebugWithoutPathCoverage($data), 'UNCOVERED_FILES_FROM_WHITELIST');
519+
$this->append(RawCodeCoverageData::fromXdebugWithoutPathCoverage($data), self::UNCOVERED_FILES_FROM_WHITELIST);
517520
}
518521

519522
private function getLinesToBeIgnored(string $fileName): array
@@ -869,28 +872,12 @@ private function initializeData(): void
869872
}
870873
}
871874

872-
$data = [];
873-
874-
foreach ($this->driver->stop()->getLineCoverage() as $file => $fileCoverage) {
875-
if ($this->filter->isFiltered($file)) {
876-
continue;
877-
}
878-
879-
foreach (\array_keys($fileCoverage) as $key) {
880-
if ($fileCoverage[$key] === Driver::LINE_EXECUTED) {
881-
$fileCoverage[$key] = Driver::LINE_NOT_EXECUTED;
882-
}
883-
}
884-
885-
$data[$file] = $fileCoverage;
886-
}
887-
888-
$this->append(RawCodeCoverageData::fromXdebugWithoutPathCoverage($data), 'UNCOVERED_FILES_FROM_WHITELIST');
889-
890875
// having now collected dead code for the entire whitelist, we can safely skip this data on subsequent runs
891876
if ($this->driver->canDetectDeadCode()) {
892877
$this->driver->disableDeadCodeDetection();
893878
}
879+
880+
$this->append($this->driver->stop(), self::UNCOVERED_FILES_FROM_WHITELIST);
894881
}
895882
}
896883

src/Report/Xml/Facade.php

-4
Original file line numberDiff line numberDiff line change
@@ -222,10 +222,6 @@ private function processTests(array $tests): void
222222
$testsObject = $this->project->getTests();
223223

224224
foreach ($tests as $test => $result) {
225-
if ($test === 'UNCOVERED_FILES_FROM_WHITELIST') {
226-
continue;
227-
}
228-
229225
$testsObject->addTest($test, $result);
230226
}
231227
}

0 commit comments

Comments
 (0)