g2 Fri May 15 23:11:21 2009 UTC Added files: /phpruntests/tests/testcase/sections/executablesections rtFileExternalSectionTest.php
Modified files: /phpruntests/src/testcase/sections/executablesections rtFileExternalSection.php _rtFileExternalSection.php /phpruntests/src testClassMap.php Log: phpruntests - added test-case for file-external-section
http://cvs.php.net/viewvc.cgi/phpruntests/src/testcase/sections/executablesections/rtFileExternalSection.php?r1=1.1&r2=1.2&diff_format=u Index: phpruntests/src/testcase/sections/executablesections/rtFileExternalSection.php diff -u phpruntests/src/testcase/sections/executablesections/rtFileExternalSection.php:1.1 phpruntests/src/testcase/sections/executablesections/rtFileExternalSection.php:1.2 --- phpruntests/src/testcase/sections/executablesections/rtFileExternalSection.php:1.1 Fri May 15 09:58:21 2009 +++ phpruntests/src/testcase/sections/executablesections/rtFileExternalSection.php Fri May 15 23:11:20 2009 @@ -12,45 +12,114 @@ * @license http://www.php.net/license/3_01.txt PHP License 3.01 * @link http://qa.php.net/ */ -class rtFileExternalSection extends rtFileSection +class rtFileExternalSection extends rtExecutableSection { - + + /** + * @var $twoBlankLines string + */ + private $twoBlankLines = '\r?\n\r?\n'; + + /** + * sets the executable filename + * + * @param $testName string the filename + * @return void + */ + public function setExecutableFileName($testName) + { + $this->fileName = $testName.".php"; + } + + /** + * runs a test-case and returns the status + * + * @param $testCase rtPhpTest + * @param $runConfiguration rtRuntestsConfiguration + * @return $status Array + */ public function run(rtPhpTest $testCase, rtRuntestsConfiguration $runConfiguration) { - if ($this->copyExternalFileContent() === true) { + $this->status = array(); + $this->writeExecutableFile(); - return parent::run($testCase, $runConfiguration); + $this->copyExternalFileContent(); + + $phpExecutable = $testCase->testConfiguration->getPhpExecutable(); + + // The CGI excutable is null if it is not available, check and SKIP if necessary + if (is_null($phpExecutable)) { + $this->status['skip'] = 'The CGI executable is unavailable'; + return $this->status; + } + + $phpCommand = $phpExecutable; + $phpCommand .= ' '. $testCase->testConfiguration->getPhpCommandLineArguments(); + $phpCommand .= ' -f '.$this->fileName; + $phpCommand .= ' '.$testCase->testConfiguration->getTestCommandLineArguments(); + $phpCommand .= ' 2>&1 '.$testCase->testConfiguration->getInputFileString(); + + + $PhpRunner = new rtPhpRunner($phpCommand, + $testCase->testConfiguration->getEnvironmentVariables(), + $runConfiguration->getSetting('WorkingDirectory') + ); + + 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(); } return $this->status; } - - private function copyExternalFileContent() + /** + * @return string + */ + public function getHeaders() { - if (sizeof($this->sectionContents) == 1) { - - $file = $this->sectionContents[0]; - - // don't allow tests to retrieve files from anywhere but this subdirectory - $file = dirname($this->fileName).'/'.trim(str_replace('..', '', $file)); - - if (file_exists($file)) { + return $this->headers; + } + + /** + * checks and copies the content of the external file to the testfile + * + * @return boolean + */ + protected function copyExternalFileContent() + { + if (sizeof($this->sectionContents) != 1) { + + $this->status['fail'] = 'One file per testcase permitted.'; + return false; + } + + $c = $this->sectionContents[0]; + + // don't allow tests to retrieve files from anywhere but this subdirectory + $file = dirname($this->fileName).'/'.trim(str_replace('..', '', $c)); - $this->sectionContents[0] = file_get_contents($file); - return true; + if (!file_exists($file)) { + + $this->status['fail'] = 'Can not open external file '.$file; + return false; + } - } else { - - $this->status['fail'] = 'Can not open external file '.$file; - } - - } else { - - $this->status['fail'] = 'One file per testcase permitted.'; - } - - return false; + $content = file_get_contents($file); + file_put_contents($this->fileName, $content); + return true; } } ?> http://cvs.php.net/viewvc.cgi/phpruntests/src/testcase/sections/executablesections/_rtFileExternalSection.php?r1=1.1&r2=1.2&diff_format=u Index: phpruntests/src/testcase/sections/executablesections/_rtFileExternalSection.php diff -u phpruntests/src/testcase/sections/executablesections/_rtFileExternalSection.php:1.1 phpruntests/src/testcase/sections/executablesections/_rtFileExternalSection.php:1.2 --- phpruntests/src/testcase/sections/executablesections/_rtFileExternalSection.php:1.1 Fri May 15 09:58:21 2009 +++ phpruntests/src/testcase/sections/executablesections/_rtFileExternalSection.php Fri May 15 23:11:20 2009 @@ -3,7 +3,6 @@ * rtFileExternalSection * Executes the code in the --FILE_EXTERNAL-- section * - * * @category Testing * @package RUNTESTS * @author Zoe Slattery <z...@php.net> @@ -13,82 +12,32 @@ * @license http://www.php.net/license/3_01.txt PHP License 3.01 * @link http://qa.php.net/ */ -class rtFileExternalSection extends rtExecutableSection +class rtFileExternalSection extends rtFileSection { - private $twoBlankLines = '\r?\n\r?\n'; - - public function setExecutableFileName($testName) - { - $this->fileName = $testName.".php"; - } public function run(rtPhpTest $testCase, rtRuntestsConfiguration $runConfiguration) { - $this->status = array(); - $this->writeExecutableFile(); - - $this->copyExternalFileContent(); - - $phpExecutable = $testCase->testConfiguration->getPhpExecutable(); - - // The CGI excutable is null if it is not available, check and SKIP if necessary - if ($phpExecutable != null) { - $phpCommand = $phpExecutable; - $phpCommand .= ' '. $testCase->testConfiguration->getPhpCommandLineArguments(); - $phpCommand .= ' -f '.$this->fileName; - $phpCommand .= ' '.$testCase->testConfiguration->getTestCommandLineArguments(); - $phpCommand .= ' 2>&1 '.$testCase->testConfiguration->getInputFileString(); - - - $PhpRunner = new rtPhpRunner($phpCommand, - $testCase->testConfiguration->getEnvironmentVariables(), - $runConfiguration->getSetting('WorkingDirectory') - ); - - 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]; - } - - } + if ($this->copyExternalFileContent() === true) { - - } catch (rtPhpRunnerException $e) { - $this->status['fail'] = $e->getMessage(); - } - } else { - $this->status['skip'] = 'The CGI executable is unavailable'; + return parent::run($testCase, $runConfiguration); } return $this->status; } - - - public function getHeaders() - { - return $this->headers; - } - + private function copyExternalFileContent() { if (sizeof($this->sectionContents) == 1) { - $c = $this->sectionContents[0]; + $file = $this->sectionContents[0]; // don't allow tests to retrieve files from anywhere but this subdirectory - $file = dirname($this->fileName).'/'.trim(str_replace('..', '', $c)); + $file = dirname($this->fileName).'/'.trim(str_replace('..', '', $file)); if (file_exists($file)) { - $content = file_get_contents($file); - file_put_contents($this->fileName, $content); + $this->sectionContents[0] = file_get_contents($file); return true; } else { http://cvs.php.net/viewvc.cgi/phpruntests/src/testClassMap.php?r1=1.3&r2=1.4&diff_format=u Index: phpruntests/src/testClassMap.php diff -u phpruntests/src/testClassMap.php:1.3 phpruntests/src/testClassMap.php:1.4 --- phpruntests/src/testClassMap.php:1.3 Wed May 13 20:13:46 2009 +++ phpruntests/src/testClassMap.php Fri May 15 23:11:20 2009 @@ -57,6 +57,7 @@ 'rtIniSection' => 'testcase/sections/configurationsections/rtIniSection.php', 'rtCleanSection' => 'testcase/sections/executablesections/rtCleanSection.php', 'rtFileSection' => 'testcase/sections/executablesections/rtFileSection.php', + 'rtFileExternalSection' => 'testcase/sections/executablesections/rtFileExternalSection.php', 'rtSkipIfSection' => 'testcase/sections/executablesections/rtSkipIfSection.php', 'rtCreditsSection' => 'testcase/sections/informationsections/rtCreditsSection.php', 'rtTestHeaderSection' => 'testcase/sections/informationsections/rtTestHeaderSection.php', http://cvs.php.net/viewvc.cgi/phpruntests/tests/testcase/sections/executablesections/rtFileExternalSectionTest.php?view=markup&rev=1.1 Index: phpruntests/tests/testcase/sections/executablesections/rtFileExternalSectionTest.php +++ phpruntests/tests/testcase/sections/executablesections/rtFileExternalSectionTest.php <?php require_once 'PHPUnit/Framework.php'; require_once dirname(__FILE__) . '../../../../../src/rtAutoload.php'; class rtFileExternalSectionTest extends PHPUnit_Framework_TestCase { public function testCreateInstance() { $fileSection = new rtFileExternalSection('FILE_EXTERNAL', array('<?php', 'echo "hello world";', '?>')); $code = $fileSection->getContents(); $this->assertEquals('<?php', $code[0]); } public function testTooMuchFiles() { $wrapper = new rtFileExternalSectionTestWrapper('FILE_EXTERNAL', array('file1','file2')); $this->assertFalse($wrapper->copyExternalFileContentTest()); $status = $wrapper->getStatus(); $this->assertEquals('One file per testcase permitted.', $status['fail']); } public function testNotExistingFile() { $wrapper = new rtFileExternalSectionTestWrapper('FILE_EXTERNAL', array('file1')); $this->assertFalse($wrapper->copyExternalFileContentTest()); $status = $wrapper->getStatus(); $this->assertEquals('Can not open external file /file1', $status['fail']); } } /** * test-wrapper to acces protected methods and members */ class rtFileExternalSectionTestWrapper extends rtFileExternalSection { public function copyExternalFileContentTest() { return parent::copyExternalFileContent(); } public function getStatus() { return $this->status; } } ?>
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php