Bearsampp 2026.9.23
Loading...
Searching...
No Matches
PEAR_RunTest Class Reference

Public Member Functions

 __construct ($logger=null, $options=array())
 _preparePhpBin ($php, $file, $ini_settings)
 iniString2array ($ini_string)
 run ($file, $ini_settings=array(), $test_number=1)
 runPHPUnit ($file, $ini_settings='')
 settings2array ($settings, $ini_settings)
 settings2params ($ini_settings)
 system_with_timeout ($commandline, $env=null, $stdin=null)

Data Fields

 $_headers = array()
 $_logger
 $_options
 $_php
 $_savephp
 $ini_overwrites
 $tests_count
 $xdebug_loaded

Detailed Description

Definition at line 44 of file RunTest.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( $logger = null,
$options = array() )

An object that supports the PEAR_Common->log() signature, or null

Parameters
PEAR_Common|null

Definition at line 82 of file RunTest.php.

83 {
84 if (!defined('E_DEPRECATED')) {
85 define('E_DEPRECATED', 0);
86 }
87 if (!defined('E_STRICT')) {
88 define('E_STRICT', 0);
89 }
90 $excluded_error_reporting = E_DEPRECATED;
91 if (!defined('PHP_VERSION_ID') || PHP_VERSION_ID < 80400) {
92 $excluded_error_reporting |= E_STRICT;
93 }
94 $this->ini_overwrites[] = 'error_reporting=' . (E_ALL & ~$excluded_error_reporting);
95 if (!defined('PHP_VERSION_ID') || PHP_VERSION_ID < 80500) {
96 $this->ini_overwrites[] = 'report_memleaks=0';
97 }
98 if (is_null($logger)) {
99 require_once 'PEAR/Common.php';
100 $logger = new PEAR_Common;
101 }
102 $this->_logger = $logger;
103 $this->_options = $options;
104
105 $conf = &PEAR_Config::singleton();
106 $this->_php = $conf->get('php_bin');
107 }
$options
Definition pearcmd.php:145

References $options.

Member Function Documentation

◆ _preparePhpBin()

_preparePhpBin ( $php,
$file,
$ini_settings )

Definition at line 226 of file RunTest.php.

227 {
228 $file = escapeshellarg($file);
229 $cmd = $php . $ini_settings . ' -f ' . $file;
230
231 return $cmd;
232 }

Referenced by run(), and runPHPUnit().

Here is the caller graph for this function:

◆ iniString2array()

iniString2array ( $ini_string)

Turns a PHP INI string into an array

Turns -d "include_path=/foo/bar" into this: array( 'include_path' => array( 'operator' => '-d', 'value' => '/foo/bar', ) ) Works both with quotes and without

Parameters
stringan PHP INI string, -d "include_path=/foo/bar"
Returns
array

Definition at line 184 of file RunTest.php.

185 {
186 if (!$ini_string) {
187 return array();
188 }
189 $split = preg_split('/[\s]|=/', $ini_string, -1, PREG_SPLIT_NO_EMPTY);
190 $key = $split[1][0] == '"' ? substr($split[1], 1) : $split[1];
191 $value = $split[2][strlen($split[2]) - 1] == '"' ? substr($split[2], 0, -1) : $split[2];
192 // FIXME review if this is really the struct to go with
193 $array = array($key => array('operator' => $split[0], 'value' => $value));
194 return $array;
195 }

Referenced by run().

Here is the caller graph for this function:

◆ run()

run ( $file,
$ini_settings = array(),
$test_number = 1 )

Runs an individual test case.

Parameters
stringThe filename of the test
array|stringINI settings to be applied to the test run
integerNumber what the current running test is of the whole test suite being runned.
Returns
string|object Returns PASSED, WARNED, FAILED depending on how the test came out. PEAR Error when the tester it self fails

Definition at line 266 of file RunTest.php.

References _cleanupOldFiles(), _preparePhpBin(), _processHeaders(), _processUpload(), _readFile(), _resetEnv(), _restorePHPBinary(), _runSkipIf(), _savePHPBinary(), _stripHeadersCGI(), _testCleanup(), _writeLog(), generate_diff(), iniString2array(), save_text(), settings2array(), settings2params(), and system_with_timeout().

Here is the call graph for this function:

◆ runPHPUnit()

runPHPUnit ( $file,
$ini_settings = '' )

Definition at line 234 of file RunTest.php.

