com phpruntests: phpruntests - update external-section testcase: src/testcase/sections/executablesections/rtFileExternalSection.php
tests/testcase/sections/executablesections/rtFileExternalSectionTest.php

From: Date: Mon, 18 May 2009 22:38:27 +0000
Subject: com phpruntests: phpruntests - update external-section testcase: src/testcase/sections/executablesections/rtFileExternalSection.php
tests/testcase/sections/executablesections/rtFileExternalSectionTest.php
Groups: php.qa 
Request: Send a blank email to php-qa+get-66442@lists.php.net to get a copy of this message
Commit: d85140fae0ad5bb3cc207dc9c2143a6744544a01 Author: Georg Gradwohl <g2@php.net> Mon, 18 May 2009 22:38:27 +0000 Parents: fda51e9aea0fe863046a4f02a104c335d8b2783f Branches: master Link: http://git.php.net/?p=phpruntests.git;a=commitdiff;h=d85140fae0ad5bb3cc207dc9c2143a6744544a01 Log: phpruntests - update external-section testcase Changed paths: M src/testcase/sections/executablesections/rtFileExternalSection.php M tests/testcase/sections/executablesections/rtFileExternalSectionTest.php Diff: diff --git a/src/testcase/sections/executablesections/rtFileExternalSection.php b/src/testcase/sections/executablesections/rtFileExternalSection.php index af18158..8df5dc7 100644 --- a/src/testcase/sections/executablesections/rtFileExternalSection.php +++ b/src/testcase/sections/executablesections/rtFileExternalSection.php @@ -14,43 +14,41 @@ */ class rtFileExternalSection extends rtFileSection { - + /** + * @param rtPhpTest $testCase + * @param rtRuntestsConfiguration $runConfiguration + * @return Array $status + */ public function run(rtPhpTest $testCase, rtRuntestsConfiguration $runConfiguration) { if ($this->copyExternalFileContent() === true) { - return parent::run($testCase, $runConfiguration); } - return $this->status; } - + /** + * @return boolean + */ private function copyExternalFileContent() { - if (sizeof($this->sectionContents) == 1) { + if (sizeof($this->sectionContents) != 1) { + $this->status['fail'] = 'One file per testcase permitted.'; + return false; + } - $file = $this->sectionContents[0]; - - // don't allow tests to retrieve files from anywhere but this subdirectory - $file = dirname($this->fileName).'/'.trim(str_replace('..', '', $file)); + $file = $this->sectionContents[0]; - if (file_exists($file)) { + // don't allow tests to retrieve files from anywhere but this subdirectory + $file = dirname($this->fileName).'/'.trim(str_replace('..', '', $file)); - $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; + $this->sectionContents[0] = file_get_contents($file); + return true; } public function writeExecutableFile() { diff --git a/tests/testcase/sections/executablesections/rtFileExternalSectionTest.php b/tests/testcase/sections/executablesections/rtFileExternalSectionTest.php index 6663583..b4b41ec 100644 --- a/tests/testcase/sections/executablesections/rtFileExternalSectionTest.php +++ b/tests/testcase/sections/executablesections/rtFileExternalSectionTest.php @@ -7,7 +7,7 @@ class rtFileExternalSectionTest extends PHPUnit_Framework_TestCase { public function testCreateInstance() { - $fileSection = new rtFileExternalSection('FILE_EXTERNAL', array('<?php', 'echo "hello world";', '?>')); + $fileSection = rtFileExternalSection::getInstance('FILE_EXTERNAL', array('<?php', 'echo "hello world";', '?>')); $code = $fileSection->getContents(); $this->assertEquals('<?php', $code[0]); @@ -15,41 +15,25 @@ class rtFileExternalSectionTest extends PHPUnit_Framework_TestCase public function testTooMuchFiles() { - $wrapper = new rtFileExternalSectionTestWrapper('FILE_EXTERNAL', array('file1','file2')); - - $this->assertFalse($wrapper->copyExternalFileContentTest()); - - $status = $wrapper->getStatus(); + $fileSection = rtFileExternalSection::getInstance('FILE_EXTERNAL', array('file1','file2')); + $content = $fileSection->getContents(); + $config = rtRuntestsConfiguration::getInstance(array()); + $test = new rtPhpTest($content, 'TEST', array('FILE_EXTERNAL'), $config); + + $status = $fileSection->run($test, $config); $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(); + $fileSection = rtFileExternalSection::getInstance('FILE_EXTERNAL', array('file1')); + $content = $fileSection->getContents(); + $config = rtRuntestsConfiguration::getInstance(array()); + $test = new rtPhpTest($content, 'TEST', array('FILE_EXTERNAL'), $config); $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; - } -} - ?> \ No newline at end of file

« previous php.qa (#66442) next »