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?

有帮助吗?

解决方案 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

其他提示

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top