本文整理汇总了PHP中TestSuite::addListener方法的典型用法代码示例。如果您正苦于以下问题:PHP TestSuite::addListener方法的具体用法?PHP TestSuite::addListener怎么用?PHP TestSuite::addListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TestSuite
的用法示例。
在下文中一共展示了TestSuite::addListener方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* Runs suite
*
* @param string[] args
* @return int exitcode
*/
public function run(array $args)
{
if (!$args) {
return $this->usage();
}
// Setup suite
$suite = new TestSuite();
// Parse arguments
$sources = new Vector();
$listener = TestListeners::$DEFAULT;
$coverage = NULL;
$arguments = array();
$colors = NULL;
$cmap = array('' => NULL, '=on' => TRUE, '=off' => FALSE, '=auto' => NULL);
try {
for ($i = 0, $s = sizeof($args); $i < $s; $i++) {
if ('-v' == $args[$i]) {
$listener = TestListeners::$VERBOSE;
} else {
if ('-q' == $args[$i]) {
$listener = TestListeners::$QUIET;
} else {
if ('-c' == $args[$i]) {
$coverage = new CoverageListener();
foreach (explode(PATH_SEPARATOR, $this->arg($args, ++$i, 'c')) as $path) {
$coverage->registerPath($path);
}
} else {
if ('-cp' == $args[$i]) {
foreach (explode(PATH_SEPARATOR, $this->arg($args, ++$i, 'cp')) as $element) {
ClassLoader::registerPath($element, NULL);
}
} else {
if ('-e' == $args[$i]) {
$sources->add(new xp·unittest·sources·EvaluationSource($this->arg($args, ++$i, 'e')));
} else {
if ('-l' == $args[$i]) {
$arg = $this->arg($args, ++$i, 'l');
$class = XPClass::forName(strstr($arg, '.') ? $arg : 'xp.unittest.' . ucfirst($arg) . 'Listener');
$arg = $this->arg($args, ++$i, 'l');
if ('-?' == $arg || '--help' == $arg) {
return $this->listenerUsage($class);
}
$output = $this->streamWriter($arg);
$instance = $suite->addListener($class->newInstance($output));
// Get all @arg-annotated methods
$options = array();
foreach ($class->getMethods() as $method) {
if ($method->hasAnnotation('arg')) {
$arg = $method->getAnnotation('arg');
if (isset($arg['position'])) {
$options[$arg['position']] = $method;
} else {
$name = isset($arg['name']) ? $arg['name'] : strtolower(preg_replace('/^set/', '', $method->getName()));
$short = isset($arg['short']) ? $arg['short'] : $name[0];
$options[$name] = $options[$short] = $method;
}
}
}
$option = 0;
} else {
if ('-o' == $args[$i]) {
if (isset($options[$option])) {
$name = '#' . ($option + 1);
$method = $options[$option];
} else {
$name = $this->arg($args, ++$i, 'o');
if (!isset($options[$name])) {
$this->err->writeLine('*** Unknown listener argument ' . $name . ' to ' . $instance->getClassName());
return 2;
}
$method = $options[$name];
}
$option++;
if (0 == $method->numParameters()) {
$pass = array();
} else {
$pass = $this->arg($args, ++$i, 'o ' . $name);
}
try {
$method->invoke($instance, $pass);
} catch (TargetInvocationException $e) {
$this->err->writeLine('*** Error for argument ' . $name . ' to ' . $instance->getClassName() . ': ' . $e->getCause()->toString());
return 2;
}
} else {
if ('-?' == $args[$i] || '--help' == $args[$i]) {
return $this->usage();
} else {
if ('-a' == $args[$i]) {
$arguments[] = $this->arg($args, ++$i, 'a');
} else {
if ('--color' == substr($args[$i], 0, 7)) {
$remainder = (string) substr($args[$i], 7);
//.........这里部分代码省略.........