Cobertura package name attribute is always empty #935
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In certain utilities that parse Cobertura files they look to the
<Package name=
attribute. In PHPUnit this attribute is always empty (null)This causes results to look like the following (in this parser at least):
As you can tell this makes no sense (The parser on the other end adds "[filename] Package 1+n" whenever it encounters an empty package name)
See: https://github.com/sebastianbergmann/phpunit/blob/main/src/TextUI/TestRunner.php#L479
The third parameter is never passed.
It appears that the Cobertura report generator was copied from the Clover report generator but they are not one-in-the same. If
$name
was properly set in the Cobertura report then every "package" would have the same name. This would confuse Cobertura parsers because the way PHPUnit works with each package is it's essentially each$report
therefore we should be setting the packageName the same as the filename (or the class but filename seems more flexible when the file contains no classes)Summary:
In a Clover file the "name" attribute is global, see: https://github.com/sebastianbergmann/php-code-coverage/blob/main/src/Report/Clover.php#L46
In Cobertura the "name" attribute is attached to PackageName and a package is generated for each report.
This change isn't really breaking because if name would have ever been passed it would have been added to each package and completely confused any parser (worse than it is now)