Commit: f5f3d771e03d8d2d7f9774b97ed5739b09895a6d

Author: Marke Hallowell | Date: 2010-02-05 19:20:58 -0800
Renamed filter and reporter base classes and updated subclasses
diff --git a/app/resources/g11n/empty b/app/resources/g11n/empty old mode 100644 new mode 100755 diff --git a/app/resources/tmp/logs/empty b/app/resources/tmp/logs/empty old mode 100644 new mode 100755 diff --git a/app/resources/tmp/tests/empty b/app/resources/tmp/tests/empty old mode 100644 new mode 100755 diff --git a/libraries/lithium/test/Filter.php b/libraries/lithium/test/Filter.php new file mode 100644 index 0000000..6137d61 --- /dev/null +++ b/libraries/lithium/test/Filter.php @@ -0,0 +1,45 @@ +<?php +/** + * Lithium: the most rad php framework + * + * @copyright Copyright 2010, Union of RAD (http://union-of-rad.org) + * @license http://opensource.org/licenses/bsd-license.php The BSD License + */ + +namespace lithium\test; + +/** + * `Base` is the base class for all test filters. + */ +class Filter extends \lithium\core\StaticObject { + + /** + * Takes an instance of an object (usually a Collection object) containing test + * instances. Allows for preparing tests before they are run. + * + * @param object $report Instance of Report which is calling apply. + * @param array $options Options for how this filter should be applied. + * @return object|void Returns the instance of `$tests`. + */ + public static function apply($report, $options = array()) {} + + /** + * Analyzes the results of a test run and returns the result of the analysis. + * + * @param object $report The report instance running this filter and aggregating results + * @param array $options + * @return array|void The results of the analysis. + */ + public static function analyze($report, $options = array()) {} + + /** + * Returns data to be output by a reporter. + * + * @param string $format I.e. `'html'` or `'text'`. + * @param array $analysis The results of the analysis. + * @return string|void + */ + public static function output($format, $analysis) {} +} + +?> \ No newline at end of file diff --git a/libraries/lithium/test/Reporter.php b/libraries/lithium/test/Reporter.php new file mode 100644 index 0000000..c22faa3 --- /dev/null +++ b/libraries/lithium/test/Reporter.php @@ -0,0 +1,139 @@ +<?php +/** + * Lithium: the most rad php framework + * + * @copyright Copyright 2010, Union of RAD (http://union-of-rad.org) + * @license http://opensource.org/licenses/bsd-license.php The BSD License + */ + +namespace lithium\test; + +use \Exception; +use \lithium\core\Libraries; +use \lithium\util\Inflector; + +/** + * Reporter class to handle test report output. + */ +class Reporter extends \lithium\core\Object { + + public function stats($stats) { + $defaults = array( + 'asserts' => null, + 'passes' => array(), + 'fails' => array(), + 'errors' => array(), + 'exceptions' => array(), + ); + $stats = (array) $stats + $defaults; + + $count = array_map( + function($value) { return is_array($value) ? count($value) : $value; }, + $stats + ); + $success = $count['passes'] === $count['asserts'] && $count['errors'] === 0; + + $result[] = $this->_result($count + compact('success')); + + foreach ((array) $stats['errors'] as $error) { + switch ($error['result']) { + case 'fail': + $error += array('class' => 'unknown', 'method' => 'unknown'); + $result[] = $this->_fail($error); + break; + case 'exception': + $result[] = $this->_exception($error); + break; + } + } + return join("\n", $result); + } + + /** + * Return menu as a string to be used as render. + * + * @param array $classes + * @param array $options + * - format: type of reporter class. eg: html default: text + * - tree: true to convert classes to tree structure + */ + public function menu($classes, $options = array()) { + $defaults = array('request' => null, 'tree' => false); + $options += $defaults; + + if ($options['tree']) { + $data = array(); + $assign = function(&$data, $class, $i = 0) use (&$assign) { + isset($data[$class[$i]]) ?: $data[] = $class[$i]; + $end = (count($class) <= $i + 1); + + if (!$end && ($offset = array_search($class[$i], $data)) !== false) { + $data[$class[$i]] = array(); + unset($data[$offset]); + } + ksort($data); + $end ?: $assign($data[$class[$i]], $class, $i + 1); + }; + + foreach ($classes as $class) { + $assign($data, explode('\\', str_replace('\tests', '', $class))); + } + $classes = $data; + } + ksort($classes); + + $result = null; + + if ($options['tree']) { + $self = $this; + $menu = function ($data, $parent = null) use (&$menu, &$self, $result, $options) { + foreach ($data as $key => $row) { + if (is_array($row) && is_string($key)) { + $key = strtolower($key); + $next = $parent . '/' . $key; + $result .= $self->invokeMethod('_item', array('group', array( + 'request' => $options['request'], 'namespace' => $next, + 'name' => $key, 'menu' => $menu($row, $next) + ))); + } else { + $next = $parent . '/' . $key; + $result .= $self->invokeMethod('_item', array('case', array( + 'request' => $options['request'], 'namespace' => $parent, 'name' => $row, + ))); + } + } + return $self->invokeMethod('_item', array(null, array('menu' => $result))); + }; + + foreach ($classes as $library => $tests) { + $group = "{$library}/tests"; + $result .= $this->_item(null, array('menu' => $this->_item('group', array( + 'request' => $options['request'], 'namespace' => $group, + 'name' => $library, 'menu' => $menu($tests, $group) + )))); + } + return $result; + } + + foreach ($classes as $test) { + $parts = explode('\\', $test); + $result .= $this->_item('case', array( + 'request' => $options['request'], 'name' => array_pop($parts), + 'namespace' => join('/', $parts) + )); + } + return $this->_item(null, array('menu' => $result)); + } + + public function filters($filters) {} + + protected function _result($data) {} + + protected function _fail($data) {} + + protected function _exception($data) {} + + protected function _item($data) {} +} + +?> \ No newline at end of file diff --git a/libraries/lithium/test/filter/Affected.php b/libraries/lithium/test/filter/Affected.php index 6ecb3c6..128e584 100644 --- a/libraries/lithium/test/filter/Affected.php +++ b/libraries/lithium/test/filter/Affected.php @@ -21,7 +21,7 @@ use lithium\analysis\Inspector; * 3. Assigning test cases to those classes. * */ -class Affected extends \lithium\test\filter\Base { +class Affected extends \lithium\test\Filter { protected static $_cachedDepends = array(); diff --git a/libraries/lithium/test/filter/Base.php b/libraries/lithium/test/filter/Base.php deleted file mode 100644 index 81b97d5..0000000 --- a/libraries/lithium/test/filter/Base.php +++ /dev/null @@ -1,45 +0,0 @@ -<?php -/** - * Lithium: the most rad php framework - * - * @copyright Copyright 2010, Union of RAD (http://union-of-rad.org) - * @license http://opensource.org/licenses/bsd-license.php The BSD License - */ - -namespace lithium\test\filter; - -/** - * `Base` is the base class for all test filters. - */ -class Base extends \lithium\core\StaticObject { - - /** - * Takes an instance of an object (usually a Collection object) containing test - * instances. Allows for preparing tests before they are run. - * - * @param object $report Instance of Report which is calling apply. - * @param array $options Options for how this filter should be applied. - * @return object|void Returns the instance of `$tests`. - */ - public static function apply($report, $options = array()) {} - - /** - * Analyzes the results of a test run and returns the result of the analysis. - * - * @param object $report The report instance running this filter and aggregating results - * @param array $options - * @return array|void The results of the analysis. - */ - public static function analyze($report, $options = array()) {} - - /** - * Returns data to be output by a reporter. - * - * @param string $format I.e. `'html'` or `'text'`. - * @param array $analysis The results of the analysis. - * @return string|void - */ - public static function output($format, $analysis) {} -} - -?> \ No newline at end of file diff --git a/libraries/lithium/test/filter/Complexity.php b/libraries/lithium/test/filter/Complexity.php index cbc0d1f..1200de5 100644 --- a/libraries/lithium/test/filter/Complexity.php +++ b/libraries/lithium/test/filter/Complexity.php @@ -14,7 +14,7 @@ use \lithium\analysis\Inspector; /** * Calculates the cyclomatic complexity of class methods, and shows worst-offenders and statistics. */ -class Complexity extends \lithium\test\filter\Base { +class Complexity extends \lithium\test\Filter { /** * The list of tokens which represent the starting point of a code branch. diff --git a/libraries/lithium/test/filter/Coverage.php b/libraries/lithium/test/filter/Coverage.php index 64186ca..cab9aa7 100644 --- a/libraries/lithium/test/filter/Coverage.php +++ b/libraries/lithium/test/filter/Coverage.php @@ -16,7 +16,7 @@ use \lithium\analysis\Inspector; /** * Runs code coverage analysis for the executed tests. */ -class Coverage extends \lithium\test\filter\Base { +class Coverage extends \lithium\test\Filter { /** * Takes an instance of an object (usually a Collection object) containing test diff --git a/libraries/lithium/test/filter/Profiler.php b/libraries/lithium/test/filter/Profiler.php index fdc1c4a..efbe18a 100644 --- a/libraries/lithium/test/filter/Profiler.php +++ b/libraries/lithium/test/filter/Profiler.php @@ -8,7 +8,7 @@ namespace lithium\test\filter; -class Profiler extends \lithium\test\filter\Base { +class Profiler extends \lithium\test\Filter { /** * Contains the list of profiler checks to run against each test. Values can be string diff --git a/libraries/lithium/test/reporter/Base.php b/libraries/lithium/test/reporter/Base.php deleted file mode 100644 index e98be02..0000000 --- a/libraries/lithium/test/reporter/Base.php +++ /dev/null @@ -1,139 +0,0 @@ -<?php -/** - * Lithium: the most rad php framework - * - * @copyright Copyright 2010, Union of RAD (http://union-of-rad.org) - * @license http://opensource.org/licenses/bsd-license.php The BSD License - */ - -namespace lithium\test\reporter; - -use \Exception; -use \lithium\core\Libraries; -use \lithium\util\Inflector; - -/** - * Reporter class to handle test report output. - */ -class Base extends \lithium\core\Object { - - public function stats($stats) { - $defaults = array( - 'asserts' => null, - 'passes' => array(), - 'fails' => array(), - 'errors' => array(), - 'exceptions' => array(), - ); - $stats = (array) $stats + $defaults; - - $count = array_map( - function($value) { return is_array($value) ? count($value) : $value; }, - $stats - ); - $success = $count['passes'] === $count['asserts'] && $count['errors'] === 0; - - $result[] = $this->_result($count + compact('success')); - - foreach ((array) $stats['errors'] as $error) { - switch ($error['result']) { - case 'fail': - $error += array('class' => 'unknown', 'method' => 'unknown'); - $result[] = $this->_fail($error); - break; - case 'exception': - $result[] = $this->_exception($error); - break; - } - } - return join("\n", $result); - } - - /** - * Return menu as a string to be used as render. - * - * @param array $classes - * @param array $options - * - format: type of reporter class. eg: html default: text - * - tree: true to convert classes to tree structure - */ - public function menu($classes, $options = array()) { - $defaults = array('request' => null, 'tree' => false); - $options += $defaults; - - if ($options['tree']) { - $data = array(); - $assign = function(&$data, $class, $i = 0) use (&$assign) { - isset($data[$class[$i]]) ?: $data[] = $class[$i]; - $end = (count($class) <= $i + 1); - - if (!$end && ($offset = array_search($class[$i], $data)) !== false) { - $data[$class[$i]] = array(); - unset($data[$offset]); - } - ksort($data); - $end ?: $assign($data[$class[$i]], $class, $i + 1); - }; - - foreach ($classes as $class) { - $assign($data, explode('\\', str_replace('\tests', '', $class))); - } - $classes = $data; - } - ksort($classes); - - $result = null; - - if ($options['tree']) { - $self = $this; - $menu = function ($data, $parent = null) use (&$menu, &$self, $result, $options) { - foreach ($data as $key => $row) { - if (is_array($row) && is_string($key)) { - $key = strtolower($key); - $next = $parent . '/' . $key; - $result .= $self->invokeMethod('_item', array('group', array( - 'request' => $options['request'], 'namespace' => $next, - 'name' => $key, 'menu' => $menu($row, $next) - ))); - } else { - $next = $parent . '/' . $key; - $result .= $self->invokeMethod('_item', array('case', array( - 'request' => $options['request'], 'namespace' => $parent, 'name' => $row, - ))); - } - } - return $self->invokeMethod('_item', array(null, array('menu' => $result))); - }; - - foreach ($classes as $library => $tests) { - $group = "{$library}/tests"; - $result .= $this->_item(null, array('menu' => $this->_item('group', array( - 'request' => $options['request'], 'namespace' => $group, - 'name' => $library, 'menu' => $menu($tests, $group) - )))); - } - return $result; - } - - foreach ($classes as $test) { - $parts = explode('\\', $test); - $result .= $this->_item('case', array( - 'request' => $options['request'], 'name' => array_pop($parts), - 'namespace' => join('/', $parts) - )); - } - return $this->_item(null, array('menu' => $result)); - } - - public function filters($filters) {} - - protected function _result($data) {} - - protected function _fail($data) {} - - protected function _exception($data) {} - - protected function _item($data) {} -} - -?> \ No newline at end of file diff --git a/libraries/lithium/test/reporter/Html.php b/libraries/lithium/test/reporter/Html.php index 58aa480..2633788 100644 --- a/libraries/lithium/test/reporter/Html.php +++ b/libraries/lithium/test/reporter/Html.php @@ -10,7 +10,7 @@ namespace lithium\test\reporter; use lithium\util\String; -class Html extends \lithium\test\reporter\Base { +class Html extends \lithium\test\Reporter { protected $_classes = array( 'router' => '\lithium\http\Router' diff --git a/libraries/lithium/test/reporter/Text.php b/libraries/lithium/test/reporter/Text.php index 38463d9..efb0ce6 100644 --- a/libraries/lithium/test/reporter/Text.php +++ b/libraries/lithium/test/reporter/Text.php @@ -10,7 +10,7 @@ namespace lithium\test\reporter; use lithium\util\String; -class Text extends \lithium\test\reporter\Base { +class Text extends \lithium\test\Reporter { protected function _result($stats) { $result = array(