|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 /* 00003 * $Id: driver.php,v 1.2 2010/12/14 17:35:49 moodlerobot Exp $ 00004 * 00005 * Copyright(c) 2004-2006, SpikeSource Inc. All Rights Reserved. 00006 * Licensed under the Open Software License version 2.1 00007 * (See http://www.spikesource.com/license.html) 00008 */ 00009 ?> 00010 <?php 00021 if(!defined("__PHPCOVERAGE_HOME")) { 00022 define("__PHPCOVERAGE_HOME", dirname(dirname(__FILE__))); 00023 } 00024 require_once __PHPCOVERAGE_HOME . "/conf/phpcoverage.conf.php"; 00025 require_once __PHPCOVERAGE_HOME . "/util/Utility.php"; 00026 00027 // ###################################################################### 00028 // ###################################################################### 00029 00030 function usage() { 00031 global $util; 00032 echo "Usage: " . $_SERVER['argv'][0] . " <options>\n"; 00033 echo "\n"; 00034 echo " Options: \n"; 00035 echo " --phpcoverage-home <path> OR -p <path> Path to PHPCoverage home (defaults to PHPCOVERAGE_HOME environment property)\n"; 00036 echo " --init Initialize PHPCoverage Reporting\n"; 00037 echo " --report Generate PHPCoverage Report\n"; 00038 echo " --local Run and generate PHPCoverage report for local test run (Implies '--report')\n"; 00039 echo " --cleanup Remove existing PHPCoverage data\n"; 00040 echo " init options \n"; 00041 echo " --cov-url <url> Specify application default url\n"; 00042 echo " --tmp-dir <path> Specify tmp directory location (Defaults to '" . $util->getTmpDir() . "')\n"; 00043 echo " --cov-file-name <name> Specify coverage data file name (Defaults to 'phpcoverage.data.xml')\n"; 00044 echo " remote report options \n"; 00045 echo " --cov-data-files <path1,path2,...> Coverage data file path [use this instead of --cov-url for a local file path]\n"; 00046 echo " --report-name <name> Report name\n"; 00047 echo " --report-dir <path> Report directory path (Defaults to 'report')\n"; 00048 echo " --appbase-path <path> Application base path (Defaults to PHPCOVERAGE_APPBASE_PATH if specified on the command line)\n"; 00049 echo " --include-paths <path1,path2,...> Comma-separated paths to include in code coverage report. (Includes appbase-path by default)\n"; 00050 echo " --exclude-paths <path1,path2,...> Comma-separated paths to exclude from code coverage report.\n"; 00051 echo " --print-summary Print coverage report summary to console.\n"; 00052 echo " local report options \n"; 00053 echo " --report-name <name> Report name\n"; 00054 echo " --report-dir <path> Report directory path (Defaults to 'report')\n"; 00055 echo " --appbase-path <path> Application base path (Defaults to PHPCOVERAGE_APPBASE_PATH if specified on the command line)\n"; 00056 echo " --include-paths <path1,path2,...> Comma-separated paths to include in code coverage report.\n"; 00057 echo " --exclude-paths <path1,path2,...> Comma-separated paths to exclude from code coverage report.\n"; 00058 echo " --print-summary Print coverage report summary to console.\n"; 00059 echo " --test-driver <path> Path to the test driver file.\n"; 00060 echo " other options \n"; 00061 echo " --verbose OR -v Print verbose information\n"; 00062 echo " --help OR -h Display this usage information\n"; 00063 echo ""; 00064 echo " Sample Usage (local execution):\n"; 00065 echo " php driver.php --local --report \\ \n"; 00066 echo " -p /opt/phpcoverage/src \\ \n"; 00067 echo " --report-name 'Test Report' --report-dir /tmp/report \\ \n"; 00068 echo " --appbase-path /opt/phpcoverage/samples/local \\ \n"; 00069 echo " --test-driver /opt/phpcoverage/samples/local/test_driver.php \\ \n"; 00070 echo " --print-summary \n"; 00071 exit; 00072 } 00073 00074 // 00075 // Setup command line argument processing 00076 // 00077 00078 $OPTION["p"] = false; 00079 $OPTION['verbose'] = false; 00080 $OPTION['init'] = false; 00081 $OPTION['report'] = false; 00082 $OPTION['cleanup'] = false; 00083 $OPTION['cov-url'] = false; 00084 $OPTION['report-name'] = false; 00085 $OPTION['report-dir'] = false; 00086 $OPTION['tmp-dir'] = false; 00087 $OPTION['cov-file-name'] = false; 00088 $OPTION['cov-data-files'] = false; 00089 $OPTION['appbase-path'] = false; 00090 $OPTION['local'] = false; 00091 $OPTION['test-driver'] = false; 00092 00093 // 00094 // loop through our arguments and see what the user selected 00095 // 00096 00097 for ($i = 1; $i < $_SERVER["argc"]; $i++) { 00098 switch($_SERVER["argv"][$i]) { 00099 case "--phpcoverage-home": 00100 case "-p": 00101 $OPTION['p'] = $_SERVER['argv'][++$i]; 00102 break; 00103 case "-v": 00104 case "--verbose": 00105 $OPTION['verbose'] = true; 00106 break; 00107 case "--init": 00108 $OPTION['init'] = true; 00109 break; 00110 case "--report": 00111 $OPTION['report'] = true; 00112 break; 00113 case "--local": 00114 $OPTION['local'] = true; 00115 $OPTION['report'] = true; 00116 break; 00117 case "--cleanup": 00118 $OPTION['cleanup'] = true; 00119 break; 00120 case "--cov-url": 00121 $OPTION['cov-url'] = $_SERVER['argv'][++$i] . "/" . "phpcoverage.remote.top.inc.php"; 00122 break; 00123 case "--tmp-dir": 00124 $OPTION['tmp-dir'] = $_SERVER['argv'][++$i]; 00125 break; 00126 case "--cov-file-name": 00127 $OPTION['cov-file-name'] = $_SERVER['argv'][++$i]; 00128 break; 00129 case "--cov-data-files": 00130 $OPTION['cov-data-files'] = $_SERVER['argv'][++$i]; 00131 break; 00132 case "--report-name": 00133 $OPTION['report-name'] = $_SERVER['argv'][++$i]; 00134 break; 00135 case "--report-dir": 00136 $OPTION['report-dir'] = $_SERVER['argv'][++$i]; 00137 break; 00138 case "--appbase-path": 00139 $OPTION['appbase-path'] = $_SERVER['argv'][++$i]; 00140 break; 00141 case "--include-paths": 00142 $OPTION['include-paths'] = $_SERVER['argv'][++$i]; 00143 break; 00144 case "--exclude-paths": 00145 $OPTION['exclude-paths'] = $_SERVER['argv'][++$i]; 00146 break; 00147 case "--print-summary": 00148 $OPTION['print-summary'] = true; 00149 break; 00150 case "--test-driver": 00151 $OPTION['test-driver'] = $_SERVER['argv'][++$i]; 00152 break; 00153 case "--help": 00154 case "-h": 00155 usage(); 00156 break; 00157 } 00158 } 00159 00160 if($OPTION['p'] == false) { 00161 $OPTION['p'] = __PHPCOVERAGE_HOME; 00162 if(empty($OPTION['p']) || !is_dir($OPTION['p'])) { 00163 die("PHPCOVERAGE_HOME does not exist. [" . $OPTION['p'] . "]"); 00164 } 00165 } 00166 00167 putenv("PHPCOVERAGE_HOME=" . $OPTION['p']); 00168 00169 require_once $OPTION['p'] . "/phpcoverage.inc.php"; 00170 require_once PHPCOVERAGE_HOME . "/remote/RemoteCoverageRecorder.php"; 00171 require_once PHPCOVERAGE_HOME . "/reporter/HtmlCoverageReporter.php"; 00172 00173 // Initializations 00174 $includePaths = array(); 00175 $excludePaths = array(); 00176 00177 if (!$OPTION['cov-url']){ 00178 if(!$OPTION['report'] && !$OPTION['cov-data-files']) { 00179 echo "ERROR: No --cov-url option specified.\n"; 00180 exit(1); 00181 } 00182 } 00183 00184 if($OPTION['init']) { 00185 if(!$OPTION['tmp-dir']) { 00186 $OPTION['tmp-dir'] = $util->getTmpDir(); 00187 } 00188 if(!$OPTION['cov-file-name']) { 00189 $OPTION['cov-file-name'] = "phpcoverage.data.xml"; 00190 } 00191 } 00192 00193 if($OPTION['report']) { 00194 if (!$OPTION['report-name']){ 00195 echo "ERROR: No --report-name option specified.\n"; 00196 exit(1); 00197 } 00198 00199 if(!$OPTION['report-dir']) { 00200 if(!empty($PHPCOVERAGE_REPORT_DIR)) { 00201 $OPTION["report-dir"] = $PHPCOVERAGE_REPORT_DIR; 00202 } 00203 else { 00204 $OPTION["report-dir"] = "report"; 00205 } 00206 } 00207 00208 if(empty($OPTION['appbase-path']) && !empty($PHPCOVERAGE_APPBASE_PATH)) { 00209 $OPTION['appbase-path'] = realpath($PHPCOVERAGE_APPBASE_PATH); 00210 } 00211 00212 if(isset($OPTION['include-paths'])) { 00213 $includePaths = explode(",", $OPTION['include-paths']); 00214 } 00215 if(isset($OPTION['appbase-path']) && !empty($OPTION["appbase-path"])) { 00216 $includePaths[] = $OPTION['appbase-path']; 00217 } 00218 00219 if(isset($OPTION['exclude-paths'])) { 00220 $excludePaths = explode(",", $OPTION['exclude-paths']); 00221 } 00222 00223 if($OPTION['local']) { 00224 //local coverage run 00225 if(empty($OPTION['test-driver'])) { 00226 echo "Error: No test driver file specified.\n"; 00227 exit(1); 00228 } 00229 if(!is_file($OPTION['test-driver'])) { 00230 echo "Error: No such file: " . $OPTION['test-driver'] . "\n"; 00231 exit(1); 00232 } 00233 $excludePaths[] = $OPTION['test-driver']; 00234 } 00235 } 00236 00237 if ($OPTION['verbose']){ 00238 echo "Options: " . print_r($OPTION, true) . "\n"; 00239 echo "include-paths: " . print_r($includePaths, true) . "\n"; 00240 echo "exclude-paths: " . print_r($excludePaths, true) . "\n"; 00241 } 00242 00243 // 00244 // 00245 // 00246 00247 if ($OPTION['init']){ 00248 echo "PHPCoverage: init " . $OPTION['cov-url'] . "?phpcoverage-action=init&cov-file-name=". urlencode($OPTION["cov-file-name"]) . "&tmp-dir=" . urlencode($OPTION['tmp-dir']) . "\n"; 00249 00250 // 00251 // Initialize the PHPCoverage reporting framework 00252 // 00253 00254 file_get_contents($OPTION['cov-url'] . "?phpcoverage-action=init&cov-file-name=". urlencode($OPTION["cov-file-name"]) . "&tmp-dir=" . urlencode($OPTION['tmp-dir'])); 00255 00256 } 00257 else if ($OPTION['report']){ 00258 00259 if(empty($OPTION['local'])) { 00260 00261 // 00262 // Retrieve coverage data (xml) from the PHPCoverage reporting framework 00263 // 00264 00265 if($OPTION['cov-data-files']) { 00266 $OPTION['cov-data-fileset'] = explode(",", $OPTION['cov-data-files']); 00267 foreach($OPTION['cov-data-fileset'] as $covDataFile) { 00268 if(!is_readable($covDataFile)) { 00269 echo "Error: Cannot read cov-data-file: " . $covDataFile . "\n"; 00270 exit(1); 00271 } 00272 $xmlUrl[] = $covDataFile; 00273 } 00274 } 00275 else { 00276 echo "PHPCoverage: report " . $OPTION['cov-url'] . "?phpcoverage-action=get-coverage-xml" . "\n"; 00277 $xmlUrl = $OPTION['cov-url'] . "?phpcoverage-action=get-coverage-xml"; 00278 } 00279 00280 // 00281 // Configure reporter, and generate the PHPCoverage report 00282 // 00283 00284 $covReporter = new HtmlCoverageReporter($OPTION['report-name'], "", $OPTION["report-dir"]); 00285 00286 // 00287 // Notice the coverage recorder is of type RemoteCoverageRecorder 00288 // 00289 00290 $cov = new RemoteCoverageRecorder($includePaths, $excludePaths, $covReporter); 00291 $cov->generateReport($xmlUrl, true); 00292 $covReporter->printTextSummary($OPTION["report-dir"] . "/report.txt"); 00293 // Should the summary be printed to console ? 00294 if(isset($OPTION['print-summary']) && $OPTION['print-summary']) { 00295 $covReporter->printTextSummary(); 00296 } 00297 } 00298 else { 00299 // 00300 // Configure reporter, and generate the PHPCoverage report 00301 // 00302 00303 $covReporter = new HtmlCoverageReporter($OPTION['report-name'], "", $OPTION["report-dir"]); 00304 00305 $cov = new CoverageRecorder($includePaths, $excludePaths, $covReporter); 00306 $cov->startInstrumentation(); 00307 echo "\n>>>>>>>>>>>>>>>>>>> Output from the test driver begins\n\n"; 00308 include $OPTION['test-driver']; 00309 echo "\n\nOutput from the test driver ends <<<<<<<<<<<<<<<<<<<<<\n"; 00310 $cov->stopInstrumentation(); 00311 $cov->generateReport(); 00312 $covReporter->printTextSummary($OPTION["report-dir"] . "/report.txt"); 00313 // Should the summary be printed to console ? 00314 if(isset($OPTION['print-summary']) && $OPTION['print-summary']) { 00315 $covReporter->printTextSummary(); 00316 } 00317 } 00318 } 00319 else if ($OPTION['cleanup']){ 00320 00321 echo "PHPCoverage: cleanup " . $OPTION['cov-url'] . "?phpcoverage-action=cleanup"; 00322 file_get_contents($OPTION['cov-url'] . "?phpcoverage-action=cleanup"); 00323 00324 } 00325 00326 ?> 00327