Skip to content

Support PHPUnit clover reports (silently reported as zero coverage) - #617

Open
Eljees wants to merge 1 commit into
Bachmann1234:mainfrom
Eljees:fix/272-phpunit-clover
Open

Support PHPUnit clover reports (silently reported as zero coverage)#617
Eljees wants to merge 1 commit into
Bachmann1234:mainfrom
Eljees:fix/272-phpunit-clover

Conversation

@Eljees

@Eljees Eljees commented Aug 6, 2026

Copy link
Copy Markdown

Fixes #272.

A clover.xml written by PHPUnit comes out as zero coverage, without an error. Two independent reasons:

  1. Format detection. XmlCoverageReporter recognises 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.
  2. File lookup. _get_src_path_line_nodes_clover() matches on file/@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.

# 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):

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Comment on lines 149 to 151
for file_tree in files:
lines.append(file_tree.findall('./line[@type="stmt"]'))
lines.append(file_tree.findall('./line[@type="cond"]'))

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The script will fail If no string 'clover' in clover xml

2 participants