Question

Am using a phing to deploy my php code but we need to add a condition to stop the deployment if any of the PHP Unit test cases fails or code coverage is less than 85%

We were able to add the PHP Unit test case condition by adding following code in built.xml

<phpunit  haltonerror="true" haltonfailure="true" printsummary="true">
</phpunit>

Now i need to test for the code coverage percentage, Please let me know how can i do that?

Était-ce utile?

La solution 2

To get the code coverage Percentage you can use clover Report, which will generate xml file.

From the xml file you can read the Statements and coveredstatements which will constitute you Total percentage

Clover Report can be generated using following command:

phpunit  --coverage-html ./code_Coverage_Report --coverage-clover ./cloverReport.xml codecoverage_test/CodeCoverage.php

--coverage-html: will generate the report in HTML format

./code_Coveerage_Report: will create a folder and the coverage clover report will be generate inside that folder

--coverage-clover: will generate a clover report

./cloverReport.xml: will generate an xml file for clover report

codecoverage_test/CodeCoverage.php: The file for which i need to generate coverage report

Autres conseils

With Phing's own PHPunit task being used, you could potentially use CoverageThresholdTask (http://www.phing.info/docs/guide/stable/apcs05.html)

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top