Permalink
Browse files

updating test suite handling. Re-Adding `\test\Controller` for browse…

…r based front end.
  • Loading branch information...
1 parent 94759a2 commit 8bfcfe4feb324a14b831d91774924801a35b38a5 @gwoo gwoo committed Mar 22, 2010
@@ -8,44 +8,17 @@
use lithium\core\Libraries;
use lithium\action\Dispatcher;
-use lithium\test\Dispatcher as TestDispatcher;
+use lithium\test\Controller;
Dispatcher::applyFilter('run', function($self, $params, $chain) {
- list($isTest, $test) = explode('/', $params['request']->url, 2) + array("", "");
+ list($isTest, $args) = explode('/', $params['request']->url, 2) + array("", "");
$request = $params['request'];
- if ($isTest === "test") {
- $group = "\\" . str_replace("/", "\\", $test);
-
- if ($group == "\\all") {
- $group = Libraries::locate('tests', null, array(
- 'filter' => '/cases|integration|functional/',
- 'exclude' => '/mocks/'
- ));
- $group = array_map(function($test) {
- $path = explode("\\", $test);
- return "\\" . array_shift($path);
- }, $group);
- $group = array_unique($group);
- }
-
- $report = TestDispatcher::run($group , $request->query + array(
- 'reporter' => 'html',
- 'format' => 'html'
- ));
- $filters = Libraries::locate('test.filter', null, array(
- 'exclude' => '/Base$/'
- ));
- $menu = Libraries::locate('tests', null, array(
- 'filter' => '/cases|integration|functional/',
- 'exclude' => '/mocks/'
- ));
- sort($menu);
- $result = compact('request', 'group', 'report', 'filters', 'classes', 'menu');
-
- return $report->render('layout', $result);
+ if ($isTest === "test") {
+ $controller = new Controller();
+ $args = str_replace('/', '\\', $args);
+ return $controller($request, compact('args'));
}
-
return $chain->next($self, $params, $chain);
});
@@ -0,0 +1,61 @@
+<?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 lithium\test\Dispatcher;
+use lithium\core\Libraries;
+use lithium\test\Group;
+
+/**
+ * The Test Controller for running the html version of the test suite
+ *
+ */
+class Controller extends \lithium\core\Object {
+
+ /**
+ * Magic method to make Controller callable.
+ *
+ * @see \lithium\action\Dispatcher::_callable()
+ * @param object $request A \lithium\action\Request object.
+ * @param array $dispatchParams Array of params after being parsed by router.
+ * @param array $options Some basic options for this controller.
+ * @return string
+ */
+ public function __invoke($request, $dispatchParams, array $options = array()) {
+ $dispatchParamsDefaults = array('args' => array());
+ $dispatchParams += $dispatchParamsDefaults;
+ $defaults = array('reporter' => 'html', 'format' => 'html');
+ $options += (array) $request->query + $defaults;
+ $params = compact('request', 'dispatchParams', 'options');
+
+ return $this->_filter(__METHOD__, $params, function($self, $params) {
+ $request = $params['request'];
+ $options = $params['options'];
+ $params = $params['dispatchParams'];
+ $group = '\\' . join('\\', (array) $params['args']);
+
+ if ($group === "\\all") {
+ $group = Group::all();
+ $options['title'] = 'All Tests';
+ }
+ $report = Dispatcher::run($group , $options);
+ $filters = Libraries::locate('test.filter');
+ $menu = Libraries::locate('tests', null, array(
+ 'filter' => '/cases|integration|functional/',
+ 'exclude' => '/mocks/'
+ ));
+ sort($menu);
+
+ $result = compact('request', 'report', 'filters', 'menu');
+ return $report->render('layout', $result);
+ });
+ }
+}
+
+?>
@@ -33,20 +33,21 @@ protected function _init() {
}
/**
- * Get all tests
+ * Get all test cases. By default, does not include function or integration tests.
*
* @param string $options
* @return array
*/
public static function all(array $options = array()) {
- $defaults = array('transform' => false, 'library' => true);
+ $defaults = array(
+ 'library' => true,
+ 'filter' => '/cases/',
+ 'exclude' => '/mock/',
+ 'recursive' => true
+ );
$options += $defaults;
- $m = '/\\\\tests\\\\cases\\\\(.+)Test$/';
- $transform = function($class) use ($m) { return preg_replace($m, '\\\\\1', $class); };
- $classes = Libraries::locate('tests', null, $options + array(
- 'filter' => '/cases|integration|functional/', 'recursive' => true
- ));
- return $options['transform'] ? array_map($transform, $classes) : $classes;
+ $classes = Libraries::locate('tests', null, $options);
+ return $classes;
}
/**
@@ -65,7 +66,7 @@ public function add($test = null, array $options = array()) {
return array(get_class($test));
}
if (is_string($test)) {
- if ($test[0] != '\\') {
+ if ($test[0] != '\\' && strpos($test, 'lithium\\') === false) {
$test = "lithium\\tests\cases\\{$test}";
}
if (preg_match("/Test/", $test)) {
@@ -735,7 +735,7 @@ protected function _message(&$data = array(), $message = null) {
}
$defaults = array('trace' => null, 'expected' => null, 'result' => null);
$result = (array) $data + $defaults;
- $data = array_diff((array) $data, $defaults);
+
return sprintf("trace: %s\nexpected: %s\nresult: %s\n",
$result['trace'],
var_export($result['expected'], true),
@@ -29,13 +29,7 @@
</div>
<div class="test-content">
- <?php if (is_array($report->title)) {
- $report->title = join (', ', $report->title);
- } ?>
-
- <?php if ($report->title != '' && $report->title != '\\') { ?>
- <h2><span>test results for </span><?php echo $report->title; ?></h2>
- <?php } ?>
+ <h2><span>test results for </span><?php echo $report->title; ?></h2>
<span class="filters">
<?php echo join('', array_map(

0 comments on commit 8bfcfe4

Please sign in to comment.