com phpruntests: fixing cgi check: src/configuration/settings/rtPhpCgiExecutableSetting.php src/testcase/rtPhpTest.php
src/testcase/rtTestConfiguration.php src/testcase/sections/executablesections/rtFileSection.php tests/testcase/rtGetExecutionTest.php

From: Date: Thu, 14 May 2009 11:35:18 +0000
Subject: com phpruntests: fixing cgi check: src/configuration/settings/rtPhpCgiExecutableSetting.php src/testcase/rtPhpTest.php
src/testcase/rtTestConfiguration.php src/testcase/sections/executablesections/rtFileSection.php tests/testcase/rtGetExecutionTest.php
Groups: php.qa 
Request: Send a blank email to php-qa+get-66460@lists.php.net to get a copy of this message
Commit: a259f8dac6536d1e4b35712b83c07ce6a6969704 Author: Zoe Slattery <zoe@php.net> Thu, 14 May 2009 11:35:18 +0000 Parents: b31b3366a54a89f3f1ed1f24326f0cf840f0040d Branches: master Link: http://git.php.net/?p=phpruntests.git;a=commitdiff;h=a259f8dac6536d1e4b35712b83c07ce6a6969704 Log: fixing cgi check Changed paths: M src/configuration/settings/rtPhpCgiExecutableSetting.php M src/testcase/rtPhpTest.php M src/testcase/rtTestConfiguration.php M src/testcase/sections/executablesections/rtFileSection.php M tests/testcase/rtGetExecutionTest.php

