Skip to content

Commit

Permalink
#576: Improved support for Clover files generated by PhpUnit
Browse files Browse the repository at this point in the history
  • Loading branch information
danielpalme committed Dec 16, 2022
1 parent 8d32a56 commit 17448ee
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/Readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ CHANGELOG

* New: #567: Added report type: MarkdownSummaryGithub
* New: #575: Added title to Markdown and text reports
* Fix: #576: Improved support for Clover files generated by PhpUnit

5.1.12.0

Expand Down
2 changes: 1 addition & 1 deletion src/ReportGenerator.Core/Parser/CoverageReportParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ private IEnumerable<ParserResult> ParseXmlFile(string filePath)
else if (item.Attribute("clover") != null || item.Attribute("generated") != null)
{
Logger.Debug(Resources.PreprocessingReport);
new CloverReportPreprocessor(this.sourceDirectories).Execute(item);
new CloverReportPreprocessor(this.sourceDirectories, this.defaultAssemblyName).Execute(item);

Logger.DebugFormat(Resources.InitiatingParser, "Clover");
var result = new CloverParser(this.assemblyFilter, this.classFilter, this.fileFilter, this.excludeTestProjects).Parse(item);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ internal class CloverReportPreprocessor
/// </summary>
private readonly IReadOnlyList<string> sourceDirectories;

/// <summary>
/// The default assembly name.
/// </summary>
private readonly string defaultAssemblyName = "Default";

/// <summary>
/// Initializes a new instance of the <see cref="CloverReportPreprocessor"/> class.
/// </summary>
Expand All @@ -37,6 +42,17 @@ internal CloverReportPreprocessor(IEnumerable<string> sourceDirectories)
this.sourceDirectories = sourceDirectories.ToList();
}

/// <summary>
/// Initializes a new instance of the <see cref="CloverReportPreprocessor" /> class.
/// </summary>
/// <param name="sourceDirectories">The source directories.</param>
/// <param name="defaultAssemblyName">The default assembly name.</param>
internal CloverReportPreprocessor(IEnumerable<string> sourceDirectories, string defaultAssemblyName)
: this(sourceDirectories)
{
this.defaultAssemblyName = defaultAssemblyName;
}

/// <summary>
/// Executes the preprocessing of the report.
/// </summary>
Expand All @@ -54,7 +70,16 @@ internal void Execute(XContainer report)
elem.Name = elem.Name.LocalName;
}

var files = report.Descendants("package").Elements("file").ToArray();
var projectsWithOutName = report.Descendants("project")
.Where(p => p.Attribute("name") == null)
.ToArray();

foreach (var projectWithOutName in projectsWithOutName)
{
projectWithOutName.Add(new XAttribute("name", this.defaultAssemblyName));
}

var files = report.Descendants("file").ToArray();

// Fix attribute name (required to support coverage files generated by PhpUnit)
foreach (var file in files)
Expand Down

0 comments on commit 17448ee

Please sign in to comment.