php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #55672
Patch autoguessing-php-executable revision 2011-09-12 12:32 UTC by confik at gmail dot com

Patch autoguessing-php-executable for Testing related Bug #55672

Patch version 2011-09-12 12:32 UTC

Return to Bug #55672 | Download this patch
Patch Revisions:

Developer: confik@gmail.com

Index: run-tests.php
===================================================================
--- run-tests.php	(revision 316514)
+++ run-tests.php	(working copy)
@@ -1,4 +1,4 @@
-#!/usr/bin/php
+#!/usr/bin/php -n
 <?php
 /*
    +----------------------------------------------------------------------+
@@ -143,55 +143,46 @@
   $environment["SystemRoot"] = getenv("SystemRoot");
 }
 
-// Don't ever guess at the PHP executable location.
-// Require the explicit specification.
-// Otherwise we could end up testing the wrong file!
+// Try to guess PHP executable location if env variable is not provided, assume it to be 'auto'.
 
-$php = null;
-$php_cgi = null;
+$php = getenv('TEST_PHP_EXECUTABLE') ? getenv('TEST_PHP_EXECUTABLE') : 'auto';
+$php_cgi = getenv('TEST_PHP_CGI_EXECUTABLE') ? getenv('TEST_PHP_CGI_EXECUTABLE') : 'auto';
 
-if (getenv('TEST_PHP_EXECUTABLE')) {
-	$php = getenv('TEST_PHP_EXECUTABLE');
-
-	if ($php=='auto') {
-		$php = $cwd . '/sapi/cli/php';
-		putenv("TEST_PHP_EXECUTABLE=$php");
-
-		if (!getenv('TEST_PHP_CGI_EXECUTABLE')) {
-			$php_cgi = $cwd . '/sapi/cgi/php-cgi';
-
-			if (file_exists($php_cgi)) {
-				putenv("TEST_PHP_CGI_EXECUTABLE=$php_cgi");
-			} else {
-				$php_cgi = null;
-			}
-		}
+if ($php == 'auto') {
+	$php = realpath($cwd . '/sapi/cli/php');
+	if (!is_file($php)) {
+		$php = realpath(__DIR__ . '/sapi/cli/php');
 	}
-	$environment['TEST_PHP_EXECUTABLE'] = $php;
+	putenv("TEST_PHP_EXECUTABLE=$php");
 }
+$environment['TEST_PHP_EXECUTABLE'] = $php;
 
-if (getenv('TEST_PHP_CGI_EXECUTABLE')) {
-	$php_cgi = getenv('TEST_PHP_CGI_EXECUTABLE');
-
-	if ($php_cgi=='auto') {
-		$php_cgi = $cwd . '/sapi/cgi/php-cgi';
-		putenv("TEST_PHP_CGI_EXECUTABLE=$php_cgi");
+if ($php_cgi == 'auto') {
+	$php_cgi = realpath($cwd . '/sapi/cgi/php-cgi');
+	if (!is_file($php_cgi)) {
+		$php_cgi = realpath(__DIR__ . '/sapi/cgi/php-cgi');
 	}
-
-	$environment['TEST_PHP_CGI_EXECUTABLE'] = $php_cgi;
+	putenv("TEST_PHP_CGI_EXECUTABLE=$php_cgi");
 }
+$environment['TEST_PHP_CGI_EXECUTABLE'] = $php_cgi;
 
 function verify_config()
 {
-	global $php;
+	global $php, $php_cgi;
 
-	if (empty($php) || !file_exists($php)) {
+	if (empty($php) || !is_file($php)) {
 		error('environment variable TEST_PHP_EXECUTABLE must be set to specify PHP executable!');
 	}
 
 	if (function_exists('is_executable') && !is_executable($php)) {
 		error("invalid PHP executable specified by TEST_PHP_EXECUTABLE  = $php");
 	}
+
+	if (!empty($php_cgi)) {
+		if (!is_file($php_cgi) || (function_exists('is_executable') && !is_executable($php_cgi))) {
+			error("invalid PHP-CGI executable specified by TEST_PHP_CGI_EXECUTABLE = $php_cgi");
+		}
+	}
 }
 
 if (getenv('TEST_PHP_LOG_FORMAT')) {
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Dec 27 16:01:29 2024 UTC