Skip to content

Commit

Permalink
Refactored test filter interface to better handle raw filter results …
Browse files Browse the repository at this point in the history
…prior to analysis
  • Loading branch information
indiefan authored and gwoo committed Feb 6, 2010
1 parent ab4d940 commit 0fddf6c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 23 deletions.
13 changes: 6 additions & 7 deletions libraries/lithium/test/Report.php
Expand Up @@ -133,18 +133,17 @@ public function run() {
/**
* Collects Results from the test filters and aggregates them.
*
* @param string $class Fully namespaced classname of the filter
* for which to aggregate results.
* @param array $results Array of the filter results packaged for
* @param string $class Classname of the filter for which to aggregate results.
* @param array $results Array of the filter results for
* later analysis by the filter itself.
* @return void
*/
public function collectFilterResults($class, $results) {
$testClass = key($results);
if(!isset($this->results['filters'][$class][$testClass])) {
$this->results['filters'][$class][$testClass] = array();
//$testClass = key($results);
if(!isset($this->results['filters'][$class])) {
$this->results['filters'][$class] = array();
}
$this->results['filters'][$class][$testClass] = $results[$testClass];
$this->results['filters'][$class][] = $results;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions libraries/lithium/test/filter/Affected.php
Expand Up @@ -26,8 +26,8 @@ class Affected extends \lithium\test\filter\Base {
/**
* Holds metrics for this filter.
*
* @see lihtium\test\filter\Affected::apply()
* @see lihtium\test\filter\Affected::output()
* @see lithium\test\filter\Affected::apply()
* @see lithium\test\filter\Affected::output()
* @var array Keys are affected classes, values (if available) corresponding test case classes.
*/
protected static $_metrics = array();
Expand Down
35 changes: 21 additions & 14 deletions libraries/lithium/test/filter/Coverage.php
Expand Up @@ -47,7 +47,7 @@ public static function apply($report, $tests, $options = array()) {
$chain->next($self, $params, $chain);
$results = xdebug_get_code_coverage();
xdebug_stop_code_coverage();
$report->collectFilterResults(__CLASS__, Coverage::collect($self->subject(), $results, $options));
$report->collectFilterResults(__CLASS__, array( $self->subject() => $results ));
}));
return $tests;
}
Expand All @@ -63,6 +63,7 @@ public static function apply($report, $tests, $options = array()) {
* instances each line was called.
*/
public static function analyze($results, $filterResults, $classes = array()) {
$filterResults = static::collect($filterResults);
$classes = $classes ?: array_filter(get_declared_classes(), function($class) {
return (!is_subclass_of($class, 'lithium\test\Unit'));
});
Expand Down Expand Up @@ -168,30 +169,36 @@ public static function output($format, $analysis) {
/**
* Collects code coverage analysis results from `xdebug_get_code_coverage()`.
*
* @param string $class Class name that these test results correspond to.
* @param array $results A results array from `xdebug_get_code_coverage()`.
* @param array $filterResults An array of results arrays from `xdebug_get_code_coverage()`.
* @param array $options Set of options defining how results should be collected.
* @return array The packaged filter results.
* @see lithium\test\Coverage::analyze()
* @todo Implement $options['merging']
*/
public static function collect($class, $results, $options = array()) {
public static function collect($filterResults, $options = array()) {
$defaults = array('merging' => 'class');
$options += $defaults;
$filterResults[$class] = array();
$packagedResults = array();

foreach ($results as $file => $lines) {
unset($results[$file][0]);
}
foreach ($filterResults as $results) {
$class = key($results);
$results = $results[$class];
foreach ($results as $file => $lines) {
unset($results[$file][0]);
}

switch ($options['merging']) {
case 'class':
default:
$filterResults[$class][] = $results;
break;
switch ($options['merging']) {
case 'class':
default:
if (!isset($packagedResults[$class])) {
$packagedResults[$class] = array();
}
$packagedResults[$class][] = $results;
break;
}
}

return $filterResults;
return $packagedResults;
}

/**
Expand Down

0 comments on commit 0fddf6c

Please sign in to comment.