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! |
…ath (#618) * perf: index the Clover file lookup instead of rescanning per source path `get_src_path_line_nodes_clover` walked every `.//file` in the report on every call, and it is called once per source path, so N source paths against a report of M files did N*M element visits and N*M `relative_path` calls. Build the lookup once per report: a map from repository-relative path, plus a map from the last path segment for the suffix match that absolute-path reports rely on. Both store document position, so matches are still returned in document order. Follow-up to the review on #617. * refactor: move the Clover file index into its own module Adding the index in this branch took violations_reporter.py to 1019 lines, past pylint's too-many-lines limit of 1000. The lookup is self-contained, so it moves to violationsreporters/clover.py as CloverFileIndex, and the module is back to 958 lines. XmlCoverageReporter keeps the per-report cache and builds the index on first use, so the dispatch in _cache_file and the signature of get_src_path_line_nodes_clover are unchanged. The moved code resolves GitPathTool in its own module, so the Clover tests patch it there. Skipping a <file> element that carries neither path nor name had no test of its own; it has one now. Requested in review on #618.
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.