Permalink
Browse files

adding some filters for `\test\Dispatcher` and `\test\Report`

moving test templates into a namespace based on reporter name.
  • Loading branch information...
gwoo committed Mar 4, 2010
1 parent ba28068 commit 97199ea55b3b0fa68618a4dbb3ffc7ff8d37346c
@@ -51,18 +51,17 @@ public static function run($group = null, array $options = array()) {
'reporter' => 'text'
);
$options += $defaults;
-
- $items = (array) $group;
$isCase = is_string($group) && preg_match('/Test$/', $group);
+ $items = ($isCase) ? array(new $group()) : (array) $group;
- if ($isCase) {
- $items = array(new $group());
- }
$options['filters'] = Set::normalize($options['filters']);
$group = static::_group($items);
$report = static::_report($group, $options);
- $report->run();
- return $report;
+
+ return static::_filter(__METHOD__, compact('report'), function($self, $params, $chain) {
+ $params['report']->run();
+ return $params['report'];
+ });
}
/**
@@ -27,13 +27,6 @@ class Report extends \lithium\core\Object {
*/
public $group = null;
- /**
- * Contains the format for the results to be rendered in
- *
- * @var string
- */
- public $format = null;
-
/**
* An array of fully-namespaced class names representing the filters to be applied to this test
* group.
@@ -75,7 +68,8 @@ public function __construct(array $config = array()) {
'title' => null,
'group' => null,
'filters' => array(),
- 'format' => 'txt'
+ 'format' => 'txt',
+ 'reporter' => 'txt'
);
parent::__construct((array) $config + $defaults);
}
@@ -89,7 +83,6 @@ protected function _init() {
$this->group = $this->_config['group'];
$this->filters = $this->_config['filters'];
$this->title = $this->_config['title'] ?: $this->_config['title'];
- $this->format = $this->_config['format'];
}
/**
@@ -182,7 +175,6 @@ public function stats() {
}
return $stats;
});
-
$stats = (array) $stats + array(
'asserts' => null,
'passes' => array(),
@@ -196,7 +188,6 @@ function($value) { return is_array($value) ? count($value) : $value; },
$stats
);
$success = $count['passes'] == $count['asserts'] && $count['errors'] === 0;
-
return compact("stats", "count", "success");
}
@@ -208,14 +199,19 @@ function($value) { return is_array($value) ? count($value) : $value; },
* @param array $options Array of options (e.g. rendering type)
* @return string
*/
- public function render($template, $data) {
- $template = Libraries::locate('test.templates', $template, array(
- 'filter' => false, 'type' => 'file', 'suffix' => '.' . $this->format . '.php',
+ public function render($template, $data = array()) {
+ $config = $this->_config;
+ $template = Libraries::locate("test.templates.{$config['reporter']}", $template, array(
+ 'filter' => false, 'type' => 'file', 'suffix' => ".{$config['format']}.php",
));
- extract($data);
- ob_start();
- include $template;
- return ob_get_clean();
+ $params = compact('template', 'data', 'config');
+
+ return $this->_filter(__METHOD__, $params, function($self, $params, $chain) {
+ extract($params['data']);
+ ob_start();
+ include $params['template'];
+ return ob_get_clean();
+ });
}
}

0 comments on commit 97199ea

Please sign in to comment.