Skip to content

Commit 199457c

Browse files
committed
added Lcov
1 parent ca6647f commit 199457c

File tree

2 files changed

+67
-1
lines changed

2 files changed

+67
-1
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@
3131
"php": "^7.3",
3232
"ext-dom": "*",
3333
"ext-xmlwriter": "*",
34+
"cedx/lcov.hx": "^1.0",
3435
"phpunit/php-file-iterator": "^3.0",
35-
"phpunit/php-token-stream": "^4.0",
3636
"phpunit/php-text-template": "^2.0",
37+
"phpunit/php-token-stream": "^4.0",
3738
"sebastian/code-unit-reverse-lookup": "^2.0",
3839
"sebastian/environment": "^5.0",
3940
"sebastian/version": "^3.0",

src/Report/Lcov.php

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of phpunit/php-code-coverage.
4+
*
5+
* (c) Sebastian Bergmann <sebastian@phpunit.de>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
namespace SebastianBergmann\CodeCoverage\Report;
11+
12+
use function dirname;
13+
use function file_put_contents;
14+
use lcov\{FunctionCoverage, LineCoverage, LineData, Record, Report};
15+
use SebastianBergmann\CodeCoverage\Directory;
16+
use SebastianBergmann\CodeCoverage\Driver\WriteOperationFailedException;
17+
use SebastianBergmann\CodeCoverage\Node\File;
18+
19+
final class Lcov
20+
{
21+
public function process(CodeCoverage $coverage, ?string $target = null, ?string $name = null): string
22+
{
23+
$report = $coverage->getReport();
24+
25+
$records = [];
26+
foreach ($report as $item) {
27+
if (!$item instanceof File) {
28+
continue;
29+
}
30+
31+
$coverageData = $item->lineCoverageData();
32+
33+
$linesData = [];
34+
35+
$record = new Record($item->pathAsString(), [
36+
'functions' => new FunctionCoverage(1, 1),
37+
'lines' => $lineCoverage
38+
]);
39+
}
40+
41+
$report = new Report("Example", $records);
42+
43+
$lineCoverage = new LineCoverage(2, 2, [
44+
new LineData(6, 2),
45+
new LineData(7, 2)
46+
]);
47+
48+
$record = new Record("/home/cedx/lcov.hx/fixture.php", [
49+
'functions' => new FunctionCoverage(1, 1),
50+
'lines' => $lineCoverage
51+
]);
52+
53+
$report = new Report("Example", [$record]);
54+
55+
if ($target !== null) {
56+
Directory::create(dirname($target));
57+
58+
if (@file_put_contents($target, $buffer) === false) {
59+
throw new WriteOperationFailedException($target);
60+
}
61+
}
62+
63+
return $buffer;
64+
}
65+
}

0 commit comments

Comments
 (0)