com phpruntests: POST implemented: src/testcase/preconditions/rtIsSectionImplemented.php src/testcase/rtTestConfiguration.php
src/testcase/sections/configurationsections/rtPostSection.php src/testcase/sections/executablesections/rtFileSection.php
src/testcase/sections/rtSection.php tests/testcase/rtPostExecutionTest.php

From: Date: Tue, 28 Apr 2009 20:58:39 +0000
Subject: com phpruntests: POST implemented: src/testcase/preconditions/rtIsSectionImplemented.php src/testcase/rtTestConfiguration.php
src/testcase/sections/configurationsections/rtPostSection.php src/testcase/sections/executablesections/rtFileSection.php
src/testcase/sections/rtSection.php tests/testcase/rtPostExecutionTest.php
Groups: php.qa 
Request: Send a blank email to php-qa+get-66507@lists.php.net to get a copy of this message
Commit: 9748c9cf1df53fccd629d5ceb22975b38e8b3f32 Author: Zoe Slattery <zoe@php.net> Tue, 28 Apr 2009 20:58:39 +0000 Parents: c0a9a390cc896a23088943d73de82839c3663cc0 Branches: master Link: http://git.php.net/?p=phpruntests.git;a=commitdiff;h=9748c9cf1df53fccd629d5ceb22975b38e8b3f32 Log: POST implemented Changed paths: M src/testcase/preconditions/rtIsSectionImplemented.php M src/testcase/rtTestConfiguration.php M src/testcase/sections/configurationsections/rtPostSection.php M src/testcase/sections/executablesections/rtFileSection.php M src/testcase/sections/rtSection.php A tests/testcase/rtPostExecutionTest.php Diff: diff --git a/src/testcase/preconditions/rtIsSectionImplemented.php b/src/testcase/preconditions/rtIsSectionImplemented.php index 96bebc2..eb0e09d 100644 --- a/src/testcase/preconditions/rtIsSectionImplemented.php +++ b/src/testcase/preconditions/rtIsSectionImplemented.php @@ -18,6 +18,7 @@ class rtIsSectionImplemented implements rtTestPreCondition 'CLEAN' => 'rtCleanSection', 'XFAIL' => 'rtXfailSection', 'GET' => 'rtGetSection', + 'POST' => 'rtPostSection' ); /** Return the message associated with an unimplemented test section diff --git a/src/testcase/rtTestConfiguration.php b/src/testcase/rtTestConfiguration.php index 7202faf..1951373 100644 --- a/src/testcase/rtTestConfiguration.php +++ b/src/testcase/rtTestConfiguration.php @@ -66,6 +66,9 @@ class rtTestConfiguration if (array_key_exists('GET', $sections)) { $this->environmentVariables = array_merge($this->environmentVariables, $sections['GET']->getGetVariables()); } + if (array_key_exists('POST', $sections)) { + $this->environmentVariables = array_merge($this->environmentVariables, $sections['POST']->getPostVariables()); + } } diff --git a/src/testcase/sections/configurationsections/rtPostSection.php b/src/testcase/sections/configurationsections/rtPostSection.php index 8d8a443...17218dc 100644 --- a/src/testcase/sections/configurationsections/rtPostSection.php +++ b/src/testcase/sections/configurationsections/rtPostSection.php @@ -18,12 +18,14 @@ class rtPostSection extends rtConfigurationSection private $postFileName; protected function init() - { + { + $postString = implode('\n', $this->sectionContents); $this->postVariables['CONTENT_TYPE'] = 'application/x-www-form-urlencoded'; + $this->postVariables['CONTENT_LENGTH'] = strlen($postString); $this->postVariables['REQUEST_METHOD'] = 'POST'; - $postString = implode('\n', $this->sectionContents); $this->postFileName = tempnam(sys_get_temp_dir(), 'post'); + file_put_contents($this->postFileName, $postString); } diff --git a/src/testcase/sections/executablesections/rtFileSection.php b/src/testcase/sections/executablesections/rtFileSection.php index ad10d91..37c49eb 100644 --- a/src/testcase/sections/executablesections/rtFileSection.php +++ b/src/testcase/sections/executablesections/rtFileSection.php @@ -34,7 +34,7 @@ class rtFileSection extends rtExecutableSection $phpCommand .= ' '. $testCase->testConfiguration->getPhpCommandLineArguments(); $phpCommand .= ' -f '.$this->fileName; $phpCommand .= ' '.$testCase->testConfiguration->getTestCommandLineArguments(); - $phpCommand .= ' '.$testCase->testConfiguration->getInputFileString(); + $phpCommand ..= ' 2>&1 '.$testCase->testConfiguration->getInputFileString(); $PhpRunner = new rtPhpRunner($phpCommand, diff --git a/src/testcase/sections/rtSection.php b/src/testcase/sections/rtSection.php index 37d3a2b..c1714cd 100644 --- a/src/testcase/sections/rtSection.php +++ b/src/testcase/sections/rtSection.php @@ -19,6 +19,7 @@ abstract class rtSection 'CLEAN' => 'rtCleanSection', 'XFAIL' => 'rtXfailSection', 'GET' => 'rtGetSection', + 'POST' => 'rtPostSection', ); protected $sectionName; diff --git a/tests/testcase/rtPostExecutionTest.php b/tests/testcase/rtPostExecutionTest.php new file mode 100644 index 0000000..3259ffb --- /dev/null +++ b/tests/testcase/rtPostExecutionTest.php @@ -0,0 +1,55 @@ +<?php + +require_once 'PHPUnit/Framework.php'; +require_once dirname(__FILE__) . '../../../src/rtAutoload..php'; + +class rtPostExecutionTest extends PHPUnit_Framework_TestCase +{ + private $sample_test; + + 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_post.phpt'; + } + + public function tearDown() + { + @unlink($this->path-to_tests . '/sample_post.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

« previous php.qa (#66507) next »