Bearsampp 2026.9.23
Loading...
Searching...
No Matches
PEAR_Command_Test Class Reference
Inheritance diagram for PEAR_Command_Test:
Collaboration diagram for PEAR_Command_Test:

Public Member Functions

 __construct (&$ui, &$config)
 doRunTests ($command, $options, $params)
Public Member Functions inherited from PEAR_Command_Common
 getCommands ()
 getGetoptArgs ($command, &$short_args, &$long_args)
 getHelp ($command)
 getHelpArgs ($command)
 getOptions ($command)
 getShortcuts ()
 run ($command, $options, $params)
Public Member Functions inherited from PEAR
 __call ($method, $arguments)
 __construct ($error_class=null)
 _checkDelExpect ($error_code)
 _PEAR ()
 delExpect ($error_code)
 expectError ($code=' *')
 PEAR ($error_class=null)
 popExpect ()

Data Fields

 $commands
 $output
Data Fields inherited from PEAR_Command_Common
 $_deps_rel_trans
 $_deps_type_trans
 $_registry
 $config
 $ui
Data Fields inherited from PEAR
 $_debug = false
 $_default_error_handler = ''
 $_default_error_mode = null
 $_default_error_options = null
 $_error_class = 'PEAR_Error'
 $_expected_errors = array()

Additional Inherited Members

Static Public Member Functions inherited from PEAR
static __callStatic ($method, $arguments)
static getSourceDateEpoch ()
static & getStaticProperty ($class, $var)
static isError ($data, $code=null)
static loadExtension ($ext)
static registerShutdownFunc ($func, $args=array())
static staticPopErrorHandling ()
static staticPushErrorHandling ($mode, $options=null)
Static Protected Member Functions inherited from PEAR
static _popErrorHandling ($object)
static _pushErrorHandling ($object, $mode, $options=null)
static _raiseError ($object, $message=null, $code=null, $mode=null, $options=null, $userinfo=null, $error_class=null, $skipmsg=false)
static _setErrorHandling ( $object, $mode=null, $options=null)
static _throwError ($object, $message=null, $code=null, $userinfo=null)
Static Protected Attributes inherited from PEAR
static $bivalentMethods

Detailed Description

Definition at line 38 of file Test.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( & $ui,
& $config )

PEAR_Command_Test constructor.

@access public

Reimplemented from PEAR_Command_Common.

Definition at line 106 of file Test.php.

107 {
108 parent::__construct($ui, $config);
109 }

References PEAR_Command_Common\$config, and PEAR_Command_Common\$ui.

Member Function Documentation

◆ doRunTests()

doRunTests ( $command,
$options,
$params )

Definition at line 111 of file Test.php.

