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

Implement processed code coverage data mapper #1028

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

AndrewFeeney
Copy link

This is my first pass at implementation for an object SebastianBergmann\CodeCoverage\Data\ProcessedCodeCoverageDataMapper which serializes to JSON and de-serializes from JSON a given instance of SebastianBergmann\CodeCoverage\Data\ProcessedCodeCoverage.

The intention here is to move in the direction of being able to generate code coverage reports that do not require the serialize() and unserialize() PHP functions, and instead rely on a data only JSON format which might be less prone to issues such as sebastianbergmann/phpcov#109. This PR attempts to implement a basic JSON format only, and does not fully realize that goal by replacing the current implementation of serialization or documentation.

The JSON format have essentially represents the underlying data in the class. i.e.

{
   "lineCoverage": [
       // ...
   ],
   "functionCoverage": [
       // ...      
   ],
}

I have not attempted to include any of the meta data that might be used to instantiate a Driver or Filter instance which are required to instantiate a CodeCoverage instance.

  • My Hesitations About My Implementation

I'm not sure if it would be better to make the JSON format more general, and nest the above properties under something like coverage using other keys, perhaps driver and filter or something else to include other meta data about the code coverage report. I have omitted this based on your stated preference to de-serialize to ProcessedCodeCoverageReport. I would welcome your guidance here.

  • My Hesitations About My Tests

I'm still familiarizing myself with the codebase and the shape of the coverage data, so I'm not certain I've covered everything I need to in testing.

I've included one "End to End" style test for XML which may not be appropriate to merge. This was more about me ensuring that I had everything I needed to replicate a known expected XML report. I'm not sure how far to go down this path in adding more tests like that, as it may be redundant, and I don't want to be retesting the XML report generation implementation. Once again, I'd welcome your opinion here.

@AndrewFeeney
Copy link
Author

I see that there are some CI failures which I'll take a look at next. I also should mention that my implementation here is laughably simple. One thing I haven't looked at is validating the JSON on unserialization. I'm not sure if that's necessary or not, but I can have a go at that if you'd like.

- This issue presents when running the test suite for the first time
  (e.g. in CI) since there is no `tests/_files/tmp` directory created.
- In the one test case which requires the cleanup of these files because
  it creates them it does not fail because the directory is created.
- The other test cases don't need this tear down, but they fail when it
  tries to run as this directory has not yet been created.
- In future we'll probably remove both the tear down and the test case
  that needs it as this is probably not an appropriately direct way to
  test this.
Copy link

codecov bot commented Jan 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (d10b53a) 84.00% compared to head (d551ba9) 84.09%.

Additional details and impacted files
@@             Coverage Diff              @@
##               main    #1028      +/-   ##
============================================
+ Coverage     84.00%   84.09%   +0.09%     
- Complexity     1194     1196       +2     
============================================
  Files            71       72       +1     
  Lines          4238     4250      +12     
============================================
+ Hits           3560     3574      +14     
+ Misses          678      676       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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.

None yet

1 participant