lithium\console\command\Test::_init()
Overrides
lithium\console\Command::_init()
Initializes the output handlers.
Returns
voidSource
protected function _init() {
parent::_init();
$command = $this;
$this->_handlers += [
'txt' => function($runner, $path) use ($command) {
if (!$command->justAssertions) {
$command->header('Test');
$command->out(null, 1);
}
$colorize = function($result) {
switch (trim($result)) {
case '.':
return $result;
case 'pass':
return "{:green}{$result}{:end}";
case 'F':
case 'fail':
return "{:red}{$result}{:end}";
case 'E':
case 'exception':
return "{:purple}{$result}{:end}";
case 'S':
case 'skip':
return "{:cyan}{$result}{:end}";
default:
return "{:yellow}{$result}{:end}";
}
};
if ($command->verbose) {
$reporter = function($result) use ($command, $colorize) {
$command->out(sprintf(
'[%s] on line %4s in %s::%s()',
$colorize(sprintf('%9s', $result['result'])),
isset($result['line']) ? $result['line'] : '??',
isset($result['class']) ? $result['class'] : '??',
isset($result['method']) ? $result['method'] : '??'
));
};
} else {
$i = 0;
$columns = 60;
$reporter = function($result) use ($command, &$i, $columns, $colorize) {
$shorten = ['fail', 'skip', 'exception'];
if ($result['result'] === 'pass') {
$symbol = '.';
} elseif (in_array($result['result'], $shorten)) {
$symbol = strtoupper($result['result'][0]);
} else {
$symbol = '?';
}
$command->out($colorize($symbol), false);
$i++;
if ($i % $columns === 0) {
$command->out();
}
};
}
$report = $runner(compact('reporter'));
if (!$command->justAssertions) {
$stats = $report->stats();
$command->out(null, 2);
$command->out($report->render('result', $stats));
$command->out($report->render('errors', $stats));
if ($command->verbose) {
$command->out($report->render('skips', $stats));
}
foreach ($report->filters() as $filter => $options) {
$data = $report->results['filters'][$filter];
$command->out($report->render($options['name'], compact('data')));
}
}
return $report;
},
'json' => function($runner, $path) use ($command) {
$report = $runner();
$filters = [];
if ($results = $report->filters()) {
foreach ($results as $filter => $options) {
$filters[$options['name']] = $report->results['filters'][$filter];
}
}
$command->out($report->render('stats', $report->stats() + compact('filters')));
return $report;
}
];
}