lithium\test\filter\Profiler::apply()
Overrides
lithium\test\Filter::apply()
Takes an instance of an object (usually a Collection object) containing test instances. Allows for preparing tests before they are run.
Parameters
-
object
$report
Instance of Report which is calling apply.
-
array
$tests
The test to apply this filter on
-
array
$options
Options for how this filter should be applied. Available options are:
'method'
'run'
'checks'
Returns
objectReturns the instance of $tests
.
Source
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;
}