lithium\test\filter\Profiler::apply()

public static method

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.

  • \lithium\util\Collection $tests

    The tests to apply this filter on.

  • array $options

    Options for how this filter should be applied. Available options are:

    • 'method'
    • 'run'
    • 'checks'

Returns

object

Returns the instance of $tests.

Source

	public static function apply($report, $tests, array $options = []) {
		$defaults = ['method' => 'run', 'checks' => static::$_metrics];
		$options += $defaults;

		foreach ($tests as $test) {
			$filter = function($params, $next) use ($report, $options, $test) {
				$start = $results = [];

				$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 = $next($params);

				foreach ($options['checks'] as $name => $check) {
					$results[$name] = $runCheck($check['function']) - $start[$name];
				}
				$report->collect(
					__CLASS__,
					[
						$test->subject() => $results,
						'options' => $options + ['test' => get_class($test)],
						'method' => $params['method']
					]
				);
				return $methodResult;
			};
			Filters::apply($test, $options['method'], $filter);
		}
		return $tests;
	}