112 {
113 if (isset($options['phpunit']) && isset($options['tapoutput'])) {
114 return $this->raiseError('ERROR: cannot use both --phpunit and --tapoutput at the same time');
115 }
116
117 require_once 'PEAR/Common.php';
118 require_once 'System.php';
119 $log = new PEAR_Common;
120 $log->ui = &$this->ui; // slightly hacky, but it will work
121 $tests = array();
122 $depth = isset($options['recur']) ? 14 : 1;
123
124 if (!count($params)) {
125 $params[] = '.';
126 }
127
128 if (isset($options['package'])) {
129 $oldparams = $params;
130 $params = array();
131 $reg = &$this->config->getRegistry();
132 foreach ($oldparams as $param) {
133 $pname = $reg->parsePackageName($param, $this->config->get('default_channel'));
134 if (PEAR::isError($pname)) {
135 return $this->raiseError($pname);
136 }
137
138 $package = &$reg->getPackage($pname['package'], $pname['channel']);
139 if (!$package) {
140 return PEAR::raiseError('Unknown package "' .
141 $reg->parsedPackageNameToString($pname) . '"');
142 }
143
144 $filelist = $package->getFilelist();
145 foreach ($filelist as $name => $atts) {
146 if (isset($atts['role']) && $atts['role'] != 'test') {
147 continue;
148 }
149
150 if (isset($options['phpunit']) && preg_match('/AllTests\.php\\z/i', $name)) {
151 $params[] = $atts['installed_as'];
152 continue;
153 } elseif (!preg_match('/\.phpt\\z/', $name)) {
154 continue;
155 }
156 $params[] = $atts['installed_as'];
157 }
158 }
159 }
160
161 foreach ($params as $p) {
162 if (is_dir($p)) {
163 if (isset($options['phpunit'])) {
164 $dir = System::find(array($p, '-type', 'f',
165 '-maxdepth', $depth,
166 '-name', 'AllTests.php'));
167 if (count($dir)) {
168 foreach ($dir as $p) {
169 $p = realpath($p);
170 if (!count($tests) ||
171 (count($tests) && strlen($p) < strlen($tests[0]))) {
172 // this is in a higher-level directory, use this one instead.
173 $tests = array($p);
174 }
175 }
176 }
177 continue;
178 }
179
180 $args = array($p, '-type', 'f', '-name', '*.phpt');
181 } else {
182 if (isset($options['phpunit'])) {
183 if (preg_match('/AllTests\.php\\z/i', $p)) {
184 $p = realpath($p);
185 if (!count($tests) ||
186 (count($tests) && strlen($p) < strlen($tests[0]))) {
187 // this is in a higher-level directory, use this one instead.
188 $tests = array($p);
189 }
190 }
191 continue;
192 }
193
194 if (file_exists($p) && preg_match('/\.phpt$/', $p)) {
195 $tests[] = $p;
196 continue;
197 }
198
199 if (!preg_match('/\.phpt\\z/', $p)) {
200 $p .= '.phpt';
201 }
202
203 $args = array(dirname($p), '-type', 'f', '-name', $p);
204 }
205
206 if (!isset($options['recur'])) {
207 $args[] = '-maxdepth';
208 $args[] = 1;
209 }
210
211 $dir = System::find($args);
212 $tests = array_merge($tests, $dir);
213 }
214
215 $ini_settings = '';
216 if (isset($options['ini'])) {
217 $ini_settings .= $options['ini'];
218 }
219
220 if (isset($_ENV['TEST_PHP_INCLUDE_PATH'])) {
221 $ini_settings .= " -d include_path={$_ENV['TEST_PHP_INCLUDE_PATH']}";
222 }
223
224 if ($ini_settings) {
225 $this->ui->outputData('Using INI settings: "' . $ini_settings . '"');
226 }
227
228 $skipped = $passed = $failed = array();
229 $tests_count = count($tests);
230 $this->ui->outputData('Running ' . $tests_count . ' tests', $command);
231 $start = time();
232 if (isset($options['realtimelog']) && file_exists('run-tests.log')) {
233 unlink('run-tests.log');
234 }
235
236 if (isset($options['tapoutput'])) {
237 $tap = '1..' . $tests_count . "\n";
238 }
239
240 require_once 'PEAR/RunTest.php';
241 $run = new PEAR_RunTest($log, $options);
242 $run->tests_count = $tests_count;
243
244 if (isset($options['coverage']) && extension_loaded('xdebug')){
245 $run->xdebug_loaded = true;
246 } else {
247 $run->xdebug_loaded = false;
248 }
249
250 $j = $i = 1;
251 foreach ($tests as $t) {
252 if (isset($options['realtimelog'])) {
253 $fp = @fopen('run-tests.log', 'a');
254 if ($fp) {
255 fwrite($fp, "Running test [$i / $tests_count] $t...");
256 fclose($fp);
257 }
258 }
260 if (isset($options['phpunit'])) {
261 $result = $run->runPHPUnit($t, $ini_settings);
262 } else {
263 $result = $run->run($t, $ini_settings, $j);
264 }
266 if (PEAR::isError($result)) {
267 $this->ui->log($result->getMessage());
268 continue;
269 }
270
271 if (isset($options['tapoutput'])) {
272 $tap .= $result[0] . ' ' . $i . $result[1] . "\n";
273 continue;
274 }
275
276 if (isset($options['realtimelog'])) {
277 $fp = @fopen('run-tests.log', 'a');
278 if ($fp) {
279 fwrite($fp, "$result\n");
280 fclose($fp);
281 }
282 }
283
284 if ($result == 'FAILED') {
285 $failed[] = $t;
286 }
287 if ($result == 'PASSED') {
288 $passed[] = $t;
289 }
290 if ($result == 'SKIPPED') {
291 $skipped[] = $t;
292 }
293
294 $j++;
295 }
296
297 $total = date('i:s', time() - $start);
298 if (isset($options['tapoutput'])) {
299 $fp = @fopen('run-tests.log', 'w');
300 if ($fp) {
301 fwrite($fp, $tap, strlen($tap));
302 fclose($fp);
303 $this->ui->outputData('wrote TAP-format log to "' .realpath('run-tests.log') .
304 '"', $command);
305 }
306 } else {
307 if (count($failed)) {
308 $output = "TOTAL TIME: $total\n";
309 $output .= count($passed) . " PASSED TESTS\n";
310 $output .= count($skipped) . " SKIPPED TESTS\n";
311 $output .= count($failed) . " FAILED TESTS:\n";
312 foreach ($failed as $failure) {
313 $output .= $failure . "\n";
314 }
315
316 $mode = isset($options['realtimelog']) ? 'a' : 'w';
317 $fp = @fopen('run-tests.log', $mode);
318
319 if ($fp) {
320 fwrite($fp, $output, strlen($output));
321 fclose($fp);
322 $this->ui->outputData('wrote log to "' . realpath('run-tests.log') . '"', $command);
323 }
324 } elseif (file_exists('run-tests.log') && !is_dir('run-tests.log')) {
325 @unlink('run-tests.log');
326 }
327 }
328 $this->ui->outputData('TOTAL TIME: ' . $total);
329 $this->ui->outputData(count($passed) . ' PASSED TESTS', $command);
330 $this->ui->outputData(count($skipped) . ' SKIPPED TESTS', $command);
331 if (count($failed)) {
332 $this->ui->outputData(count($failed) . ' FAILED TESTS:', $command);
333 foreach ($failed as $failure) {
334 $this->ui->outputData($failure, $command);
335 }
336 }
337
338 if (count($failed) == 0) {
339 return true;
340 }
341 return $this->raiseError('Some tests failed');
342 }
const PEAR_ERROR_RETURN
Definition PEAR.php:24
$result
static staticPopErrorHandling()
Definition PEAR.php:654
static staticPushErrorHandling($mode, $options=null)
Definition PEAR.php:619
static find($args)
Definition System.php:568
$options
Definition pearcmd.php:145
if( $raw) foreach($opts as $opt) if( $store_system_config) if($store_user_config) $command
Definition pearcmd.php:322

References $command, $options, $output, $result, PEAR_Command_Common\$ui, PEAR\isError(), PEAR_ERROR_RETURN, PEAR\staticPopErrorHandling(), and PEAR\staticPushErrorHandling().

Here is the call graph for this function:

Field Documentation

◆ $commands

$commands

Definition at line 40 of file Test.php.

◆ $output

$output

Definition at line 99 of file Test.php.

Referenced by doRunTests().


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