lithium\test\filter\Coverage::apply PHP Method

apply() public static method

Takes an instance of an object (usually a Collection object) containing test instances. Attaches code coverage filtering to test cases.
See also: lithium\test\filter\Coverage::collect()
public static apply ( object $report, array $tests, array $options = [] ) : object
$report object Instance of Report which is calling apply.
$tests array The test to apply this filter on
$options array 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'.
return object Returns the instance of `$tests` with code coverage analysis triggers applied.
    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;
    }