Support PHPUnit clover reports (silently reported as zero coverage) - #617
Conversation
| # Loop through the files that contain the xml roots | ||
| for i, xml_document in enumerate(self._xml_roots): | ||
| if xml_document.findall(".[@clover]"): | ||
| if self._is_clover_report(xml_document): |
There was a problem hiding this comment.
we should not have to recompute this for every file.
Perhaps we just compute a mapping in init so we can just turn this check into a dict lookup rather then re-searchign though the xml file?
| for file_tree in files: | ||
| lines.append(file_tree.findall('./line[@type="stmt"]')) | ||
| lines.append(file_tree.findall('./line[@type="cond"]')) |
There was a problem hiding this comment.
I think you need to add one of these for @type="method"
https://github.com/sebastianbergmann/php-code-coverage/blob/main/src/Report/Clover.php#L116
There was a problem hiding this comment.
to be clear, I know this was not in your changes, but I think it will prove important for ... honeslty both php clover and other clover reports
Two points from the review of Bachmann1234#617. Detecting the report format searched the whole document, and it was done once per source file inside _cache_file. The answer cannot change after load, so classify each root once in __init__ and look the answer up. This also folds in the JaCoCo probe, which had the same shape. Clover marks an executable line as method, stmt or cond. PHPUnit emits method for the declaration line of every function it measured, and leaving that type out reported those lines as unmeasured. This part is not specific to PHPUnit - it applies to any Clover writer.
|
Both fair, and the second one is a real gap rather than a nit — thanks. On the per-file re-scan. You're right, and it's broader than the clover check I added: the whole dispatch in There's a second re-scan in the same path that I'd like to fix in the same pass: On |
|
alrighty, lets get this out! |
|
Released as version 10.5.0 https://pypi.org/project/diff-cover/10.5.0/ thanks for the pr! |
Fixes #272.
A
clover.xmlwritten by PHPUnit comes out as zero coverage, without an error. Two independent reasons:XmlCoverageReporterrecognises Clover by.[@clover]on the root node. Atlassian Clover writes that attribute; PHPUnit writes a bare<coverage generated="…">, so the document falls through to the Cobertura branch, which finds nothing and returns an empty set instead of failing._get_src_path_line_nodes_clover()matches onfile/@path. PHPUnit identifies files with@name, so even once detection is fixed the lookup finds nothing.Detection now also accepts a document containing
file/line[@num][@count]— the element shape both dialects always produce — and the file lookup falls back to@name, comparing normalised paths and accepting a path that ends with the requested source path (PHPUnit writes absolute paths).Test added alongside the existing clover tests: a PHPUnit-shaped report whose covered lines are found. It fails on
main(empty result) and passes with the fix.AI-assisted (LLM used for drafting and for running the checks); the analysis and the runs are mine.