235 {
236 if (!file_exists($file) && file_exists(getcwd() . DIRECTORY_SEPARATOR . $file)) {
237 $file = realpath(getcwd() . DIRECTORY_SEPARATOR . $file);
238 } elseif (file_exists($file)) {
239 $file = realpath($file);
240 }
241
242 $cmd = $this->_preparePhpBin($this->_php, $file, $ini_settings);
243 if (isset($this->_logger)) {
244 $this->_logger->log(2, 'Running command "' . $cmd . '"');
245 }
246
247 $savedir = getcwd(); // in case the test moves us around
248 chdir(dirname($file));
249 echo `$cmd`;
250 chdir($savedir);
251 return 'PASSED'; // we have no way of knowing this information so assume passing
252 }
_preparePhpBin($php, $file, $ini_settings)
Definition RunTest.php:226

References _preparePhpBin().

Here is the call graph for this function:

◆ settings2array()

settings2array ( $settings,
$ini_settings )

Definition at line 197 of file RunTest.php.

198 {
199 foreach ($settings as $setting) {
200 if (strpos($setting, '=') !== false) {
201 $setting = explode('=', $setting, 2);
202 $name = trim(strtolower($setting[0]));
203 $value = trim($setting[1]);
204 $ini_settings[$name] = $value;
205 }
206 }
207 return $ini_settings;
208 }

Referenced by run().

Here is the caller graph for this function:

◆ settings2params()

settings2params ( $ini_settings)

Definition at line 210 of file RunTest.php.

211 {
212 $settings = '';
213 foreach ($ini_settings as $name => $value) {
214 if (is_array($value)) {
215 $operator = $value['operator'];
216 $value = $value['value'];
217 } else {
218 $operator = '-d';
219 }
220 $value = addslashes($value);
221 $settings .= " $operator \"$name=$value\"";
222 }
223 return $settings;
224 }

Referenced by run().

Here is the caller graph for this function:

◆ system_with_timeout()

system_with_timeout ( $commandline,
$env = null,
$stdin = null )

Taken from php-src/run-tests.php

Parameters
string$commandlinecommand name
array$env
string$stdinstandard input to pass to the command
Returns
unknown

Definition at line 117 of file RunTest.php.

118 {
119 $data = '';
120 $proc = proc_open($commandline, array(
121 0 => array('pipe', 'r'),
122 1 => array('pipe', 'w'),
123 2 => array('pipe', 'w')
124 ), $pipes, null, $env, array('suppress_errors' => true));
125
126 if (!$proc) {
127 return false;
128 }
129
130 if (is_string($stdin)) {
131 fwrite($pipes[0], $stdin);
132 }
133 fclose($pipes[0]);
134
135 while (true) {
136 /* hide errors from interrupted syscalls */
137 $r = $pipes;
138 unset($r[0]);
139 $e = $w = [];
140 $n = @stream_select($r, $w, $e, 60);
141
142 if ($n === 0) {
143 /* timed out */
144 $data .= "\n ** ERROR: process timed out **\n";
145 proc_terminate($proc);
146 return array(1234567890, $data);
147 } else if ($n > 0) {
148 $line = fread($pipes[1], 8192);
149 if (strlen($line) == 0) {
150 /* EOF */
151 break;
152 }
153 $data .= $line;
154 }
155 }
156 if (function_exists('proc_get_status')) {
157 $stat = proc_get_status($proc);
158 if ($stat['signaled']) {
159 $data .= "\nTermsig=".$stat['stopsig'];
160 }
161 }
162 $code = proc_close($proc);
163 if (function_exists('proc_get_status')) {
164 $code = $stat['exitcode'];
165 }
166 return array($code, $data);
167 }
$proc
Definition ajax.php:130

References $proc.

Referenced by _runSkipIf(), _testCleanup(), and run().

Here is the caller graph for this function:

Field Documentation

◆ $_headers

$_headers = array()

Definition at line 46 of file RunTest.php.

◆ $_logger

$_logger

Definition at line 47 of file RunTest.php.

◆ $_options

$_options

Definition at line 48 of file RunTest.php.

◆ $_php

$_php

Definition at line 49 of file RunTest.php.

Referenced by _savePHPBinary().

◆ $_savephp

$_savephp

Definition at line 58 of file RunTest.php.

Referenced by _restorePHPBinary().

◆ $ini_overwrites

$ini_overwrites
Initial value:
= array(
'output_handler=',
'open_basedir=',
'disable_functions=',
'output_buffering=Off',
'display_errors=1',
'log_errors=0',
'html_errors=0',
'report_zend_debug=0',
'docref_root=',
'docref_ext=.html',
'error_prepend_string=',
'error_append_string=',
'auto_prepend_file=',
'auto_append_file=',
'xdebug.default_enable=0',
'allow_url_fopen=1',
)

Definition at line 59 of file RunTest.php.

◆ $tests_count

$tests_count

Definition at line 50 of file RunTest.php.

◆ $xdebug_loaded

$xdebug_loaded

Definition at line 51 of file RunTest.php.


The documentation for this class was generated from the following file:
  • E:/Bearsampp-development/sandbox/core/libs/php/pear/pear/PEAR/RunTest.php