Stop phing deployment if code coverage is below 85

2019-07-07 21:07发布

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条回答
ら.Afraid
2楼-- · 2019-07-07 21:25

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

查看更多
太酷不给撩
3楼-- · 2019-07-07 21:37

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

查看更多
登录 后发表回答