com phpruntests: Changes to enable GET: src/testcase/preconditions/rtIsSectionImplemented.php src/testcase/rtPhpTest.php
src/testcase/rtTestConfiguration.php src/testcase/sections/configurationsections/rtGetSection.php
src/testcase/sections/executablesections/rtFileSection.php src/testcase/sections/rtSection.php tests/testcase/rtGetExecutionTest.php
tests/testcase/rtTestConfigurationTest.php

From: Date: Sun, 26 Apr 2009 22:45:10 +0000
Subject: com phpruntests: Changes to enable GET: src/testcase/preconditions/rtIsSectionImplemented.php src/testcase/rtPhpTest.php
src/testcase/rtTestConfiguration.php src/testcase/sections/configurationsections/rtGetSection.php
src/testcase/sections/executablesections/rtFileSection.php src/testcase/sections/rtSection.php tests/testcase/rtGetExecutionTest.php
tests/testcase/rtTestConfigurationTest.php
Groups: php.qa 
Request: Send a blank email to php-qa+get-66510@lists.php.net to get a copy of this message
Commit: 4a05ec1df3537899120f0dca7e0a97ba3149e976 Author: Zoe Slattery <zoe@php.net> Sun, 26 Apr 2009 22:45:10 +0000 Parents: d8d11112a22f223f1a69a879075ae1716c418098 Branches: master Link: http://git.php.net/?p=phpruntests.git;a=commitdiff;h=4a05ec1df3537899120f0dca7e0a97ba3149e976 Log: Changes to enable GET Changed paths: M src/testcase/preconditions/rtIsSectionImplemented.php M src/testcase/rtPhpTest.php M src/testcase/rtTestConfiguration.php M src/testcase/sections/configurationsections/rtGetSection.php M src/testcase/sections/executablesections/rtFileSection.php M src/testcase/sections/rtSection.php A tests/testcase/rtGetExecutionTest.php M tests/testcase/rtTestConfigurationTest.php

