diff --git a/run-tests.php b/run-tests.php index 092009b50011c..a575f93cd4d5b 100755 --- a/run-tests.php +++ b/run-tests.php @@ -28,10 +28,10 @@ /* Let there be no top-level code beyond this point: * Only functions and classes, thanks! * - * Minimum required PHP version: 7.0.0 + * Minimum required PHP version: 7.1.0 */ -function show_usage() +function show_usage(): void { echo << 'php_error' @@ -1732,7 +1755,7 @@ function run_worker() // // Show file or result block // -function show_file_block($file, $block, $section = null) +function show_file_block(string $file, string $block, ?string $section = null): void { global $cfg; @@ -1750,7 +1773,10 @@ function show_file_block($file, $block, $section = null) // // Run an individual test case. // -function run_test($php, $file, $env) +/** + * @param string|array $file + */ +function run_test(string $php, $file, array $env): string { global $log_format, $ini_overwrites, $PHP_FAILED_TESTS; global $pass_options, $DETAILED, $IN_REDIRECT, $test_cnt, $test_idx; @@ -2777,7 +2803,10 @@ function run_test($php, $file, $env) return $restype[0] . 'ED'; } -function comp_line($l1, $l2, $is_reg) +/** + * @return bool|int + */ +function comp_line(string $l1, string $l2, bool $is_reg) { if ($is_reg) { return preg_match('/^' . $l1 . '$/s', $l2); @@ -2786,8 +2815,17 @@ function comp_line($l1, $l2, $is_reg) } } -function count_array_diff($ar1, $ar2, $is_reg, $w, $idx1, $idx2, $cnt1, $cnt2, $steps) -{ +function count_array_diff( + array $ar1, + array $ar2, + bool $is_reg, + array $w, + int $idx1, + int $idx2, + int $cnt1, + int $cnt2, + int $steps +): int { $equal = 0; while ($idx1 < $cnt1 && $idx2 < $cnt2 && comp_line($ar1[$idx1], $ar2[$idx2], $is_reg)) { @@ -2828,7 +2866,7 @@ function count_array_diff($ar1, $ar2, $is_reg, $w, $idx1, $idx2, $cnt1, $cnt2, $ return $equal; } -function generate_array_diff($ar1, $ar2, $is_reg, $w) +function generate_array_diff(array $ar1, array $ar2, bool $is_reg, array $w): array { $idx1 = 0; $cnt1 = @count($ar1); @@ -2896,7 +2934,7 @@ function generate_array_diff($ar1, $ar2, $is_reg, $w) return $diff; } -function generate_diff($wanted, $wanted_re, $output) +function generate_diff(string $wanted, ?string $wanted_re, string $output): string { $w = explode("\n", $wanted); $o = explode("\n", $output); @@ -2906,13 +2944,13 @@ function generate_diff($wanted, $wanted_re, $output) return implode(PHP_EOL, $diff); } -function error($message) +function error(string $message): void { echo "ERROR: {$message}\n"; exit(1); } -function settings2array($settings, &$ini_settings) +function settings2array(array $settings, &$ini_settings): void { foreach ($settings as $setting) { if (strpos($setting, '=') !== false) { @@ -2933,7 +2971,7 @@ function settings2array($settings, &$ini_settings) } } -function settings2params($ini_settings) +function settings2params(array $ini_settings): string { $settings = ''; @@ -2962,7 +3000,7 @@ function settings2params($ini_settings) return $settings; } -function compute_summary() +function compute_summary(): void { global $n_total, $test_results, $ignored_by_ext, $sum_results, $percent_results; @@ -2991,7 +3029,7 @@ function compute_summary() } } -function get_summary($show_ext_summary) +function get_summary(bool $show_ext_summary): string { global $exts_skipped, $exts_tested, $n_total, $sum_results, $percent_results, $end_time, $start_time, $failed_test_summary, $PHP_FAILED_TESTS, $valgrind; @@ -3057,7 +3095,7 @@ function get_summary($show_ext_summary) $failed_test_summary = ''; if (count($PHP_FAILED_TESTS['SLOW'])) { - usort($PHP_FAILED_TESTS['SLOW'], function ($a, $b) { + usort($PHP_FAILED_TESTS['SLOW'], function (array $a, array $b): int { return $a['info'] < $b['info'] ? 1 : -1; }); @@ -3154,22 +3192,22 @@ function get_summary($show_ext_summary) return $summary; } -function show_start($start_time) +function show_start($start_time): void { echo "TIME START " . date('Y-m-d H:i:s', $start_time) . "\n=====================================================================\n"; } -function show_end($end_time) +function show_end($end_time): void { echo "=====================================================================\nTIME END " . date('Y-m-d H:i:s', $end_time) . "\n"; } -function show_summary() +function show_summary(): void { echo get_summary(true); } -function show_redirect_start($tests, $tested, $tested_file) +function show_redirect_start(string $tests, string $tested, string $tested_file): void { global $SHOW_ONLY_GROUPS; @@ -3180,7 +3218,7 @@ function show_redirect_start($tests, $tested, $tested_file) } } -function show_redirect_ends($tests, $tested, $tested_file) +function show_redirect_ends(string $tests, string $tested, string $tested_file): void { global $SHOW_ONLY_GROUPS; @@ -3191,7 +3229,7 @@ function show_redirect_ends($tests, $tested, $tested_file) } } -function show_test($test_idx, $shortname) +function show_test(int $test_idx, string $shortname): void { global $test_cnt; global $line_length; @@ -3202,7 +3240,7 @@ function show_test($test_idx, $shortname) flush(); } -function clear_show_test() +function clear_show_test(): void { global $line_length; // Parallel testing @@ -3221,8 +3259,13 @@ function parse_conflicts(string $text): array return array_map('trim', explode("\n", trim($text))); } -function show_result($result, $tested, $tested_file, $extra = '', $temp_filenames = null) -{ +function show_result( + string $result, + string $tested, + string $tested_file, + string $extra = '', + ?array $temp_filenames = null +): void { global $temp_target, $temp_urlbase, $line_length, $SHOW_ONLY_GROUPS; if (!$SHOW_ONLY_GROUPS || in_array($result, $SHOW_ONLY_GROUPS)) { @@ -3233,7 +3276,7 @@ function show_result($result, $tested, $tested_file, $extra = '', $temp_filename } -function junit_init() +function junit_init(): void { // Check whether a junit log is wanted. global $workerID; @@ -3262,7 +3305,7 @@ function junit_init() ); } -function junit_save_xml() +function junit_save_xml(): void { global $JUNIT; if (!junit_enabled()) { @@ -3284,7 +3327,7 @@ function junit_save_xml() fwrite($JUNIT['fp'], $xml); } -function junit_get_suite_xml($suite_name = '') +function junit_get_suite_xml(string $suite_name = ''): string { global $JUNIT; @@ -3313,7 +3356,7 @@ function junit_get_suite_xml($suite_name = '') return $result; } -function junit_enabled() +function junit_enabled(): bool { global $JUNIT; return !empty($JUNIT); @@ -3321,16 +3364,15 @@ function junit_enabled() /** * @param array|string $type - * @param string $file_name - * @param string $test_name - * @param int|string $time - * @param string $message - * @param string $details - * - * @return void */ -function junit_mark_test_as($type, $file_name, $test_name, $time = null, $message = '', $details = '') -{ +function junit_mark_test_as( + $type, + string $file_name, + string $test_name, + ?int $time = null, + string $message = '', + string $details = '' +): void { global $JUNIT; if (!junit_enabled()) { return; @@ -3344,7 +3386,7 @@ function junit_mark_test_as($type, $file_name, $test_name, $time = null, $messag junit_suite_record($suite, 'execution_time', $time); $escaped_details = htmlspecialchars($details, ENT_QUOTES, 'UTF-8'); - $escaped_details = preg_replace_callback('/[\0-\x08\x0B\x0C\x0E-\x1F]/', function ($c) { + $escaped_details = preg_replace_callback('/[\0-\x08\x0B\x0C\x0E-\x1F]/', function (array $c): string { return sprintf('[[0x%02x]]', ord($c[0])); }, $escaped_details); $escaped_message = htmlspecialchars($message, ENT_QUOTES, 'UTF-8'); @@ -3382,7 +3424,7 @@ function junit_mark_test_as($type, $file_name, $test_name, $time = null, $messag $JUNIT['files'][$file_name]['xml'] .= "\n"; } -function junit_suite_record($suite, $param, $value = 1) +function junit_suite_record(string $suite, string $param, int $value = 1): void { global $JUNIT; @@ -3390,7 +3432,7 @@ function junit_suite_record($suite, $param, $value = 1) $JUNIT['suites'][$suite][$param] += $value; } -function junit_get_timer($file_name) +function junit_get_timer(string $file_name): int { global $JUNIT; if (!junit_enabled()) { @@ -3404,7 +3446,7 @@ function junit_get_timer($file_name) return 0; } -function junit_start_timer($file_name) +function junit_start_timer(string $file_name): void { global $JUNIT; if (!junit_enabled()) { @@ -3420,12 +3462,12 @@ function junit_start_timer($file_name) } } -function junit_get_suitename_for($file_name) +function junit_get_suitename_for(string $file_name): string { return junit_path_to_classname(dirname($file_name)); } -function junit_path_to_classname($file_name) +function junit_path_to_classname(string $file_name): string { global $JUNIT; @@ -3461,7 +3503,7 @@ function junit_path_to_classname($file_name) return $JUNIT['name'] . '.' . str_replace(array(DIRECTORY_SEPARATOR, '-'), '.', $file_name); } -function junit_init_suite($suite_name) +function junit_init_suite(string $suite_name): void { global $JUNIT; if (!junit_enabled()) { @@ -3485,7 +3527,7 @@ function junit_init_suite($suite_name) ); } -function junit_finish_timer($file_name) +function junit_finish_timer(string $file_name): void { global $JUNIT; if (!junit_enabled()) { @@ -3505,7 +3547,7 @@ function junit_finish_timer($file_name) unset($JUNIT['files'][$file_name]['start']); } -function junit_merge_results($junit) +function junit_merge_results(array $junit): void { global $JUNIT; $JUNIT['test_total'] += $junit['test_total']; @@ -3542,12 +3584,12 @@ class RuntestsValgrind protected $version_3_8_0 = false; protected $tool = null; - public function getVersion() + public function getVersion(): string { return $this->version; } - public function getHeader() + public function getHeader(): string { return $this->header; } @@ -3572,7 +3614,7 @@ public function __construct(array $environment, string $tool = 'memcheck') $this->version_3_8_0 = version_compare($version, '3.8.0', '>='); } - public function wrapCommand($cmd, $memcheck_filename, $check_all) + public function wrapCommand(string $cmd, string $memcheck_filename, bool $check_all): string { $vcmd = "valgrind -q --tool={$this->tool} --trace-children=yes"; if ($check_all) { @@ -3591,7 +3633,7 @@ public function wrapCommand($cmd, $memcheck_filename, $check_all) } } -function init_output_buffers() +function init_output_buffers(): void { // Delete as much output buffers as possible. while (@ob_end_clean()) { @@ -3602,7 +3644,7 @@ function init_output_buffers() } } -function check_proc_open_function_exists() +function check_proc_open_function_exists(): void { if (!function_exists('proc_open')) { echo <<