danielpalme / ReportGenerator

ReportGenerator converts coverage reports generated by coverlet, OpenCover, dotCover, Visual Studio, NCover, Cobertura, JaCoCo, Clover, gcov or lcov into human readable reports in various formats.
https://reportgenerator.io
Apache License 2.0
2.58k stars 281 forks source link

Doesn't seem to work with clover coverage from PHPUnit #576

Closed uuf6429 closed 1 year ago

uuf6429 commented 1 year ago

Describe the bug

This tool doesn't seem to work for clover files generated by PHPUnit. In the logging result, it's always saying Analyzing 0 classes even though it also says f.e. Loading report '/app/coverage.xml'.

I dug into the source code a bit and it seems to assume that the project element always has a name attribute, but this isn't the case: https://github.com/danielpalme/ReportGenerator/blob/119c33ec80c55f280e50512a6432029184ea42d4/src/ReportGenerator.Core/Parser/CloverParser.cs#L70 So I manually added that attribute and the result log changed a bit:

2022-12-16T15:26:35: Loading report '/app/coverage.xml' 1/1 in memory
2022-12-16T15:26:36: Preprocessing report
2022-12-16T15:26:36: Initiating parser for Clover
2022-12-16T15:26:36: Current Assembly: Project
2022-12-16T15:26:36: Error during reading report '/app/coverage.xml' (Size: 364.9KB): Multiple errors
Object reference not set to an instance of an object.
Object reference not set to an instance of an object.
Object reference not set to an instance of an object.

2022-12-16T15:26:36: Parsing of 1 files completed
2022-12-16T15:26:36: Coverage report parsing took 0.1 seconds
2022-12-16T15:26:36: Initializing report builders for report types: JsonSummary, Html
2022-12-16T15:26:36: Analyzing 0 classes

Now it works one step further, but then it still breaks somewhere.

Specs

ReportGenerator 4.8.1 (I think) from loremfoobar/reportgenerator-coverage-bitbucket-pipe:0.7.0 and PHPUnit 9.5.x-dev

To Reproduce

Example coverage xml

<?xml version="1.0" encoding="UTF-8"?>
<coverage generated="1671183722">
  <project timestamp="1671183722">            <!--  <-- seems that the code requires a name attribute here  -->
    <file name="/Users/<user>/PhpstormProjects/myapp/src/ClosureLogger.php">
      <class name="MyApp\ClosureLogger" namespace="global">
        <metrics complexity="2" methods="2" coveredmethods="2" conditionals="0" coveredconditionals="0" statements="2" coveredstatements="2" elements="4" coveredelements="4"/>
      </class>
      <line num="13" type="method" name="__construct" visibility="public" complexity="1" crap="1" count="59"/>
      <line num="15" type="stmt" count="59"/>
      <line num="17" type="method" name="log" visibility="public" complexity="1" crap="1" count="8"/>
      <line num="19" type="stmt" count="8"/>
      <metrics loc="22" ncloc="22" classes="1" methods="2" coveredmethods="2" conditionals="0" coveredconditionals="0" statements="2" coveredstatements="2" elements="4" coveredelements="4"/>
    </file>
  </project>
</coverage>

Mixed log output (from the bitbucket pipe + report generator):

[15:41:21 DBG] DEBUG=True
[15:41:21 DBG] Workdir=/app
[15:41:21 DBG] Authenticating using app password
2022-12-16T15:41:21: Executable: /app/ReportGenerator.Core.dll
2022-12-16T15:41:21: Working directory: /app
2022-12-16T15:41:21: Settings
2022-12-16T15:41:21:  { "NumberOfReportsParsedInParallel": 1, "NumberOfReportsMergedInParallel": 1, "MaximumNumberOfHistoricCoverageFiles": 100, "RenderPngFallBackImagesForHistoryCharts": false, "CachingDurationOfRemoteFilesInMinutes": 10080, "DisableRiskHotspots": false, "ExcludeTestProjects": false, "CreateSubdirectoryForAllReportTypes": false, "CustomHeadersForRemoteFiles": null, "DefaultAssemblyName": "Default" }
2022-12-16T15:41:21:  { "MetricThresholdForCyclomaticComplexity": 15, "MetricThresholdForCrapScore": 30, "MetricThresholdForNPathComplexity": 200 }
2022-12-16T15:41:21: Loading report '/app/coverage.xml' 1/1 in memory
2022-12-16T15:41:21: Preprocessing report
2022-12-16T15:41:21: Initiating parser for Clover
2022-12-16T15:41:21: Finished parsing '/app/coverage.xml' 1/1
2022-12-16T15:41:21: Parsing of 1 files completed
2022-12-16T15:41:21: Starting merging result 1
2022-12-16T15:41:21: Finished merging result 1
2022-12-16T15:41:21: Coverage report parsing took 0.1 seconds
2022-12-16T15:41:21: Initializing report builders for report types: JsonSummary, Html
2022-12-16T15:41:21: Analyzing 0 classes
2022-12-16T15:41:21: Creating summary
2022-12-16T15:41:21: Writing report file 'coverage-report/index.html'
2022-12-16T15:41:22: Writing report file 'coverage-report/Summary.json'
2022-12-16T15:41:22: Report generation took 0.2 seconds
...
danielpalme commented 1 year ago

Thanks for your detailed issue!

I fixed the problem. PHPUnit seems to have changed the format of its Clover interpretation (see #292).

New release will be available within the next days!

uuf6429 commented 1 year ago

Whoa, thanks for a very quick reply, I appreciate it a lot!!

So I suppose the next step is to get the bitbucket pipe thingy rebuilt after the fix is released.

danielpalme commented 1 year ago

So I suppose the next step is to get the bitbucket pipe thingy rebuilt after the fix is released.

Correct!

danielpalme commented 1 year ago

Release 5.1.13 has been published. I also created a PR for the bitbucket pipeline: https://github.com/LoremFooBar/reportgenerator-coverage-bitbucket-pipe/pull/1

LoremFooBar commented 1 year ago

@uuf6429 Just published v0.8.0 of the pipe with the fix. On a side note, feel free to contact me if you have any feedback on the pipe :)