Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
uuf6429 opened this issue Dec 16, 2022 · 5 comments
Closed

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

uuf6429 opened this issue Dec 16, 2022 · 5 comments
Labels

Comments

@uuf6429
Copy link

uuf6429 commented Dec 16, 2022

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:

.Where(p => p.Attribute("name") != null)

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
Copy link
Owner

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
Copy link
Author

uuf6429 commented Dec 16, 2022

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
Copy link
Owner

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

Correct!

@danielpalme
Copy link
Owner

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

@LoremFooBar
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants