Closed SolovievEvgenii closed 1 year ago
Unfortunately, I do not use the Cobertura XML report myself and also have no experience with the format or its implementation in PHPUnit.
Maybe @smmccabe, @bastien-phi, @dvdoug, @jseniuk, or @tm1000, who have worked on this code in the past, can help.
I actually only used Cobertura for https://github.com/clearlyip/code-coverage-report-action (for support) but I use clover myself
We are working with one legacy PHP project that contains about 3000 classes and over 1000 global functions. We try to plug in the code coverage feature to our gitlab. When I tried to export the coverage report to Cobertura XML format, I received a Killed Error from Linux:
I simulated the situation by simple files (https://github.com/SolovievEvgenii/cobertura_bug1), debugged the Cobertura class and found that the nodes of all our global functions is included in the body of each package (which corresponds to a single file), although in reality the file may not have any relationship with global functions, no calls. no definitions. Look at the screenshot with resulted XML and the corresponded codes:
Pay attention at nodes, underlined by magenta lines, these nodes are talking about two different methods, but both are pointing to the same line. It is wrong, is it? It happens because at each package's iteration the list of functions is taken from global scope instead of list from package's functions
To get the fixed XML I added to your code my little crutch, I take a list of functions not from an iterating element "item", but from element from "children" array of the "report" object.
See the function with my try to fix here
At last I'he got the cobertura format of our big project without any killings. But I am not sure that it is really right, is it difficult to validate the report of large project. I suspect that my fix is not optimized way and hope to receive feedback about the correctness of this approach.