-
-
Notifications
You must be signed in to change notification settings - Fork 384
Feature LCOV code coverage #869
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Please rebase your branch so that it has #870. Thanks! |
Codecov Report
@@ Coverage Diff @@
## master #869 +/- ##
============================================
+ Coverage 84.75% 84.82% +0.07%
- Complexity 1086 1104 +18
============================================
Files 60 61 +1
Lines 3575 3625 +50
============================================
+ Hits 3030 3075 +45
- Misses 545 550 +5
Continue to review full report at Codecov.
|
Out of curiosity: what are you missing from the HTML report generated by this library that you get from the one generated by LCOV's |
To be honest, I prefer the built-in HTML report. I am only using the And for that specific case, line coverage is more than enough imo. |
@sebastianbergmann @dvdoug |
return $testName[0]; | ||
} | ||
|
||
private function getCoverageByTestCase(File $file): array |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get the below when generating LCOV for php-code-coverage's own test suite (using version of PHPUnit from your PR in that repo). I think you need a guard clause around line 35/36
Message: SebastianBergmann\CodeCoverage\Report\Lcov::getCoverageByTestCase(): Argument #1 ($file) must be of type SebastianBergmann\CodeCoverage\Node\File, SebastianBergmann\CodeCoverage\Node\Directory given
foreach ($report as $file) { | ||
$tests = $this->getCoverageByTestCase($file); | ||
|
||
foreach ($tests as $name => $test) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This overrides the $name
given in the function signature (which is unused?)
|
||
$testSpecificData[$test]['functionLineNumbers'][$methodName] = $method['startLine']; | ||
|
||
if (0 < $method['executedLines'] && $method['coverage'] == 100) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recommend strict equality (===
) here and on line 118
} | ||
} | ||
|
||
$buffer = implode("\n", $lcovLines) . "\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand this is how the other reports do it (generate in memory and then write to disk), but I'm concerned these might turn out to be very, very large files.
What's the largest project you've tested this with?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been trying to find a good phpunit project that I could wire up to test, has been challenging... Any suggestions? 😅
Since lcov
is pretty much a per line file, not like a closed structure like xml or json, I was tempted to just file_put_contents($filename, $line, FILE_APPEND);
but seeing how the other coverage did it, I didnt want to "rock the boat"... I could switch it tho?
EDIT: Only concerned I had about the file append, is the buffer that is returned? file_get_content()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fwrite
is probably a better choice? file_put_contents
would open and close the file on every call.
I've had good luck with Symfony in the past when seeking out a giant codebase, it's one repo that has all of the individual components.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fwrite
is probably a better choice?file_put_contents
would open and close the file on every call.
What do I do about returning the "buffer" at the end? Just open up the file and return the whole thing as string? 🤔
EDIT: what about Moderate phpunit projects I could rewire up easily for further testing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do I do about returning the "buffer" at the end? Just open up the file and return the whole thing as string?
It's only the text report where the contents are reused by the calling application 🤔. @sebastianbergmann would you be OK if nothing was returned?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
its used for the tests as well, returning an empty string would make the lcov tests fail... I would have to refactor to test it another way... 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, 💩
); | ||
} | ||
|
||
public function testCloverForFileWithIgnoredLines(): void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public function testCloverForFileWithIgnoredLines(): void | |
public function testLcovForFileWithIgnoredLines(): void |
); | ||
} | ||
|
||
public function testCloverForClassWithAnonymousFunction(): void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public function testCloverForClassWithAnonymousFunction(): void | |
public function testLcovForClassWithAnonymousFunction(): void |
I think we've been going about this the wrong way. I dont think we should have the "per test case basis" as a default output, this will create huge files ex: I believe we should have a sane default output which should be on a source file basis line coverage, and if the user really want the coverage on a per test basis he can add the extra option @sebastianbergmann @dvdoug What do you think? 🤔 💭 |
I will defer to @sebastianbergmann on adding options, I'm just a humble contributor. |
Thank you for your contribution. I appreciate the time you invested in preparing this pull request. However, I have decided not to merge it. |
Feature request issue #735
Generate an lcov code coverage, which can be tested with
genhtml
which is part of most Debian derived distribution packagelcov
.Ref: http://ltp.sourceforge.net/coverage/lcov/geninfo.1.php
Once you have generated the lcov file you can generate the html coverage with the following command: