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

public static method

Takes an instance of an object (usually a Collection object) containing test instances. Attaches code coverage filtering to test cases.

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 code coverage should be applied. These options are also passed to Coverage::collect() to determine how to aggregate results. See the documentation for collect() for further options. Options affecting this method are: -'method': The name of method to attach to, defaults to 'run'.

Returns

object

Returns the instance of $tests with code coverage analysis triggers applied.

Source

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

		if (!function_exists('xdebug_start_code_coverage')) {
			$msg = "Xdebug not installed. Please install Xdebug before running code coverage.";
			throw new RuntimeException($msg);
		}

		foreach ($tests as $test) {
			$filter = function($params, $next) use ($test, $report) {
				xdebug_start_code_coverage(XDEBUG_CC_UNUSED);
				$next($params);
				$results = xdebug_get_code_coverage();
				xdebug_stop_code_coverage();
				$report->collect(__CLASS__, [$test->subject() => $results]);
			};
			Filters::apply($test, $options['method'], $filter);
		}
		return $tests;
	}