Controller.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * Lithium: the most rad php framework
  4. *
  5. * @copyright Copyright 2013, Union of RAD (http://union-of-rad.org)
  6. * @license http://opensource.org/licenses/bsd-license.php The BSD License
  7. */
  8. namespace lithium\test;
  9. use lithium\test\Dispatcher;
  10. use lithium\core\Libraries;
  11. use lithium\test\Group;
  12. use lithium\util\Set;
  13. /**
  14. * The Test Controller for running the html version of the test suite
  15. *
  16. */
  17. class Controller extends \lithium\core\Object {
  18. /**
  19. * Magic method to make Controller callable.
  20. *
  21. * @see lithium\action\Dispatcher::_callable()
  22. * @param object $request A \lithium\action\Request object.
  23. * @param array $dispatchParams Array of params after being parsed by router.
  24. * @param array $options Some basic options for this controller.
  25. * @return string
  26. * @filter
  27. */
  28. public function __invoke($request, $dispatchParams, array $options = array()) {
  29. $dispatchParamsDefaults = array('args' => array());
  30. $dispatchParams += $dispatchParamsDefaults;
  31. $defaults = array('format' => 'html', 'timeout' => 0);
  32. $options += (array) $request->query + $defaults;
  33. $params = compact('request', 'dispatchParams', 'options');
  34. return $this->_filter(__METHOD__, $params, function($self, $params) {
  35. $request = $params['request'];
  36. $options = $params['options'];
  37. $params = $params['dispatchParams'];
  38. set_time_limit((integer) $options['timeout']);
  39. $group = join('\\', (array) $params['args']);
  40. if ($group === "all") {
  41. $group = Group::all();
  42. $options['title'] = 'All Tests';
  43. }
  44. $report = Dispatcher::run($group, $options);
  45. $filters = Libraries::locate('test.filter');
  46. $menu = Libraries::locate('tests', null, array(
  47. 'filter' => '/cases|integration|functional/',
  48. 'exclude' => '/mocks/'
  49. ));
  50. sort($menu);
  51. $menu = Set::expand(array_combine($menu, $menu), array('separator' => "\\"));
  52. $result = compact('request', 'report', 'filters', 'menu');
  53. return $report->render('layout', $result);
  54. });
  55. }
  56. }
  57. ?>