Tests are added to this group either on construct by passing a fully-namespaced test class or namespace string-based path, e.g. $group = new Group(array('data' => array( 'data\ModelTest', new \lithium\tests\cases\core\ObjectTest() ))); Or they can be added programmatically: $group->add('data\ModelTest');
Inheritance: extends lithium\util\Collection
Example #1
0
 public function testAnalyze()
 {
     $ns = 'lithium\\tests\\cases';
     $expected = array('lithium\\g11n\\Message' => "{$ns}\\g11n\\MessageTest", 'lithium\\console\\command\\g11n\\Extract' => "{$ns}\\console\\command\\g11n\\ExtractTest");
     $group = new Group();
     $group->add('lithium\\tests\\cases\\g11n\\CatalogTest');
     $this->report->group = $group;
     $tests = Affected::apply($this->report, $group->tests());
     $results = Affected::analyze($this->report);
     $this->assertEqual($results, $expected);
 }
Example #2
0
 public function testCyclicDependency()
 {
     $group = new Group();
     $group->add('lithium\\tests\\cases\\g11n\\CatalogTest');
     $group->add('lithium\\tests\\cases\\g11n\\MessageTest');
     $this->report->group = $group;
     $tests = Affected::apply($this->report, $group->tests());
     $expected = array('lithium\\tests\\cases\\g11n\\CatalogTest', 'lithium\\tests\\cases\\g11n\\MessageTest', 'lithium\\tests\\cases\\console\\command\\g11n\\ExtractTest');
     $result = $tests->map('get_class', array('collect' => false));
     $this->assertEqual($expected, $result);
 }
Example #3
0
 /**
  * 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);
     });
 }
Example #4
0
 /**
  * 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));
     }
 }
 /**
  * Tests the `collect` method which takes the raw report data and prepares it for analysis.
  *
  * @see lithium\test\filter\Complexity::collect()
  */
 public function testCollect()
 {
     extract($this->_paths);
     $group = new Group();
     $group->add($testClassTest);
     $this->report->group = $group;
     Complexity::apply($this->report, $group->tests());
     $results = Complexity::collect($this->report->results['filters'][$complexity]);
     $expected = array($testClass => $this->_metrics);
     $this->assertEqual($expected, $results);
 }
Example #6
0
 /**
  * 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);
 }
Example #7
0
 public function testRunGroupForTestAppModel()
 {
     $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);
     $group = new Group(array('data' => array('\\test_app\\tests\\cases')));
     $expected = array('test_app\\tests\\cases\\models\\UserTest');
     $result = $group->to('array');
     $this->assertEqual($expected, $result);
     $expected = 'pass';
     $result = $group->tests()->run();
     $this->assertEqual($expected, $result[0][0]['result']);
     Libraries::cache(false);
     $this->_cleanUp();
 }
 public function testQueryAllTests()
 {
     $result = Group::all(array('library' => 'lithium'));
     $this->assertTrue(count($result) >= 60);
 }