com phpruntests: fix to do a better guess at finding the CGI executable: src/configuration/settings/rtPhpCgiExecutableSetting.php
tests/configuration/settings/rtPhpCgiExecutableSettingTest.php tests/testcase/rtGetExecutionTest.php
| From: | David Soria Parra | Date: | Fri, 11 May 2012 08:04:49 +0000 |
| Subject: | com phpruntests: fix to do a better guess at finding the CGI executable: src/configuration/settings/rtPhpCgiExecutableSetting.php tests/configuration/settings/rtPhpCgiExecutableSettingTest.php tests/testcase/rtGetExecutionTest.php |
||
| Groups: | php.qa | ||
| Request: | Send a blank email to php-qa+get-66280@lists.php.net to get a copy of this message | ||
Commit: 48bb681ca2440c4a9c3ba713ed5376c2defb0d6a
Author: Zoe Slattery <zoe@php.net> Fri, 11 May 2012 08:04:49 +0000
Parents: 571e6cb00c85a618df98b9ab1333a1ece0b39bd5
Branches: master
Link: http://git.php.net/?p=phpruntests.git;a=commitdiff;h=48bb681ca2440c4a9c3ba713ed5376c2defb0d6a
Log:
fix to do a better guess at finding the CGI executable
Changed paths:
M src/configuration/settings/rtPhpCgiExecutableSetting.php
M tests/configuration/settings/rtPhpCgiExecutableSettingTest.php
M tests/testcase/rtGetExecutionTest.php
Diff:
diff --git a/src/configuration/settings/rtPhpCgiExecutableSetting.php
b/src/configuration/settings/rtPhpCgiExecutableSetting.php
index db81b0d...2b666d8 100644
--- a/src/configuration/settings/rtPhpCgiExecutableSetting.php
+++ b/src/configuration/settings/rtPhpCgiExecutableSetting.php
@@ -43,17 +43,24 @@ class rtPhpCgiExecutableSetting extends rtSetting
}
/**
- * @todo spriebsch: does this method need to be public, is it only called from get()?
- * @todo zoe:This method only works if we are running from a PHP source tree, do we need to
- * cope with /usr/local/bin/php for example?
+ * If the path tp the php cli executable is either:
+ * something/cli/php
+ * or, failing that,
+ * something/php
+ * we can make a guess at the path to the cgi executable
*/
- public function guessFromPhpCli($phpCli)
+ private function guessFromPhpCli($phpCli)
{
- if(substr(dirname($phpCli),-3) == 'cli') {
- $pathLength = strlen(dirname($phpCli)) - 3;
- $sapiDir = substr(dirname($phpCli), 0, $pathLength);
- $this->phpCgiExecutable = $sapiDir."cgi/php-cgi";
- }
+
+ if(substr($phpCli, -7) === "cli/php") {
+ $cgiGuess = substr($phpCli, 0, -7) . "cgi/php-cgi";
+ }elseif( substr($phpCli, -3) === "php") {
+ $cgiGuess = substr($phpCli, 0, -3) . "php-cgi";
+ }else{
+ $cgiGuess = null;
+ }
+
+ return $cgiGuess;
}
/**
@@ -68,9 +75,10 @@ class rtPhpCgiExecutableSetting extends rtSetting
// We ask rtPhpExecutableSetting for the path to the PHP executable.
$rtPhpExecutableSetting = new rtPhpExecutableSetting($this->configuration);
- $this->guessFromPhpCli($rtPhpExecutableSetting->get());
+ $phpCli=$rtPhpExecutableSetting->get();
+ $this->phpCgiExecutable = $this->guessFromPhpCli($phpCli);
+
}
-
return $this->phpCgiExecutable;
}
}
diff --git a/tests/configuration/settings/rtPhpCgiExecutableSettingTest.php
b/tests/configuration/settings/rtPhpCgiExecutableSettingTest.php
index 77ee774..9a6d428 100644
--- a/tests/configuration/settings/rtPhpCgiExecutableSettingTest.php
+++ b/tests/configuration/settings/rtPhpCgiExecutableSettingTest.php
@@ -27,25 +27,32 @@ class rtPhpCgiExecutableSettingTest extends PHPUnit_Framework_TestCase
$setPhp = $configuration->getSetting('TEST_PHP_EXECUTABLE');
- if (preg_match("/sapi/", $setPhp)) {
- // Make no assertion bacuse the CGI executable can be guesed
+ if (substr($setPhp, -3) === "php") {
+ // Make no assertion because the CGI executable can be guesed
} else {
$this->assertEquals(null, $setting->get());
}
}
public function testSetFromCliExecutableName() {
- $configuration = rtRuntestsConfiguration::getInstance(array('run-tests.php',
'-p', '/a/sapi/cli/php', 'test.phpt'));
+ $configuration = rtRuntestsConfiguration::getInstance(array('run-tests.php',
'-p', '/some/thing/php', 'test.phpt'));
$configuration->setEnvironmentVariable('TEST_PHP_CGI_EXECUTABLE', null);
$setting = new rtPhpCgiExecutableSetting($configuration);
- $this->assertEquals('/a/sapi/cgi/php-cgi', $setting->get());
+ $this->assertEquals('/some/thing/php-cgi', $setting->get());
}
public function testSetFromCli2() {
- $configuration = rtRuntestsConfiguration::getInstance(array('run-tests.php',
'-p', '/a/sapi/cli/php', 'test.phpt'));
+ $configuration = rtRuntestsConfiguration::getInstance(array('run-tests.php',
'-p', '/some/thing/sapi/cli/php', 'test.phpt'));
$setting = new rtPhpCgiExecutableSetting($configuration);
- $this->assertEquals('/a/sapi/cgi/php-cgi', $setting->get());
+ $this->assertEquals('/some/thing/sapi/cgi/php-cgi', $setting->get());
}
+ public function testSetFromCli3() {
+ $configuration = rtRuntestsConfiguration::getInstance(array('run-tests.php',
'-p', '/some/thing/sapi/cli/phpblah', 'test.phpt'));
+ $setting = new rtPhpCgiExecutableSetting($configuration);
+
+ $this->assertEquals(null, $setting->get());
+ }
+
}
?>
diff --git a/tests/testcase/rtGetExecutionTest.php b/tests/testcase/rtGetExecutionTest.php
index 9d5703a..0b24ed7 100644
--- a/tests/testcase/rtGetExecutionTest.php
+++ b/tests/testcase/rtGetExecutionTest.php
@@ -83,7 +83,7 @@ class rtGetExecutionTest extends PHPUnit_Framework_TestCase
$setPhp = $config->getSetting('PhpExecutable');
- if (preg_match("/sapi/", $setPhp)) {
+ if (substr($setPhp, -3) === "php") {
// Make no assertion bacuse the CGI executable can be guesed
} else {
$this->assertEquals(0, strlen($output));