diff --git a/src/configuration/settings/rtPhpCgiExecutableSetting.php b/src/configuration/settings/rtPhpCgiExecutableSetting.php index 02665d1..9be4050 100644 --- a/src/configuration/settings/rtPhpCgiExecutableSetting.php +++ b/src/configuration/settings/rtPhpCgiExecutableSetting.php @@ -33,10 +33,12 @@ 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? */ public function guessFromPhpCli($phpCli) { - if(substr(dirname($phpCli),-3) == 'cli') { + if(substr(dirname($phpCli),-3) == 'cli') { $pathLength = strlen(dirname($phpCli)) - 3; $sapiDir = substr(dirname($phpCli), 0, $pathLength); $this->phpCgiExecutable = $sapiDir."cgi/php-cgi"; @@ -57,7 +59,7 @@ class rtPhpCgiExecutableSetting extends rtSetting $rtPhpExecutableSetting = new rtPhpExecutableSetting($this->configuration); $this->guessFromPhpCli($rtPhpExecutableSetting->get()); } - + return $this->phpCgiExecutable; } } diff --git a/src/testcase/rtPhpTest.php b/src/testcase/rtPhpTest.php index bbb8f5b..cbad260 100644 --- a/src/testcase/rtPhpTest.php +++ b/src/testcase/rtPhpTest.php @@ -60,7 +60,7 @@ class rtPhpTest //Identify the file and expect section types $this->fileSection = $this->setFileSection(); $this->expectSection = $this->setExpectSection(); - + $this->fileSection->setExecutableFileName($this->getName()); } @@ -80,8 +80,11 @@ class rtPhpTest if (!array_key_exists('skip', $this->status) && !array_key_exists('bork', $this->status)) { $this->status = array_merge($this->status, $this->fileSection->run($this, $runConfiguration)); - $this->output = $this->fileSection->getOutput(); - $this->compareOutput(); + //The test can be skipped by file sections if the CGI executable is not available + if(!array_key_exists('skip', $this->status)) { + $this->output = $this->fileSection->getOutput(); + $this->compareOutput(); + } if (array_key_exists('CLEAN', $this->sections)) { diff --git a/src/testcase/rtTestConfiguration.php b/src/testcase/rtTestConfiguration.php index 9561a82..a594eab 100644 --- a/src/testcase/rtTestConfiguration.php +++ b/src/testcase/rtTestConfiguration.php @@ -40,7 +40,7 @@ class rtTestConfiguration private function init(rtRuntestsConfiguration $runConfiguration, $sections, $sectionHeadings, $fileSection) { - $this->isCgiTest($sectionHeadings); + $this->setCgiTest($sectionHeadings); $this->setEnvironmentVariables($runConfiguration, $sections, $fileSection); $this->setPhpCommandLineArguments($runConfiguration, $sections); @@ -110,7 +110,11 @@ class rtTestConfiguration private function setPhpExecutable($runConfiguration, $sectionHeadings) { if ($this->cgiTest) { - $this->phpExecutable = $runConfiguration->getSetting('PhpCgiExecutable'). " -C"; + if($runConfiguration->getSetting('PhpCgiExecutable') != null) { + $this->phpExecutable = $runConfiguration->getSetting('PhpCgiExecutable'). " -C"; + } else { + $this->phpExecutable = null; + } } else { $this->phpExecutable = $runConfiguration->getSetting('PhpExecutable'); } @@ -133,7 +137,7 @@ class rtTestConfiguration } } - private function isCgiTest($sectionHeadings) + private function setCgiTest($sectionHeadings) { $tempArray = array_diff($this->cgiSections, $sectionHeadings); if (count($tempArray) < count($this->cgiSections)) { @@ -166,5 +170,10 @@ class rtTestConfiguration { return $this->inputFileString; } + + public function isCgiTest() + { + return $this->cgiTest;; + } } ?> diff --git a/src/testcase/sections/executablesections/rtFileSection.php b/src/testcase/sections/executablesections/rtFileSection.php index 37c49eb..ddd893b 100644 --- a/src/testcase/sections/executablesections/rtFileSection.php +++ b/src/testcase/sections/executablesections/rtFileSection.php @@ -15,7 +15,8 @@ class rtFileSection extends rtExecutableSection { private $twoBlankLines = '\r?\n\r?\n'; - + private $headers; + public function setExecutableFileName($testName) { $this->fileName = $testName.".php"; @@ -44,15 +45,16 @@ class rtFileSection extends rtExecutableSection try { $this->output = $PhpRunner->runphp(); - - //If it's a CGI test sort the headers out here - if(substr($phpExecutable, -2) == '-C') { - + + //If it's a CGI test and separate the headers from the output + if($testCase->testConfiguration->isCgiTest()) { + // Would this be better done with substr/strpos, not sure how to cope with \n + // Do Web servers alsways send \n\r\n\r? I *think* so but need to check + if (preg_match("/^(.*?)$this->twoBlankLines(.*)/s", $this->output, $match)) { $this->output = $match[2]; $this->headers = $match[1]; - } - + } } @@ -62,8 +64,17 @@ class rtFileSection extends rtExecutableSection } else { $this->status['skip'] = 'The CGI executable is unavailable'; } - return $this->status; } + + /** + * + */ + public function getHeaders() + { + return $this->headers; + } + + } ?> diff --git a/tests/testcase/rtGetExecutionTest.php b/tests/testcase/rtGetExecutionTest.php index aad7a04..1f6c72c 100644 --- a/tests/testcase/rtGetExecutionTest.php +++ b/tests/testcase/rtGetExecutionTest.php @@ -24,7 +24,7 @@ class rtGetExecutionTest extends PHPUnit_Framework_TestCase } public function testFileRun() - { + { //Create a new test configuration $config = rtRuntestsConfiguration::getInstance(array('run-tests.php', '-p', $this->php, $this->sample_test)); $config->setEnvironmentVariable('TEST_PHP_CGI_EXECUTABLE',$this->php_cgi); @@ -39,16 +39,47 @@ class rtGetExecutionTest extends PHPUnit_Framework_TestCase $testFile->normaliseLineEndings(); //Create a new test case - $testCase = new rtPhpTest($testFile->getContents(), $testFile->getTestName(), $testFile->getSectionHeadings(), $config); + $testCase = new rtPhpTest($testFile->getContents(), $testFile->getTestName(), $testFile->getSectionHeadings(), $config); //Setup and set the local environment for the test case $testCase->executeTest($config); $output = $testCase->getOutput(); $status = $testCase->getStatus(); - + $this->assertEquals('85', strlen($output)); $this->assertEquals('', $status['pass']); + + + } + + public function testNoCGI() + { + //Create a new test configuration + $config = rtRuntestsConfiguration::getInstance(array('run-tests.php', '-p', $this->php, $this->sample_test)); + $config->configure(); + + //Retrieve the array of test file names + $testFiles = $config->getSetting('TestFiles'); + + //Read the test file + $testFile = new rtPhpTestFile(); + $testFile->doRead($testFiles[0]); + $testFile->normaliseLineEndings(); + + //Create a new test case + $testCase = new rtPhpTest($testFile->getContents(), $testFile->getTestName(), $testFile->getSectionHeadings(), $config); + + //Setup and set the local environment for the test case + $testCase->executeTest($config); + $output = $testCase->getOutput(); + //var_dump($output); + $status = $testCase->getStatus(); + + + $this->assertEquals(0, strlen($output)); + $this->assertEquals('The CGI executable is unavailable', $status['skip']); + } }
« previous php.qa (#66460) next »