public static function apply($report, $tests, array $options = array())
{
$defaults = array('method' => 'run', 'checks' => static::$_metrics);
$options += $defaults;
$m = $options['method'];
$filter = function ($self, $params, $chain) use($report, $options) {
$start = $results = array();
$runCheck = function ($check) {
switch (true) {
case is_object($check) || is_string($check):
return $check();
break;
case is_array($check):
$function = array_shift($check);
$result = !$check ? $check() : call_user_func_array($function, $check);
break;
}
return $result;
};
foreach ($options['checks'] as $name => $check) {
$start[$name] = $runCheck($check['function']);
}
$methodResult = $chain->next($self, $params, $chain);
foreach ($options['checks'] as $name => $check) {
$results[$name] = $runCheck($check['function']) - $start[$name];
}
$report->collect(__CLASS__, array($self->subject() => $results, 'options' => $options + array('test' => get_class($self)), 'method' => $params['method']));
return $methodResult;
};
$tests->invoke('applyFilter', array($m, $filter));
return $tests;
}