I am working on a customized application to parse through the clover.xml
report.
Just wondering if anybody knows which is the correct formula to get the Classes and Traits
total coverage percentage.
Here's the formulas that I found for Lines
and Functions&Methods
coverage:
// TPC = (coveredconditionals + coveredstatements + coveredmethods) / (conditionals + statements + methods)
phpMetric.project = (((phpMetric.coveredconditionals + phpMetric.coveredstatements + phpMetric.coveredmethods) / (phpMetric.conditionals + phpMetric.statements + phpMetric.methods))) * 100;
// Lines coverage formula - LTPC = (coveredstatements / statements) * 100
phpMetric.lines = ((phpMetric.coveredstatements / phpMetric.statements)* 100);
// Functions and Methods coverage formula - FMTPC = (coveredmethods / methods) * 100
phpMetric.functions = ((phpMetric.coveredmethods / phpMetric.methods)* 100);
And this is the metrics
from clover.xml
<metrics files="10070" loc="1354443" ncloc="1110810" classes="8575" methods="46082" coveredmethods="31707" conditionals="0" coveredconditionals="0" statements="561696" coveredstatements="371009" elements="607778" coveredelements="402716"/>
Update:
The information that I wanna extract from the report is the column Classes and Traits
, the total coverage %.
Thanks!
I don't know anything about clover, but - if I understand you correctly - you can use php (which is tagged in your question) do something like the following. Obviously, you can then modify it as necessary:
$cloverstr = <<<SOMEXML
<root>
<metrics files="10070" loc="1354443" ncloc="1110810" classes="8575" methods="46082" coveredmethods="31707" conditionals="0" coveredconditionals="0" statements="561696" coveredstatements="371009" elements="607778" coveredelements="402716" />
</root>
SOMEXML;
$xml = simplexml_load_string ($cloverstr);
$coveredmethods = $xml->xpath("//metrics/@coveredmethods");
$methods = $xml->xpath("//metrics/@methods");
$coveredstatements = $xml->xpath("//metrics/@coveredstatements");
$statements = $xml->xpath("//metrics/@statements");
$coveredelements = $xml->xpath("//metrics/@coveredelements");
$elements = $xml->xpath("//metrics/@elements");
$TCP = ($coveredmethods[0] / $methods[0]) * 100;
$LTPC = ($coveredstatements[0] / $statements[0]) * 100;
$XYZ = ($coveredelements[0] / $elements[0]) * 100;
echo ("TCP: " . $TCP . ' </br> ');
echo ("LTPC: " . $LTPC . ' </br> ');
echo ("XYZ: " . $XYZ);
Output:
TCP: 68.805607395512
LTPC: 66.0515652595
XYZ: 66.260377966955