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.

  • array $tests

    The test 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 = array()) {
		$defaults = array('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);
		}

		$filter = function($self, $params, $chain) use ($report, $options) {
			xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
			$chain->next($self, $params, $chain);
			$results = xdebug_get_code_coverage();
			xdebug_stop_code_coverage();
			$report->collect(__CLASS__, array($self->subject() => $results));
		};
		$tests->invoke('applyFilter', array($options['method'], $filter));
		return $tests;
	}