114 return $this->raiseError(
'ERROR: cannot use both --phpunit and --tapoutput at the same time');
117 require_once
'PEAR/Common.php';
118 require_once
'System.php';
122 $depth = isset(
$options[
'recur']) ? 14 : 1;
124 if (!count($params)) {
129 $oldparams = $params;
131 $reg = &$this->config->getRegistry();
132 foreach ($oldparams as $param) {
133 $pname = $reg->parsePackageName($param, $this->config->get(
'default_channel'));
135 return $this->raiseError($pname);
138 $package = &$reg->getPackage($pname[
'package'], $pname[
'channel']);
140 return PEAR::raiseError(
'Unknown package "' .
141 $reg->parsedPackageNameToString($pname) .
'"');
144 $filelist = $package->getFilelist();
145 foreach ($filelist as $name => $atts) {
146 if (isset($atts[
'role']) && $atts[
'role'] !=
'test') {
150 if (isset(
$options[
'phpunit']) && preg_match(
'/AllTests\.php\\z/i', $name)) {
151 $params[] = $atts[
'installed_as'];
153 } elseif (!preg_match(
'/\.phpt\\z/', $name)) {
156 $params[] = $atts[
'installed_as'];
161 foreach ($params as $p) {
164 $dir = System::find(array($p,
'-type',
'f',
166 '-name',
'AllTests.php'));
168 foreach ($dir as $p) {
170 if (!count($tests) ||
171 (count($tests) && strlen($p) < strlen($tests[0]))) {
180 $args = array($p,
'-type',
'f',
'-name',
'*.phpt');
183 if (preg_match(
'/AllTests\.php\\z/i', $p)) {
185 if (!count($tests) ||
186 (count($tests) && strlen($p) < strlen($tests[0]))) {
194 if (file_exists($p) && preg_match(
'/\.phpt$/', $p)) {
199 if (!preg_match(
'/\.phpt\\z/', $p)) {
203 $args = array(dirname($p),
'-type',
'f',
'-name', $p);
207 $args[] =
'-maxdepth';
211 $dir = System::find($args);
212 $tests = array_merge($tests, $dir);
220 if (isset($_ENV[
'TEST_PHP_INCLUDE_PATH'])) {
221 $ini_settings .=
" -d include_path={$_ENV['TEST_PHP_INCLUDE_PATH']}";
225 $this->ui->outputData(
'Using INI settings: "' . $ini_settings .
'"');
228 $skipped = $passed = $failed = array();
229 $tests_count = count($tests);
230 $this->ui->outputData(
'Running ' . $tests_count .
' tests',
$command);
232 if (isset(
$options[
'realtimelog']) && file_exists(
'run-tests.log')) {
233 unlink(
'run-tests.log');
237 $tap =
'1..' . $tests_count .
"\n";
240 require_once
'PEAR/RunTest.php';
242 $run->tests_count = $tests_count;
244 if (isset(
$options[
'coverage']) && extension_loaded(
'xdebug')){
245 $run->xdebug_loaded =
true;
247 $run->xdebug_loaded =
false;
251 foreach ($tests as $t) {
252 if (isset(
$options[
'realtimelog'])) {
253 $fp = @fopen(
'run-tests.log',
'a');
255 fwrite($fp,
"Running test [$i / $tests_count] $t...");
261 $result = $run->runPHPUnit($t, $ini_settings);
263 $result = $run->run($t, $ini_settings, $j);
267 $this->ui->log(
$result->getMessage());
276 if (isset(
$options[
'realtimelog'])) {
277 $fp = @fopen(
'run-tests.log',
'a');
279 fwrite($fp,
"$result\n");
297 $total = date(
'i:s', time() - $start);
299 $fp = @fopen(
'run-tests.log',
'w');
301 fwrite($fp, $tap, strlen($tap));
303 $this->ui->outputData(
'wrote TAP-format log to "' .realpath(
'run-tests.log') .
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) {
316 $mode = isset(
$options[
'realtimelog']) ?
'a' :
'w';
317 $fp = @fopen(
'run-tests.log', $mode);
322 $this->ui->outputData(
'wrote log to "' . realpath(
'run-tests.log') .
'"',
$command);
324 } elseif (file_exists(
'run-tests.log') && !is_dir(
'run-tests.log')) {
325 @unlink(
'run-tests.log');
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);
338 if (count($failed) == 0) {
341 return $this->raiseError(
'Some tests failed');