コード例 #1
0
 /**
  * Run unit tests selected via checkbox
  * @return TestGui
  */
 public function runSelectedTests()
 {
     self::getAvailableTests();
     // just to include all files
     if (array_key_exists('runtest', $_REQUEST)) {
         // logging
         require_once dirname(__FILE__) . DS . 'SimpleHtmlReporter.php';
         $out = "\n" . str_repeat('=', 50) . "\nStarting tests, executed by user [" . self::getUserName() . "]. Deleted [" . TestUtils::flushTempDir() . "] files from temp dir [" . DIR_TEMP . "]\n" . str_repeat('=', 50);
         TestUtils::log($out, self::LOGNAME, TestUtils::LEVEL_INFO);
         $selected_tests = array();
         foreach ($_REQUEST['runtest'] as $test_case => $methods) {
             if (is_array($methods)) {
                 $selected_tests[$test_case] = array_keys($methods);
             } else {
                 $this->errors[] = '<div class="alert alert-error">Caution - TestCase "' . $test_case . '" has no selected unit test.</div>';
             }
         }
         $reporter = new SimpleHtmlReporter();
         $reporter->setTests($selected_tests);
         $test_suite = new TestSuite();
         foreach ($selected_tests as $class => $methods) {
             /**
              * @var WebTestCase
              */
             $test_case = new $class();
             // uprav nastavenia podla typu prostredia
             $modifier_class = $class . 'Set';
             if (class_exists($modifier_class, false)) {
                 // pozri priklad v testing/database.php
                 $test_case = call_user_func(array($modifier_class, 'set'), $test_case);
             }
             $test_suite->add($test_case);
         }
         $test_suite->run($reporter);
         self::$output_result_tests = $reporter->getOutput();
         // logging
         foreach ($reporter->getStatus() as $name => $test_case) {
             $log = '[' . $test_case['passed'] . '] passed, [' . $test_case['failed'] . '] failed for [' . $name . ']. Executed methods: ' . implode(', ', $test_case['methods']);
             if (sizeof($test_case['messages']) > 0) {
                 $log .= "\n" . implode("\n", $test_case['messages']);
             }
             TestUtils::log(strip_tags($log), self::LOGNAME, TestUtils::LEVEL_INFO);
         }
         $timeMemory = " -- Execution time [" . TestUtils::execTime() . '], memory usage [' . TestUtils::getMemoryUsage() . ']';
         TestUtils::log($timeMemory, self::LOGNAME, TestUtils::LEVEL_INFO);
     }
     return self::$instance;
 }