@@ -234,65 +234,6 @@ function main(): void
234
234
$ php_cgi = null ;
235
235
$ phpdbg = null ;
236
236
237
- if (getenv ('TEST_PHP_EXECUTABLE ' )) {
238
- $ php = getenv ('TEST_PHP_EXECUTABLE ' );
239
-
240
- if ($ php == 'auto ' ) {
241
- $ php = TEST_PHP_SRCDIR . '/sapi/cli/php ' ;
242
- putenv ("TEST_PHP_EXECUTABLE= $ php " );
243
-
244
- if (!getenv ('TEST_PHP_CGI_EXECUTABLE ' )) {
245
- $ php_cgi = TEST_PHP_SRCDIR . '/sapi/cgi/php-cgi ' ;
246
-
247
- if (file_exists ($ php_cgi )) {
248
- putenv ("TEST_PHP_CGI_EXECUTABLE= $ php_cgi " );
249
- } else {
250
- $ php_cgi = null ;
251
- }
252
- }
253
- }
254
- $ environment ['TEST_PHP_EXECUTABLE ' ] = $ php ;
255
- }
256
-
257
- if (getenv ('TEST_PHP_CGI_EXECUTABLE ' )) {
258
- $ php_cgi = getenv ('TEST_PHP_CGI_EXECUTABLE ' );
259
-
260
- if ($ php_cgi == 'auto ' ) {
261
- $ php_cgi = TEST_PHP_SRCDIR . '/sapi/cgi/php-cgi ' ;
262
- putenv ("TEST_PHP_CGI_EXECUTABLE= $ php_cgi " );
263
- }
264
-
265
- $ environment ['TEST_PHP_CGI_EXECUTABLE ' ] = $ php_cgi ;
266
- }
267
-
268
- if (!getenv ('TEST_PHPDBG_EXECUTABLE ' )) {
269
- if (IS_WINDOWS && file_exists (dirname ($ php ) . "/phpdbg.exe " )) {
270
- $ phpdbg = realpath (dirname ($ php ) . "/phpdbg.exe " );
271
- } elseif (file_exists (dirname ($ php ) . "/../../sapi/phpdbg/phpdbg " )) {
272
- $ phpdbg = realpath (dirname ($ php ) . "/../../sapi/phpdbg/phpdbg " );
273
- } elseif (file_exists ("./sapi/phpdbg/phpdbg " )) {
274
- $ phpdbg = realpath ("./sapi/phpdbg/phpdbg " );
275
- } elseif (file_exists (dirname ($ php ) . "/phpdbg " )) {
276
- $ phpdbg = realpath (dirname ($ php ) . "/phpdbg " );
277
- } else {
278
- $ phpdbg = null ;
279
- }
280
- if ($ phpdbg ) {
281
- putenv ("TEST_PHPDBG_EXECUTABLE= $ phpdbg " );
282
- }
283
- }
284
-
285
- if (getenv ('TEST_PHPDBG_EXECUTABLE ' )) {
286
- $ phpdbg = getenv ('TEST_PHPDBG_EXECUTABLE ' );
287
-
288
- if ($ phpdbg == 'auto ' ) {
289
- $ phpdbg = TEST_PHP_SRCDIR . '/sapi/phpdbg/phpdbg ' ;
290
- putenv ("TEST_PHPDBG_EXECUTABLE= $ phpdbg " );
291
- }
292
-
293
- $ environment ['TEST_PHPDBG_EXECUTABLE ' ] = $ phpdbg ;
294
- }
295
-
296
237
if (getenv ('TEST_PHP_LOG_FORMAT ' )) {
297
238
$ log_format = strtoupper (getenv ('TEST_PHP_LOG_FORMAT ' ));
298
239
} else {
@@ -692,13 +633,34 @@ function main(): void
692
633
return ;
693
634
}
694
635
695
- // Default to PHP_BINARY as executable
696
- if (!isset ($ environment ['TEST_PHP_EXECUTABLE ' ])) {
636
+ if (!$ php ) {
637
+ $ php = getenv ('TEST_PHP_EXECUTABLE ' );
638
+ }
639
+ if (!$ php ) {
697
640
$ php = PHP_BINARY ;
698
- putenv ("TEST_PHP_EXECUTABLE= $ php " );
699
- $ environment ['TEST_PHP_EXECUTABLE ' ] = $ php ;
700
641
}
701
642
643
+ if (!$ php_cgi ) {
644
+ $ php_cgi = getenv ('TEST_PHP_CGI_EXECUTABLE ' );
645
+ }
646
+ if (!$ php_cgi ) {
647
+ $ php_cgi = get_binary ($ php , 'php-cgi ' , 'sapi/cgi/php-cgi ' );
648
+ }
649
+
650
+ if (!$ phpdbg ) {
651
+ $ phpdbg = getenv ('TEST_PHPDBG_EXECUTABLE ' );
652
+ }
653
+ if (!$ phpdbg ) {
654
+ $ phpdbg = get_binary ($ php , 'phpdbg ' , 'sapi/phpdbg/phpdbg ' );
655
+ }
656
+
657
+ putenv ("TEST_PHP_EXECUTABLE= $ php " );
658
+ $ environment ['TEST_PHP_EXECUTABLE ' ] = $ php ;
659
+ putenv ("TEST_PHP_CGI_EXECUTABLE= $ php_cgi " );
660
+ $ environment ['TEST_PHP_CGI_EXECUTABLE ' ] = $ php_cgi ;
661
+ putenv ("TEST_PHPDBG_EXECUTABLE= $ phpdbg " );
662
+ $ environment ['TEST_PHPDBG_EXECUTABLE ' ] = $ phpdbg ;
663
+
702
664
if ($ conf_passed !== null ) {
703
665
if (IS_WINDOWS ) {
704
666
$ pass_options .= " -c " . escapeshellarg ($ conf_passed );
@@ -1058,6 +1020,21 @@ function save_or_mail_results(): void
1058
1020
}
1059
1021
}
1060
1022
1023
+ function get_binary (string $ php , string $ sapi , string $ sapi_path ): ?string
1024
+ {
1025
+ $ dir = dirname ($ php );
1026
+ if (IS_WINDOWS && file_exists ("$ dir/ $ sapi.exe " )) {
1027
+ return realpath ("$ dir/ $ sapi.exe " );
1028
+ }
1029
+ if (file_exists ("$ dir/../../ $ sapi_path " )) {
1030
+ return realpath ("$ dir/../../ $ sapi_path " );
1031
+ }
1032
+ if (file_exists ("$ dir/ $ sapi " )) {
1033
+ return realpath ("$ dir/ $ sapi " );
1034
+ }
1035
+ return null ;
1036
+ }
1037
+
1061
1038
function find_files (string $ dir , bool $ is_ext_dir = false , bool $ ignore = false ): void
1062
1039
{
1063
1040
global $ test_files , $ exts_to_test , $ ignored_by_ext , $ exts_skipped ;
@@ -2007,25 +1984,14 @@ function run_test(string $php, $file, array $env): string
2007
1984
2008
1985
/* For GET/POST/PUT tests, check if cgi sapi is available and if it is, use it. */
2009
1986
if (array_key_exists ('CGI ' , $ section_text ) || !empty ($ section_text ['GET ' ]) || !empty ($ section_text ['POST ' ]) || !empty ($ section_text ['GZIP_POST ' ]) || !empty ($ section_text ['DEFLATE_POST ' ]) || !empty ($ section_text ['POST_RAW ' ]) || !empty ($ section_text ['PUT ' ]) || !empty ($ section_text ['COOKIE ' ]) || !empty ($ section_text ['EXPECTHEADERS ' ])) {
2010
- if (isset ($ php_cgi )) {
2011
- $ php = $ php_cgi . ' -C ' ;
2012
- } elseif (IS_WINDOWS && file_exists (dirname ($ php ) . "/php-cgi.exe " )) {
2013
- $ php = realpath (dirname ($ php ) . "/php-cgi.exe " ) . ' -C ' ;
2014
- } else {
2015
- if (file_exists (dirname ($ php ) . "/../../sapi/cgi/php-cgi " )) {
2016
- $ php = realpath (dirname ($ php ) . "/../../sapi/cgi/php-cgi " ) . ' -C ' ;
2017
- } elseif (file_exists ("./sapi/cgi/php-cgi " )) {
2018
- $ php = realpath ("./sapi/cgi/php-cgi " ) . ' -C ' ;
2019
- } elseif (file_exists (dirname ($ php ) . "/php-cgi " )) {
2020
- $ php = realpath (dirname ($ php ) . "/php-cgi " ) . ' -C ' ;
2021
- } else {
2022
- return skip_test ($ tested , $ tested_file , $ shortname , 'CGI not available ' );
2023
- }
1987
+ if (!$ php_cgi ) {
1988
+ return skip_test ($ tested , $ tested_file , $ shortname , 'CGI not available ' );
2024
1989
}
1990
+ $ php = $ php_cgi . ' -C ' ;
1991
+ $ uses_cgi = true ;
2025
1992
if ($ num_repeats > 1 ) {
2026
1993
return skip_test ($ tested , $ tested_file , $ shortname , 'CGI does not support --repeat ' );
2027
1994
}
2028
- $ uses_cgi = true ;
2029
1995
}
2030
1996
2031
1997
/* For phpdbg tests, check if phpdbg sapi is available and if it is, use it. */
0 commit comments