PHPCoverage Code
Status: Beta
Brought to you by:
pnimish
| a/samples/remote/codeCoverageMain.php | b/samples/remote/codeCoverageMain.php | ||
|---|---|---|---|
... |
... |
||
| 15 | if(empty($PHPCOVERAGE_REPORT_DIR)) { |
15 | if(empty($PHPCOVERAGE_REPORT_DIR)) { |
| 16 | $PHPCOVERAGE_REPORT_DIR = "report"; |
16 | $PHPCOVERAGE_REPORT_DIR = "report"; |
| 17 | } |
17 | } |
| 18 | $web_url = "http://localhost/coverage/"; |
18 | $web_url = "http://localhost/coverage/"; |
| 19 | $cov_url = $web_url . "phpcoverage.remote.top.inc.php"; |
19 | $cov_url = $web_url . "phpcoverage.remote.top.inc.php"; |
| 20 | // Session 1 |
||
| 20 | file_get_contents($cov_url . "?phpcoverage-action=init&cov-file-name=". urlencode("phpcoverage.data.xml") . "&tmp-dir=". urlencode("/tmp")); |
21 | file_get_contents($cov_url . "?phpcoverage-action=init&cov-file-name=". urlencode("phpcoverage.data.xml") . "&tmp-dir=". urlencode("/tmp")); |
| 21 | 22 | $str = file_get_contents($web_url . "sample.php"); |
|
| 22 | file_get_contents($web_url . "sample.php"); |
23 | file_put_contents("/tmp/data1.xml", file_get_contents($cov_url . "?phpcoverage-action=get-coverage-xml")); |
| 24 | file_get_contents($cov_url . "?phpcoverage-action=cleanup"); |
||
| 25 | |||
| 26 | // Session 2 |
||
| 27 | file_get_contents($cov_url . "?phpcoverage-action=init&cov-file-name=". urlencode("phpcoverage.data2.xml") . "&tmp-dir=". urlencode("/tmp")); |
||
| 28 | $str = file_get_contents($web_url . "sample2.php"); |
||
| 29 | file_put_contents("/tmp/data2.xml", file_get_contents($cov_url . "?phpcoverage-action=get-coverage-xml")); |
||
| 30 | file_get_contents($cov_url . "?phpcoverage-action=cleanup"); |
||
| 31 | |||
| 32 | // Session 3 |
||
| 33 | file_get_contents($cov_url . "?phpcoverage-action=init&cov-file-name=". urlencode("phpcoverage.data.xml") . "&tmp-dir=". urlencode("/tmp")); |
||
| 34 | $str = file_get_contents($web_url . "sample.php"); |
||
| 35 | file_put_contents("/tmp/data3.xml", file_get_contents($cov_url . "?phpcoverage-action=get-coverage-xml")); |
||
| 36 | file_get_contents($cov_url . "?phpcoverage-action=cleanup"); |
||
| 23 | 37 | ||
| 24 | // Configure reporter, and generate report |
38 | // Configure reporter, and generate report |
| 25 | $covReporter = new HtmlCoverageReporter( |
39 | $covReporter = new HtmlCoverageReporter( |
| 26 | "Sample Web Test Code Coverage", "", $PHPCOVERAGE_REPORT_DIR); |
40 | "Sample Web Test Code Coverage", "", $PHPCOVERAGE_REPORT_DIR); |
| 27 | $excludePaths = array(); |
41 | $excludePaths = array(); |
... |
... |
||
| 30 | $includePaths = array(realpath($PHPCOVERAGE_APPBASE_PATH)); |
44 | $includePaths = array(realpath($PHPCOVERAGE_APPBASE_PATH)); |
| 31 | 45 | ||
| 32 | // Notice the coverage recorder is of type RemoteCoverageRecorder |
46 | // Notice the coverage recorder is of type RemoteCoverageRecorder |
| 33 | $cov = new RemoteCoverageRecorder($includePaths, $excludePaths, $covReporter); |
47 | $cov = new RemoteCoverageRecorder($includePaths, $excludePaths, $covReporter); |
| 34 | // Pass the code coverage XML url into the generateReport function |
48 | // Pass the code coverage XML url into the generateReport function |
| 35 | $cov->generateReport($cov_url . "?phpcoverage-action=get-coverage-xml", true); |
49 | //$cov->generateReport($cov_url . "?phpcoverage-action=get-coverage-xml", true); |
| 50 | $cov->generateReport(array("/tmp/data1.xml", "/tmp/data2.xml", "/tmp/data3.xml"), true); |
||
| 36 | $covReporter->printTextSummary($PHPCOVERAGE_REPORT_DIR . "/report.txt"); |
51 | $covReporter->printTextSummary($PHPCOVERAGE_REPORT_DIR . "/report.txt"); |
| 37 | // Clean up |
52 | // Clean up |
| 38 | file_get_contents($cov_url . "?phpcoverage-action=cleanup"); |
53 | // file_get_contents($cov_url . "?phpcoverage-action=cleanup"); |
| 39 | 54 | ||
| 40 | ?> |
55 | ?> |