Beispiel #1
0
 protected function _doRun()
 {
     $short_opts = self::getShortOpts();
     $long_opts = self::getLongOpts();
     lmbTestGetopt::defineAndExtractConstants($this->argv);
     try {
         if ($this->posix_opts) {
             $options = lmbTestGetopt::getopt($this->argv, $short_opts, $long_opts);
         } else {
             $options = lmbTestGetopt::getopt2($this->argv, $short_opts, $long_opts);
         }
     } catch (Exception $e) {
         $this->_help(1);
     }
     $config_file = null;
     $cover_include = '';
     $cover_exclude = '';
     $cover_report_dir = null;
     foreach ($options[0] as $option) {
         switch ($option[0]) {
             case 'h':
             case '--help':
                 $this->_help(0);
                 break;
             case 'V':
             case '--verbose':
                 lmbTestOptions::set('verbose', true);
                 break;
             case 'v':
             case '--version':
                 $this->_version();
                 break;
             case 'c':
             case '--config':
                 $config_file = $option[1];
                 break;
             case 'I':
             case '--include':
                 lmbTestOptions::set('file_filter', $option[1]);
                 break;
             case 'G':
             case '--groups':
                 lmbTestOptions::set('groups_filter', array_map('trim', explode(',', trim($option[1]))));
                 break;
             case 'T':
             case '--tests':
                 lmbTestOptions::set('tests_filter', array_map('trim', explode(',', trim($option[1]))));
                 break;
             case 'M':
             case '--methods':
                 lmbTestOptions::set('methods_filter', array_map('trim', explode(',', trim($option[1]))));
                 break;
             case 'C':
             case '--cover':
                 $cover_include = $option[1];
                 break;
             case '--cover-report':
                 $cover_report_dir = $option[1];
                 break;
             case '--cover-exclude':
                 $cover_exclude = $option[1];
                 break;
         }
     }
     if (!$config_file) {
         $config_file = getenv('LIMB_TESTS_RUNNER_CONFIG');
     }
     if ($config_file) {
         if (!($php = @file_get_contents(realpath($config_file)))) {
             $this->_error("Could not read configuration file '{$config_file}'\n");
         }
         if (!$this->_phpLint($php, $error)) {
             $this->_error("Configuration file '{$config_file}' is invalid(check syntax)\n{$error}");
         }
         if (!(include_once realpath($config_file))) {
             $this->_error("Could not include configuration file '{$config_file}'\n");
         }
     }
     if (!is_array($options[1]) || !count($options[1])) {
         $paths = array('.');
     } else {
         $paths = $options[1];
     }
     if (!$cover_report_dir && defined('LIMB_TESTS_RUNNER_COVERAGE_REPORT_DIR')) {
         $cover_report_dir = LIMB_TESTS_RUNNER_COVERAGE_REPORT_DIR;
     }
     require_once dirname(__FILE__) . '/lmbTestRunner.class.php';
     $runner = new lmbTestRunner();
     if ($this->reporter) {
         $runner->setReporter($this->reporter);
     }
     if ($cover_include) {
         $runner->useCoverage($cover_include, $cover_exclude, $cover_report_dir);
     }
     try {
         require_once dirname(__FILE__) . '/lmbTestTreeGlobNode.class.php';
         $node = new lmbTestTreeGlobNode($paths);
         $res = $runner->run($node);
     } catch (lmbTestUserException $e) {
         $this->_error($e->getMessage());
     } catch (Exception $e) {
         $this->_error($e->__toString());
     }
     return $res;
 }