public static function run() { self::loadClasses(); $total = 0; $failed = 0; $errors = 0; echo BaseTest::_indent('Starting testing phase:'); $cwd = getcwd(); foreach (self::$children as $instance) { chdir(static::classFolder($instance)); $instance->prepare(); $methods = get_class_methods($instance); foreach ($methods as $method) { if (!preg_match('/^test[a-zA-Z0-9_]*$/', $method)) { continue; } static::$state = BaseTest::STATE_OK; static::$tests = 0; echo BaseTest::_indent('Running test "' . get_class($instance) . '->' . $method . '"<br />', 1); try { $msg = call_user_method($method, $instance); if (is_string($msg)) { echo BaseTest::_indent('<span class="message">Got Message ' . $msg . ' </span><br />', 2); } if (static::$state == BaseTest::STATE_OK) { echo BaseTest::_indent('<span class="ok">Sub tests passed (' . static::$tests . ' tests ran)</span><br />', 1); } else { $failed += static::$tests; echo BaseTest::_indent('<span class="warning">Sub tests not passed. (' . static::$tests . ' tests ran)</span><br />', 1); } $total += static::$tests; } catch (Exception $e) { static::$tests++; // Was not increased due to error $total += static::$tests; $errors += static::$tests; echo BaseTest::_indent('<span class="error">Error while testing. Msg:' . $e->getMessage() . ' (' . static::$tests . ' tests ran)</span><br />', 1); continue; } echo '<br />'; } $instance->finish(); } chdir($cwd); echo '<div class="results">'; echo 'Testing finished, a total of <strong>' . $total . '</strong> tests ran: <br />'; echo BaseTest::_indent('<span class="label label-result">Errors:</span><span class="error">' . $errors . '</span><br />', 1); echo BaseTest::_indent('<span class="label label-result">Fails:</span><span class="warning">' . $failed . '</span><br />', 1); echo BaseTest::_indent('<span class="label label-result">Passed:</span><span class="ok">' . ($total - $errors - $failed) . '</span><br />', 1); echo '</div>'; }