/** * 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'); set_time_limit(0); 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); }); }
/** * Main method. * * @param string $path Absolute path to file or directory. * @return boolean */ public function run() { $path = $this->request->action; if (!($path = realpath($path))) { $this->error('Not a valid path.'); return false; } if (!($library = $this->_library($path))) { $this->error("No library registered for path `{$path}`."); return false; } $classes = Libraries::find($library, array('recursive' => true, 'exclude' => '/tests|resources|webroot|index$|^app\\\\config|^app\\\\views|Exception$/')); $tests = array(); foreach (Group::all() as $test) { $class = preg_replace('/(tests\\\\[a-z]+\\\\|Test$)/', null, $test); $tests[$class] = $test; } foreach ($classes as $class) { $coverage = null; if ($hasTest = isset($tests[$class])) { $report = Dispatcher::run($tests[$class], array('reporter' => 'console', 'format' => 'txt', 'filters' => array('Coverage'))); $coverage = $report->results['filters']['lithium\\test\\filter\\Coverage']; $coverage = isset($coverage[$class]) ? $coverage[$class]['percentage'] : null; } $this->out(sprintf('%10s | %7s | %s', $hasTest ? 'has test' : 'no test', is_numeric($coverage) ? sprintf('%.2f%%', $coverage) : 'n/a', $class)); } }
/** * Shows which classes are un-tested. * * @return void */ public function missing() { $this->header('Classes with no test case'); $classes = Libraries::find(true, array('recursive' => true, 'exclude' => '/\\w+Test$|webroot|index$|^app\\\\config|^app\\\\views/')); $tests = Group::all(); $classes = array_diff($classes, $tests); sort($classes); $this->out($classes); }
public function testRunGroupAllForTestApp() { $testApp = Libraries::get(true, 'resources') . '/tmp/tests/test_app'; mkdir($testApp); Libraries::add('test_app', array('path' => $testApp)); mkdir($testApp . '/tests/cases/models', 0777, true); file_put_contents($testApp . '/tests/cases/models/UserTest.php', "<?php namespace test_app\\tests\\cases\\models;\n\n\t\t\tclass UserTest extends \\lithium\\test\\Unit { public function testMe() {\n\t\t\t\t\$this->assertTrue(true);\n\t\t\t}}"); Libraries::cache(false); $expected = array('test_app\\tests\\cases\\models\\UserTest'); $result = Group::all(array('library' => 'test_app')); $this->assertEqual($expected, $result); Libraries::cache(false); $this->_cleanUp(); }
public function testQueryAllTests() { $result = Group::all(array('library' => 'lithium')); $this->assertTrue(count($result) >= 60); }