diff --git a/src/testcase/preconditions/rtIsSectionImplemented.php b/src/testcase/preconditions/rtIsSectionImplemented.php index a99acae..96bebc2 100644 --- a/src/testcase/preconditions/rtIsSectionImplemented.php +++ b/src/testcase/preconditions/rtIsSectionImplemented.php @@ -17,6 +17,7 @@ class rtIsSectionImplemented implements rtTestPreCondition 'CREDITS' => 'rtCreditsSection', 'CLEAN' => 'rtCleanSection', 'XFAIL' => 'rtXfailSection', + 'GET' => 'rtGetSection', ); /** Return the message associated with an unimplemented test section diff --git a/src/testcase/rtPhpTest.php b/src/testcase/rtPhpTest.php index 21bf5bf..bbb8f5b 100644 --- a/src/testcase/rtPhpTest.php +++ b/src/testcase/rtPhpTest.php @@ -60,11 +60,13 @@ class rtPhpTest //Identify the file and expect section types $this->fileSection = $this->setFileSection(); $this->expectSection = $this->setExpectSection(); + + $this->fileSection->setExecutableFileName($this->getName()); } public function init(rtRuntestsConfiguration $runConfiguration) { - $this->testConfiguration = new rtTestConfiguration($runConfiguration, $this->sections, $this->sectionHeadings); + $this->testConfiguration = new rtTestConfiguration($runConfiguration, $this->sections, $this->sectionHeadings, $this->fileSection); } //run diff --git a/src/testcase/rtTestConfiguration.php b/src/testcase/rtTestConfiguration.php index 12fef62..a8e322f 100644 --- a/src/testcase/rtTestConfiguration.php +++ b/src/testcase/rtTestConfiguration.php @@ -21,6 +21,7 @@ class rtTestConfiguration private $phpCommandLineArguments; private $testCommandLineArguments; private $phpExecutable; + private $isCgiTest = false; private $cgiSections = array( 'GET', 'POST', @@ -31,20 +32,29 @@ class rtTestConfiguration 'COOKIE', ); - public function __construct(rtRuntestsConfiguration $runConfiguration, $sections, $sectionHeadings) + public function __construct(rtRuntestsConfiguration $runConfiguration, $sections, $sectionHeadings, $fileSection) { - $this->init($runConfiguration, $sections, $sectionHeadings); + $this->init($runConfiguration, $sections, $sectionHeadings, $fileSection); } - private function init(rtRuntestsConfiguration $runConfiguration, $sections, $sectionHeadings) + private function init(rtRuntestsConfiguration $runConfiguration, $sections, $sectionHeadings, $fileSection) { - $this->setEnvironmentVariables($runConfiguration, $sections); + $this->queryCgiTest($sectionHeadings); + + $this->setEnvironmentVariables($runConfiguration, $sections, $fileSection); $this->setPhpCommandLineArguments($runConfiguration, $sections); $this->setTestCommandLineArguments($sections); $this->setPhpExecutable($runConfiguration, $sectionHeadings); + + if($this->isCgiTest) { + $this->environmentVariables['SCRIPT_FILENAME'] = $fileSection->getFileName(); + $this->environmentVariables['PATH_TRANSLATED'] = $fileSection->getFileName(); + //Required by when the cgi has been compiled with force-cgi-redirect. + $this->environmentVariables['REDIRECT_STATUS'] = '1'; + } } - private function setEnvironmentVariables(rtRuntestsConfiguration $runConfiguration, $sections) + private function setEnvironmentVariables(rtRuntestsConfiguration $runConfiguration, $sections, $fileSection) { $this->environmentVariables = $runConfiguration->getEnvironmentVariables(); if (array_key_exists('ENV', $sections)) { @@ -77,14 +87,21 @@ class rtTestConfiguration private function setPhpExecutable($runConfiguration, $sectionHeadings) { - $tempArray = array_diff($this->cgiSections, $sectionHeadings); - if (count($tempArray) < count($this->cgiSections)) { - $this->phpExecutable = $runConfiguration->getSetting('PhpCgiExecutable'); + if ($this->isCgiTest) { + $this->phpExecutable = $runConfiguration->getSetting('PhpCgiExecutable'). " -C"; } else { $this->phpExecutable = $runConfiguration->getSetting('PhpExecutable'); } } + private function queryCgiTest($sectionHeadings) + { + $tempArray = array_diff($this->cgiSections, $sectionHeadings); + if (count($tempArray) < count($this->cgiSections)) { + $this->isCgiTest = true; + } + } + public function getPhpExecutable() { return $this->phpExecutable; @@ -93,6 +110,7 @@ class rtTestConfiguration public function getEnvironmentVariables() { return $this->environmentVariables; + } public function getPhpCommandLineArguments() diff --git a/src/testcase/sections/configurationsections/rtGetSection.php b/src/testcase/sections/configurationsections/rtGetSection.php index fab49ef..69629f7 100644 --- a/src/testcase/sections/configurationsections/rtGetSection.php +++ b/src/testcase/sections/configurationsections/rtGetSection.php @@ -30,6 +30,7 @@ class rtGetSection extends rtConfigurationSection protected function init() { $this->getVariables['QUERY_STRING'] = $this->sectionContents[0]; + $this->getVariables['REQUEST_METHOD'] = 'GET'; } /** diff --git a/src/testcase/sections/executablesections/rtFileSection.php b/src/testcase/sections/executablesections/rtFileSection.php index 93d6f17..943aa82 100644 --- a/src/testcase/sections/executablesections/rtFileSection.php +++ b/src/testcase/sections/executablesections/rtFileSection.php @@ -25,6 +25,8 @@ */ class rtFileSection extends rtExecutableSection { + private $twoBlankLines = '\r?\n\r?\n'; + public function setExecutableFileName($testName) { $this->fileName = $testName.".php"; @@ -33,18 +35,18 @@ class rtFileSection extends rtExecutableSection public function run(rtPhpTest $testCase, rtRuntestsConfiguration $runConfiguration) { $this->status = array(); - - $this->setExecutableFileName($testCase->getName()); $this->writeExecutableFile(); $phpExecutable = $testCase->testConfiguration->getPhpExecutable(); - - // The CGI excutable is null if it is not available, check and SKIP if appropriate + + + // The CGI excutable is null if it is not available, check and SKIP if asubstrppropriate if ($phpExecutable != null) { $phpCommand = $phpExecutable; - $phpCommand .= ' '.$testCase->testConfiguration->getPhpCommandLineArguments(); + $phpCommand .= ' '. $testCase->testConfiguration->getPhpCommandLineArguments(); $phpCommand .= ' -f '.$this->fileName; $phpCommand .= ' '.$testCase->testConfiguration->getTestCommandLineArguments(); + $PhpRunner = new rtPhpRunner($phpCommand, $testCase->testConfiguration->getEnvironmentVariables(), @@ -53,6 +55,18 @@ 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 (preg_match("/^(.*?)$this->twoBlankLines(.*)/s", $this->output, $match)) { + $this->output = $match[2]; + $this->headers = $match[1]; + } + + } + + } catch (rtPhpRunnerException $e) { $this->status['fail'] = $e->getMessage(); } diff --git a/src/testcase/sections/rtSection.php b/src/testcase/sections/rtSection.php index cf2de24..37d3a2b 100644 --- a/src/testcase/sections/rtSection.php +++ b/src/testcase/sections/rtSection.php @@ -18,6 +18,7 @@ abstract class rtSection 'CREDITS' => 'rtCreditsSection', 'CLEAN' => 'rtCleanSection', 'XFAIL' => 'rtXfailSection', + 'GET' => 'rtGetSection', ); protected $sectionName; diff --git a/tests/testcase/rtGetExecutionTest.php b/tests/testcase/rtGetExecutionTest.php new file mode 100644 index 0000000..4c9a5ec --- /dev/null +++ b/tests/testcase/rtGetExecutionTest.php @@ -0,0 +1,57 @@ +<?php + +require_once 'PHPUnit/Framework.php'; +require_once dirname(__FILE__) . '../../../src/rtAutoload.php'; + +class rtGetExecutionTest extends PHPUnit_Framework_TestCase +{ + private $path_to_tests; + private $sample_test; + private $sample_fail; + + public function setUp() + { + $this->php = trim(shell_exec("which php")); + $this->php_cgi = trim(shell_exec("which php-cgi")); + + $this->path_to_tests = realpath(dirname(__FILE__) . '/../../phpt-tests'); + $this->sample_test = $this->path_to_tests . '/sample_get.phpt'; + } + + public function tearDown() + { + @unlink($this->path-to_tests . '/sample_get.php'); + } + + 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); + $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(); + $status = $testCase->getStatus(); + + $this->assertEquals('85', strlen($output)); + $this->assertEquals('', $status['pass']); + + + } +} + +?> +?> \ No newline at end of file diff --git a/tests/testcase/rtTestConfigurationTest.php b/tests/testcase/rtTestConfigurationTest.php index ee8d1ed..974c24d 100644 --- a/tests/testcase/rtTestConfigurationTest.php +++ b/tests/testcase/rtTestConfigurationTest.php @@ -12,6 +12,8 @@ class rtTestConfigurationTest extends PHPUnit_Framework_TestCase $this->sections['ARGS'] = new rtArgsSection('ARGS', array('-vvv -a value -1111 -2 -v')); $this->sections['ENV'] = new rtEnvSection('ENV', array('env1 = ENV1', 'env2=ENV2')); $this->sections['INI'] = new rtIniSection('INI', array('error_reporting=E_ALL | E_STRICT | E_DEPRECATED', 'assert.active = 1')); + $this->sections['FILE'] = new rtFileSection('FILE', array('blah')); + } public function testCreateInstance() @@ -19,7 +21,7 @@ class rtTestConfigurationTest extends PHPUnit_Framework_TestCase $config = rtRuntestsConfiguration::getInstance(array('run-tests.php', '-p', 'a-php-exe', 'test.phpt')); $config->configure(); - $testConfiguration = new rtTestConfiguration($config, $this->sections, array()); + $testConfiguration = new rtTestConfiguration($config, $this->sections, array(),$this->sections['FILE']); $this->assertEquals('rtTestConfiguration', get_class($testConfiguration)); } @@ -29,7 +31,7 @@ class rtTestConfigurationTest extends PHPUnit_Framework_TestCase $config = rtRuntestsConfiguration::getInstance(array('run-tests.php', '-p', 'a-php-exe', 'test.phpt')); $config->configure(); - $testConfiguration = new rtTestConfiguration($config, $this->sections, array()); + $testConfiguration = new rtTestConfiguration($config, $this->sections, array(), $this->sections['FILE']); $envVars = $testConfiguration->getEnvironmentVariables(); @@ -41,7 +43,7 @@ class rtTestConfigurationTest extends PHPUnit_Framework_TestCase $config = rtRuntestsConfiguration::getInstance(array('run-tests.php', '-p', 'a-php-exe', 'test.phpt')); $config->configure(); - $testConfiguration = new rtTestConfiguration($config, $this->sections, array()); + $testConfiguration = new rtTestConfiguration($config, $this->sections, array(),$this->sections['FILE']); $args = $testConfiguration->getTestCommandLineArguments(); @@ -53,7 +55,7 @@ class rtTestConfigurationTest extends PHPUnit_Framework_TestCase $config = rtRuntestsConfiguration::getInstance(array('run-tests.php', '-p', 'a-php-exe', 'test.phpt')); $config->configure(); - $testConfiguration = new rtTestConfiguration($config, $this->sections, array()); + $testConfiguration = new rtTestConfiguration($config, $this->sections, array(),$this->sections['FILE']); $phpargs = $testConfiguration->getPhpCommandLineArguments(); $match = preg_match("/-d \"error_reporting=E_ALL | E_STRICT | E_DEPRECATED\" -d \"assert.active=1\"/", $phpargs); @@ -65,7 +67,7 @@ class rtTestConfigurationTest extends PHPUnit_Framework_TestCase $config = rtRuntestsConfiguration::getInstance(array('run-tests.php', '-p', 'a-php-exe', 'test.phpt')); $config->configure(); - $testConfiguration = new rtTestConfiguration($config, $this->sections, array()); + $testConfiguration = new rtTestConfiguration($config, $this->sections, array(),$this->sections['FILE']); $phpExe = $testConfiguration->getPhpExecutable(); $this->assertEquals('a-php-exe', $phpExe); @@ -78,10 +80,10 @@ class rtTestConfigurationTest extends PHPUnit_Framework_TestCase $config->configure(); - $testConfiguration = new rtTestConfiguration($config, $this->sections, array('GET')); + $testConfiguration = new rtTestConfiguration($config, $this->sections, array('GET'),$this->sections['FILE']); $phpExe = $testConfiguration->getPhpExecutable(); - $this->assertEquals('a-php-cgi-exe', $phpExe); + $this->assertEquals('a-php-cgi-exe -C', $phpExe); } } ?>
« previous php.qa (#66510) next »