Exemplo n.º 1
0
 /**
  * Handles report generation
  */
 public function action_report()
 {
     // We don't want to use the HTML layout, we're sending the user 100111011100110010101100
     $this->auto_render = FALSE;
     $suite = Kohana_Tests::suite();
     $temp_path = rtrim($this->config->temp_path, '/') . '/';
     $group = (array) Arr::get($_GET, 'group', array());
     $report_format = Arr::get($_POST, 'format', 'PHP_Util_Report');
     // Fairly foolproof
     if ($report_format !== 'PHP_Util_Report' && !class_exists('Archive')) {
         throw new Kohana_Exception('The Archive module is needed to package the reports');
     }
     // Stop phpunit from interpretting "all groups" as "no groups"
     if (empty($group) or empty($group[0])) {
         $group = array();
     }
     if (Arr::get($_GET, 'use_whitelist', FALSE)) {
         $this->whitelist(Arr::get($_GET, 'whitelist', array()));
     }
     $runner = new Kohana_PHPUnit($suite);
     if ($report_format === 'PHP_Util_Report') {
         $file_handler = opendir($this->config->temp_path);
         while (false !== ($dirname = readdir($file_handler))) {
             if (0 !== strpos($dirname, '.') && is_dir($this->config->temp_path . $dirname)) {
                 $this->rmdir_recursive($this->config->temp_path . $dirname);
             }
         }
     }
     // $report is the actual directory of the report,
     // $folder is the name component of directory
     list($report, $folder) = $runner->generate_report($group, $temp_path, $report_format);
     if ($report_format !== 'PHP_Util_Report') {
         $archive = Archive::factory('zip');
         // TODO: Include the test results?
         $archive->add($report, 'report', TRUE);
         $filename = $folder . '.zip';
         $archive->save($temp_path . $filename);
         $this->request->send_file($temp_path . $filename, $filename);
     } else {
         Request::instance()->redirect($this->config->coverage_url . $folder . '/index.html');
     }
 }
Exemplo n.º 2
0
 /**
  * Handles report generation
  */
 public function action_report()
 {
     // Fairly foolproof
     if (!$this->config->cc_report_path and !class_exists('Archive')) {
         throw new Kohana_Exception('Cannot generate report');
     }
     // We don't want to use the HTML layout, we're sending the user 100111011100110010101100
     $this->auto_render = FALSE;
     $suite = Kohana_Tests::suite();
     $temp_path = rtrim($this->config->temp_path, '/') . '/';
     $group = (array) Arr::get($_GET, 'group', array());
     // Stop unittest from interpretting "all groups" as "no groups"
     if (empty($group) or empty($group[0])) {
         $group = array();
     }
     if (Arr::get($_GET, 'use_whitelist', FALSE)) {
         $this->whitelist(Arr::get($_GET, 'whitelist', array()));
     }
     $runner = new Kohana_PHPUnit($suite);
     // If the user wants to download a report
     if ($this->cc_archive_enabled and Arr::get($_GET, 'archive') === '1') {
         // $report is the actual directory of the report,
         // $folder is the name component of directory
         list($report, $folder) = $runner->generate_report($group, $temp_path);
         $archive = Archive::factory('zip');
         // TODO: Include the test results?
         $archive->add($report, 'report', TRUE);
         $filename = $folder . '.zip';
         $archive->save($temp_path . $filename);
         // It'd be nice to clear up afterwards but by deleting the report dir we corrupt the archive
         // And once the archive has been sent to the user Request stops the script so we can't delete anything
         // It'll be up to the user to delete files periodically
         $this->request->send_file($temp_path . $filename, $filename);
     } else {
         $folder = trim($this->config->cc_report_path, '/') . '/';
         $path = DOCROOT . $folder;
         if (!file_exists($path)) {
             throw new Kohana_Exception('Report directory :dir does not exist', array(':dir' => $path));
         }
         if (!is_writable($path)) {
             throw new Kohana_Exception('Script doesn\'t have permission to write to report dir :dir ', array(':dir' => $path));
         }
         $runner->generate_report($group, $path, FALSE);
         $this->request->redirect(URL::base(FALSE, TRUE) . $folder . 'index.html');
     }
 }
Exemplo n.º 3
0
 /**
  * Handles report generation
  */
 public function action_report()
 {
     // Fairly foolproof
     if (!class_exists('Archive')) {
         throw new Kohana_Exception('The Archive module is needed to package the reports');
     }
     // We don't want to use the HTML layout, we're sending the user 100111011100110010101100
     $this->auto_render = FALSE;
     $suite = Kohana_Tests::suite();
     $temp_path = rtrim($this->config->temp_path, '/') . '/';
     $group = (array) Arr::get($_GET, 'group', array());
     $report_format = Arr::get($_POST, 'format', 'PHP_Util_Report');
     // Stop phpunit from interpretting "all groups" as "no groups"
     if (empty($group) or empty($group[0])) {
         $group = array();
     }
     if (Arr::get($_GET, 'use_whitelist', FALSE)) {
         $this->whitelist(Arr::get($_GET, 'whitelist', array()));
     }
     $runner = new Kohana_PHPUnit($suite);
     // $report is the actual directory of the report,
     // $folder is the name component of directory
     list($report, $folder) = $runner->generate_report($group, $temp_path, $report_format);
     $archive = Archive::factory('zip');
     // TODO: Include the test results?
     $archive->add($report, 'report', TRUE);
     $filename = $folder . '.zip';
     $archive->save($temp_path . $filename);
     // It'd be nice to clear up afterwards but by deleting the report dir we corrupt the archive
     // And once the archive has been sent to the user Request stops the script so we can't delete anything
     // It'll be up to the user to delete files periodically
     $this->request->send_file($temp_path . $filename, $filename);
 }