getMethods() as $method) { if (preg_match('/test/i', $method->name)) { $testMethods []= $method; } } } return $testMethods; } function runAll() { $startTime = microtime(true); $testMethods = getTestMethods(); echo 'Starting tests' . PHP_EOL; //get display names of the methods $labels = []; foreach ($testMethods as $key => $method) $labels[$key] = $method->class . '::' . $method->name; //ensure every label has the same length $maxLabelLength = max(array_map('strlen', $labels)); foreach ($labels as &$label) $label = str_pad($label, $maxLabelLength + 1, ' '); $pad = count($testMethods) ? ceil(log10(count($testMethods))) : 0; //run all the methods $success = true; foreach ($testMethods as $key => $method) { $instance = new $method->class(); $testStartTime = microtime(true); echo str_pad($key + 1, $pad, ' ', STR_PAD_LEFT) . ' '; echo $labels[$key] . '... '; unset($e); try { runSingle(function() use ($method, $instance) { $method->invoke($instance); }); echo 'OK'; } catch (Exception $e) { $success = false; echo 'FAIL'; } printf(' [%.03fs]' . PHP_EOL, microtime(true) - $testStartTime); if (isset($e)) { echo '---' . PHP_EOL; echo $e->getMessage() . PHP_EOL; echo $e->getTraceAsString() . PHP_EOL; echo '---' . PHP_EOL . PHP_EOL; } } printf('%s %s... %s [%.03fs]' . PHP_EOL, str_pad('', $pad, ' '), str_pad('All tests', $maxLabelLength + 1, ' '), $success ? 'OK' : 'FAIL', microtime(true) - $startTime); return $success; } function runSingle($callback) { resetEnvironment(); \Chibi\Database::rollback(function() use ($callback) { $callback(); }); }