runtest.php
来自「视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.」· PHP 代码 · 共 849 行 · 第 1/3 页
PHP
849 行
<?php/** * PEAR_RunTest * * PHP versions 4 and 5 * * LICENSE: This source file is subject to version 3.0 of the PHP license * that is available through the world-wide-web at the following URI: * http://www.php.net/license/3_0.txt. If you did not receive a copy of * the PHP License and are unable to obtain it through the web, please * send a note to license@php.net so we can mail you a copy immediately. * * @category pear * @package PEAR * @author Tomas V.V.Cox <cox@idecnet.com> * @author Greg Beaver <cellog@php.net> * @copyright 1997-2006 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version CVS: $Id: RunTest.php,v 1.45 2007/06/19 03:10:49 cellog Exp $ * @link http://pear.php.net/package/PEAR * @since File available since Release 1.3.3 *//** * for error handling */require_once 'PEAR.php';require_once 'PEAR/Config.php';define('DETAILED', 1);putenv("PHP_PEAR_RUNTESTS=1");/** * Simplified version of PHP's test suite * * Try it with: * * $ php -r 'include "../PEAR/RunTest.php"; $t=new PEAR_RunTest; $o=$t->run("./pear_system.phpt");print_r($o);' * * * @category pear * @package PEAR * @author Tomas V.V.Cox <cox@idecnet.com> * @author Greg Beaver <cellog@php.net> * @copyright 1997-2006 The PHP Group * @license http://www.php.net/license/3_0.txt PHP License 3.0 * @version Release: 1.6.1 * @link http://pear.php.net/package/PEAR * @since Class available since Release 1.3.3 */class PEAR_RunTest{ var $_headers = array(); var $_logger; var $_options; var $_php; var $test_count; var $xdebug_loaded; var $ini_overwrites = array( 'output_handler=', 'open_basedir=', 'safe_mode=0', 'disable_functions=', 'output_buffering=Off', 'display_errors=1', 'log_errors=0', 'html_errors=0', 'track_errors=1', 'report_memleaks=0', 'report_zend_debug=0', 'docref_root=', 'docref_ext=.html', 'error_prepend_string=', 'error_append_string=', 'auto_prepend_file=', 'auto_append_file=', 'magic_quotes_runtime=0', 'xdebug.default_enable=0', 'allow_url_fopen=1', ); /** * An object that supports the PEAR_Common->log() signature, or null * @param PEAR_Common|null */ function PEAR_RunTest($logger = null, $options = array()) { $this->ini_overwrites[] = 'error_reporting=' . E_ALL; if (is_null($logger)) { require_once 'PEAR/Common.php'; $logger = new PEAR_Common; } $this->_logger = $logger; $this->_options = $options; $conf = &PEAR_Config::singleton(); $this->_php = $conf->get('php_bin'); } /** * Taken from php-src/run-tests.php * * @param string $commandline command name * @param array $env * @param string $stdin standard input to pass to the command * @return unknown */ function system_with_timeout($commandline, $env = null, $stdin = null) { $data = ''; if (version_compare(phpversion(), '5.0.0', '<')) { $proc = proc_open($commandline, array( 0 => array('pipe', 'r'), 1 => array('pipe', 'w'), 2 => array('pipe', 'w') ), $pipes); } else { $proc = proc_open($commandline, array( 0 => array('pipe', 'r'), 1 => array('pipe', 'w'), 2 => array('pipe', 'w') ), $pipes, null, $env, array('suppress_errors' => true)); } if (!$proc) { return false; } if (is_string($stdin)) { fwrite($pipes[0], $stdin); } fclose($pipes[0]); while (true) { /* hide errors from interrupted syscalls */ $r = $pipes; $e = $w = null; $n = @stream_select($r, $w, $e, 60); if ($n === 0) { /* timed out */ $data .= "\n ** ERROR: process timed out **\n"; proc_terminate($proc); return array(1234567890, $data); } else if ($n > 0) { $line = fread($pipes[1], 8192); if (strlen($line) == 0) { /* EOF */ break; } $data .= $line; } } if (function_exists('proc_get_status')) { $stat = proc_get_status($proc); if ($stat['signaled']) { $data .= "\nTermsig=".$stat['stopsig']; } } $code = proc_close($proc); if (function_exists('proc_get_status')) { $code = $stat['exitcode']; } return array($code, $data); } function settings2array($settings, $ini_settings) { foreach ($settings as $setting) { if (strpos($setting, '=')!== false) { $setting = explode('=', $setting, 2); $name = trim(strtolower($setting[0])); $value = trim($setting[1]); $ini_settings[$name] = $value; } } return $ini_settings; } function settings2params($ini_settings) { $settings = ''; foreach ($ini_settings as $name => $value) { $value = addslashes($value); $settings .= " -d \"$name=$value\""; } return $settings; } function runPHPUnit($file, $ini_settings = '') { $cmd = "$this->_php$ini_settings -f $file"; if (isset($this->_logger)) { $this->_logger->log(2, 'Running command "' . $cmd . '"'); } $savedir = getcwd(); // in case the test moves us around chdir(dirname($file)); echo `$cmd`; chdir($savedir); return 'PASSED'; // we have no way of knowing this information so assume passing } // // Run an individual test case. // function run($file, $ini_settings = '', $test_number) { if (empty($this->_options['cgi'])) { // try to see if php-cgi is in the path if (false !== $this->system_with_timeout('php-cgi -v')) { $this->_options['cgi'] = 'php-cgi'; } } if (1 < $len = strlen($this->tests_count)) { $test_number = str_pad($test_number, $len, ' ', STR_PAD_LEFT); $test_nr = "[$test_number/$this->tests_count] "; } else { $test_nr = ''; } $file = realpath($file); $section_text = $this->_readFile($file); if (PEAR::isError($section_text)) { return $section_text; } if (isset($section_text['POST_RAW']) && isset($section_text['UPLOAD'])) { return PEAR::raiseError("Cannot contain both POST_RAW and UPLOAD in test file: $file"); } $cwd = getcwd(); $pass_options = ''; if (!empty($this->_options['ini'])) { $pass_options = $this->_options['ini']; } $ini_settings = $this->settings2array($this->ini_overwrites, $ini_settings); if ($section_text['INI']) { if (strpos($section_text['INI'], '{PWD}') !== false) { $section_text['INI'] = str_replace('{PWD}', dirname($file), $section_text['INI']); } $ini = preg_split( "/[\n\r]+/", $section_text['INI']); $ini_settings = $this->settings2array($ini, $ini_settings); } $ini_settings = $this->settings2params($ini_settings); $shortname = str_replace($cwd . DIRECTORY_SEPARATOR, '', $file); $tested = trim($section_text['TEST']); $tested.= !isset($this->_options['simple']) ? "[$shortname]" : ' '; if (!empty($section_text['POST']) || !empty($section_text['POST_RAW']) || !empty($section_text['UPLOAD']) || !empty($section_text['GET']) || !empty($section_text['COOKIE']) || !empty($section_text['EXPECTHEADERS'])) { if (empty($this->_options['cgi'])) { if (!isset($this->_options['quiet'])) { $this->_logger->log(0, "SKIP $test_nr$tested (reason: --cgi option needed for this test, type 'pear help run-tests')"); } if (isset($this->_options['tapoutput'])) { return array('ok', ' # skip --cgi option needed for this test, "pear help run-tests" for info'); } return 'SKIPPED'; } $this->_php = $this->_options['cgi']; } $temp_dir = realpath(dirname($file)); $main_file_name = basename($file, 'phpt'); $diff_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name.'diff'; $log_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name.'log'; $exp_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name.'exp'; $output_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name.'out'; $memcheck_filename = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name.'mem'; $temp_file = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name.'php'; $temp_skipif = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name.'skip.php'; $temp_clean = $temp_dir . DIRECTORY_SEPARATOR . $main_file_name.'clean.php'; $tmp_post = $temp_dir . DIRECTORY_SEPARATOR . uniqid('phpt.'); // unlink old test results $this->_cleanupOldFiles($file);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?