getLoader() public method

Returns the loader to be used.
public getLoader ( ) : PHPUnit_Runner_TestSuiteLoader
return PHPUnit_Runner_TestSuiteLoader
Ejemplo n.º 1
0
 /**
  * @access public
  * @static
  */
 public static function main()
 {
     self::_initConfiguration();
     self::_initSuitesAndTests();
     self::_initArguments();
     $runner = new PHPUnit_TextUI_TestRunner();
     $master_suite = new PHPUnit_Framework_TestSuite('Zend Framework');
     $loadable_suites = array();
     if (count(self::$_arguments['suite_filter']) > 0) {
         $first_pass = true;
         foreach (self::$_arguments['suite_filter'] as $suite_filter) {
             // if the suite filter is not valid class name (extranious char.) - continue
             if (!preg_match("/[a-z0-9\\-_.]/i", $suite_filter)) {
                 continue;
             }
             if ($suite_filter[0] != "@" && strpos($suite_filter, "#") === false) {
                 /**
                  * This block will parse all filters below the named suite (branch)
                  */
                 foreach (self::$_test_suites as $test_suite) {
                     if (strpos($test_suite, $suite_filter) !== false) {
                         $suite_config = ZFTestManager::getConfig($test_suite);
                         if (isset($suite_config['disabled']) && $suite_config['disabled'] == true) {
                             continue;
                         }
                         $loadable_suites[$test_suite] = null;
                     }
                 }
             } elseif ($suite_filter[0] == "@") {
                 /**
                  * This block will mark only
                  */
                 $suite_filter_base = ltrim($suite_filter, "@");
                 if (in_array($suite_filter_base, self::$_test_suites)) {
                     $loadable_suites[$suite_filter_base] = null;
                 } else {
                     continue;
                 }
                 // remove branches deeper than this one if they exist
                 foreach (self::$_test_suites as $test_suite_id => $test_suite) {
                     if (strpos($test_suite, $suite_filter_base) === 0) {
                         unset(self::$_test_suites[$test_suite_id]);
                     }
                 }
                 continue;
             } elseif (strpos($suite_filter, "#") !== false) {
                 list($suite_filter_base, $suite_filter_testcase) = split("#", $suite_filter);
                 if ($suite_filter_base != "" && $suite_filter_testcase != "") {
                     $loadable_suites[$suite_filter_base] = $suite_filter_testcase;
                 }
             }
         }
     } else {
         foreach (self::$_test_suites as $suite_name) {
             $suite_config = ZFTestManager::getConfig($suite_name);
             if (isset($suite_config['disabled']) && $suite_config['disabled'] == true) {
                 continue;
             }
             $loadable_suites[$suite_name] = null;
         }
     }
     foreach ($loadable_suites as $suite_name => $sub_suite) {
         $runner->getLoader()->load($suite_name . "_AllTests", str_replace("_", DIRECTORY_SEPARATOR, $suite_name) . DIRECTORY_SEPARATOR . "AllTests.php");
         $classname = $suite_name . "_AllTests";
         $master_suite->addTestSuite(call_user_func(array($classname, "suite"), $sub_suite));
     }
     if ($master_suite->testCount() == 0) {
         self::_printVersionString();
         echo "\nNo tests found in the current working directory.\n\n";
         exit(PHPUnit_TextUI_TestRunner::EXCEPTION_EXIT);
     }
     try {
         self::_printVersionString(false);
         $runner_parameters = array_merge(self::$_configuration['runner_parameters'], self::$_arguments['runner_parameters']);
         $result = $runner->doRun($master_suite, $runner_parameters);
     } catch (Exception $e) {
         throw new RuntimeException('Could not create and run test suite: ' . $e->getMessage());
     }
     if ($result->wasSuccessful()) {
         exit(PHPUnit_TextUI_TestRunner::SUCCESS_EXIT);
     } else {
         if ($result->errorCount() > 0) {
             exit(PHPUnit_TextUI_TestRunner::EXCEPTION_EXIT);
         } else {
             exit(PHPUnit_TextUI_TestRunner::FAILURE_EXIT);
         }
     }
 }