コード例 #1
0
ファイル: unittest.php プロジェクト: joelpittet/unittest
 /**
  * Handles test running interface
  */
 public function action_run()
 {
     $this->template->body = View::factory('unittest/results');
     // Get the test suite and work out which groups we're testing
     $suite = Kohana_Tests::suite();
     $group = (array) Arr::get($_GET, 'group', array());
     // Stop phpunit from interpretting "all groups" as "no groups"
     if (empty($group) or empty($group[0])) {
         $group = array();
     }
     // Only collect code coverage if the user asked for it
     $collect_cc = (bool) Arr::get($_GET, 'collect_cc', FALSE);
     if ($collect_cc and Arr::get($_GET, 'use_whitelist', FALSE)) {
         $whitelist = $this->whitelist(Arr::get($_GET, 'whitelist', array()));
     }
     $runner = new Kohana_PHPUnit($suite);
     try {
         $runner->run($group, $collect_cc);
         if ($collect_cc) {
             $this->template->body->set('coverage', $runner->calculate_cc_percentage());
         }
         if (isset($whitelist)) {
             $this->template->body->set('coverage_explanation', $this->nice_whitelist_explanation($whitelist));
         }
     } catch (Kohana_Exception $e) {
         // Code coverage is not allowed, possibly xdebug disabled?
         // TODO: Tell the user this?
         $runner->run($group);
     }
     // Show some results
     $this->template->body->set('results', $runner->results)->set('totals', $runner->totals)->set('time', $this->nice_time($runner->time))->set('group', Arr::get($this->get_groups_list($suite), reset($group), 'All groups'))->set('groups', $this->get_groups_list($suite))->set('report_uri', $this->report_uri . url::query())->set('whitelistable_items', $this->get_whitelistable_items())->set('whitelisted_items', isset($whitelist) ? array_keys($whitelist) : array())->set('whitelist', !empty($whitelist));
 }