com phpruntests: Reformatted to conform to PEAR coding standard.: src/BuildClassMap.php src/configuration/preconditions/rtIsProcOpenAvailable.php
src/configuration/preconditions/rtIsTestFileSpecified.php src/configuration/rtCommandLineOptions.php src/configuration/rtEnvironmentVariables.php
src/configuration/rtIniAsCommandLineArgs.php src/configuration/rtPreConditionList.php src/configuration/rtRuntestsConfiguration.php
src/configuration/rtSettin
| From: | David Soria Parra | Date: | Fri, 24 Apr 2009 08:41:26 +0000 |
| Subject: | com phpruntests: Reformatted to conform to PEAR coding standard.: src/BuildClassMap.php src/configuration/preconditions/rtIsProcOpenAvailable.php src/configuration/preconditions/rtIsTestFileSpecified.php src/configuration/rtCommandLineOptions.php src/configuration/rtEnvironmentVariables.php src/configuration/rtIniAsCommandLineArgs.php src/configuration/rtPreConditionList.php src/configuration/rtRuntestsConfiguration.php src/configuration/rtSettin |
||
| Groups: | php.qa | ||
| Request: | Send a blank email to php-qa+get-66531@lists.php.net to get a copy of this message | ||
Commit: de34dd9091b4f58941c8d90c82ef0583e167e22f
Author: Stefan Priebsch <spriebsch@php.net> Fri, 24 Apr 2009 08:41:26 +0000
Parents: 4e85fe1e1a3e503eee35a12aef17350cb96d61d6
Branches: master
Link: http://git.php.net/?p=phpruntests.git;a=commitdiff;h=de34dd9091b4f58941c8d90c82ef0583e167e22f
Log:
Reformatted to conform to PEAR coding standard.
Changed paths:
M src/BuildClassMap.php
M src/configuration/preconditions/rtIsProcOpenAvailable.php
M src/configuration/preconditions/rtIsTestFileSpecified.php
M src/configuration/rtCommandLineOptions.php
M src/configuration/rtEnvironmentVariables.php
M src/configuration/rtIniAsCommandLineArgs.php
M src/configuration/rtPreConditionList.php
M src/configuration/rtRuntestsConfiguration.php
M src/configuration/rtSetting.php
M src/configuration/settings/rtPhpCgiExecutableSetting.php
M src/configuration/settings/rtPhpCommandLineArgSetting.php
M src/configuration/settings/rtPhpExecutableSetting..php
M src/configuration/settings/rtTestDirectorySetting.php
M src/configuration/settings/rtTestFileSetting.php
M src/configuration/settings/rtWorkingDirectorySetting.php
M src/configuration/unix/rtUnixConfiguration.php
M src/configuration/unix/rtUnixEnvironmentVariables.php
M src/configuration/unix/rtUnixPreConditionList.php
M src/configuration/unix/rtUnixSettingList.php
M src/configuration/windows/rtWinConfiguration.php
M src/configuration/windows/rtWinEnvironmentVariables.php
M src/configuration/windows/rtWinPreConditionList.php
M src/configuration/windows/rtWinSettingList.php
M src/rtText.php
M src/testcase/exceptions/rtCodeRunnerException.php
M src/testcase/output/rtTestOutputWriterList.php
M src/testcase/output/rtTestOutputWriterXML.php
M src/testcase/preconditions/rtHasMandatorySections.php
M src/testcase/preconditions/rtHasNoDuplicateSections.php
M src/testcase/preconditions/rtIsSectionImplemented.php
M src/testcase/preconditions/rtIsValidSectionName.php
M src/testcase/rtPhpRunner.php
M src/testcase/rtPhpTest.php
M src/testcase/rtPhpTestFile.php
M src/testcase/rtTestConfiguration.php
M src/testcase/rtTestDifference.php
M src/testcase/rtTestOutputWriter.php
M src/testcase/rtTestPreCondition.php
M src/testcase/rtTestResults.php
M src/testcase/sections/configurationsections/rtArgsSection.php
M src/testcase/sections/configurationsections/rtEnvSection.php
M src/testcase/sections/configurationsections/rtIniSection.php
M src/testcase/sections/executablesections/rtCleanSection.php
M src/testcase/sections/executablesections/rtFileSection.php
M src/testcase/sections/executablesections/rtSkipIfSection.php
M src/testcase/sections/informationsections/rtCreditsSection.php
M src/testcase/sections/informationsections/rtTestHeaderSection.php
M src/testcase/sections/informationsections/rtXfailSection.php
M src/testcase/sections/outputsections/rtExpectFSection.php
M src/testcase/sections/outputsections/rtExpectRegexSection.php
M src/testcase/sections/outputsections/rtExpectSection.php
M src/testcase/sections/rtConfigurationSection.php
M src/testcase/sections/rtExecutableSection.php
M src/testcase/sections/rtInformationSection.php
M src/testcase/sections/rtOutputSection.php
M src/testcase/sections/rtSection.php
M src/testgroup/rtPhpTestGroup.php
M src/testrun/rtPhpTestRun.php
diff --git a/src/BuildClassMap.php b/src/BuildClassMap.php index 30e837d..7c6ff42 100644 --- a/src/BuildClassMap.php +++ b/src/BuildClassMap.php @@ -1,5 +1,4 @@ <?php - /* * This is stand alone code to build the file rtClassMap used by rtAutoload to find classes. * It assumes that all classes have the same name at the file name (less .php) and all are prefixed by 'rt' @@ -9,69 +8,70 @@ $map = new BuildClassMap(); $map->buildMap(); -class BuildClassMap { - - public function buildMap() { - - $thisDir = getcwd(); - - $sourceFiles = $this->getSourceList($thisDir); - - $mapString = '<?php'."\n"; - - $mapString .= ' $rtClassMap = array('."\n"; - sort($sourceFiles); - foreach($sourceFiles as $class) { - $relativeLocation = substr($class, strlen($thisDir.'/')); - - $className = basename($class, '.php'); - - $spaces = $this->getSpaces(strlen($className)); - - $mapString .= " ".'\''.$className.'\''. $spaces. " => ".'\''.$relativeLocation.'\','."\n"; - - } - $mapString .= ' );'."\n"; - $mapString .= '?>'."\n"; - - file_put_contents($thisDir.'/rtClassMap.php', $mapString); - - } - - public function getSpaces($length) { - $spaces = ""; - $nspaces = 40 - $length; - for($i=0; $i < $nspaces; $i++) { - $spaces .=" "; - } - return $spaces; - } +class BuildClassMap +{ + public function buildMap() + { + $thisDir = getcwd(); - public function getSourceList($aDirectory) - { - $files = array(); + $sourceFiles = $this->getSourceList($thisDir); - foreach (new PhpFilterIterator(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($aDirectory))) as $item) + $mapString = '<?php'."\n"; + $mapString .= ' $rtClassMap = array('."\n"; + + sort($sourceFiles); + + foreach ($sourceFiles as $class) { + $relativeLocation = substr($class, strlen($thisDir.'/')); + + $className = basename($class, '.php'); + + $spaces = $this->getSpaces(strlen($className)); + + $mapString .= " ".'\''.$className.'\''. $spaces. " => ".'\''.$relativeLocation.'\','."\n"; + } + + $mapString .= ' );'."\n"; + $mapString .= '?>'."\n"; + + file_put_contents($thisDir.'/rtClassMap.php', $mapString); + } + + public function getSpaces($length) { - $files[] = $item->getPathname(); + $spaces = ""; + $nspaces = 40 - $length; + + for ($i=0; $i < $nspaces; $i++) { + $spaces .=" "; + } + + return $spaces; } - return $files; - } + public function getSourceList($aDirectory) + { + $files = array(); -} + foreach (new PhpFilterIterator(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($aDirectory))) as $item) { + $files[] = $item->getPathname(); + } + return $files; + } +} class PhpFilterIterator extends FilterIterator { - public function accept() - { - if(substr($this->current(), -strlen('.php')) == '.php') { - if(substr(basename($this->current()), 0, strlen('rt')) == 'rt') { - return true; - } + public function accept() + { + if (substr($this->current(), -strlen('.php')) == '.php') { + if (substr(basename($this->current()), 0, strlen('rt')) == 'rt') { + return true; + } + } + + return false; } - return false; - } } -?> \ No newline at end of file +?> diff --git a/src/configuration/preconditions/rtIsProcOpenAvailable.php b/src/configuration/preconditions/rtIsProcOpenAvailable.php index 21bc802..ce3556c 100644 --- a/src/configuration/preconditions/rtIsProcOpenAvailable.php +++ b/src/configuration/preconditions/rtIsProcOpenAvailable.php @@ -13,7 +13,7 @@ class rtIsProcOpenAvailable extends rtPreCondition */ public function getMessage() { - return rtText::get('procOpenNotAvailable'); + return rtText::get('procOpenNotAvailable'); } /** @@ -24,7 +24,7 @@ class rtIsProcOpenAvailable extends rtPreCondition public function check(rtCommandLineOptions $commandLine = null, rtEnvironmentVariables $environmentVariables = null) { if (function_exists('proc_open')) { - return true; + return true; } return false; diff --git a/src/configuration/preconditions/rtIsTestFileSpecified.php b/src/configuration/preconditions/rtIsTestFileSpecified.php index bdf79eb..4dfd1e8 100644 --- a/src/configuration/preconditions/rtIsTestFileSpecified.php +++ b/src/configuration/preconditions/rtIsTestFileSpecified.php @@ -1,5 +1,4 @@ <?php - /** * Class for checking that a test file, or directory has been specified * @@ -25,20 +24,20 @@ class rtIsTestFileSpecified extends rtPreCondition */ public function check(rtCommandLineOptions $commandLine = null, rtEnvironmentVariables $environmentVariables = null) { - if($commandLine->hasOption('l')) { - return true; + if ($commandLine->hasOption('l')) { + return true; } - if($commandLine->hasOption('r')) { - return true; + if ($commandLine->hasOption('r')) { + return true; } - if($commandLine->getTestFilename() != null) { - return true; + if ($commandLine->getTestFilename() != null) { + return true; } - if($environmentVariables->hasVariable('TEST_PHP_USER')) { - return true; + if ($environmentVariables->hasVariable('TEST_PHP_USER')) { + return true; } return false; diff --git a/src/configuration/rtCommandLineOptions.php b/src/configuration/rtCommandLineOptions.php index 4a42880..30d699f 100644 --- a/src/configuration/rtCommandLineOptions.php +++ b/src/configuration/rtCommandLineOptions.php @@ -1,11 +1,10 @@ <?php - /** * Parse command line options * - * @package control - * @author Zoe Slattery <zoe.slattery@googlemail.com> - * @license PHP http://www.php.net/license/3_01.txt + * @package control + * @author Zoe Slattery <zoe.slattery@googlemail.com> + * @license PHP http://www.php.net/license/3_01.txt * */ class rtCommandLineOptions @@ -93,35 +92,35 @@ class rtCommandLineOptions */ public function parseCommandLineOptions($argv) { - for ($i=0; $i<count($argv); $i++) { - - if (!$this->isShortOption($argv[$i]) && !$this->isLongOption($argv[$i])) { - $this->testFilename[] = $argv[$i]; - continue; - } - - if ($this->isShortOption($argv[$i])) { - $option = substr($argv[$i], 1); - } else { - $option = substr($argv[$i], 2); - } - - if (!in_array($option, array_merge($this->shortOptions, $this->shortOptionsWithArgs, $this->longOptions, $this->longOptionsWithArgs))) { - throw new rtUnknownOptionException('Unknown option ' . $argv[$i]); - } - - if (in_array($option, array_merge($this->shortOptions, $this->longOptions))) { - $this->options[$option] = true; - continue; + for ($i=0; $i<count($argv); $i++) { + + if (!$this->isShortOption($argv[$i]) && !$this->isLongOption($argv[$i])) { + $this->testFilename[] = $argv[$i]; + continue; + } + + if ($this->isShortOption($argv[$i])) { + $option = substr($argv[$i], 1); + } else { + $option = substr($argv[$i], 2); + } + + if (!in_array($option, array_merge($this->shortOptions, $this->shortOptionsWithArgs, $this->longOptions, $this->longOptionsWithArgs))) { + throw new rtUnknownOptionException('Unknown option ' . $argv[$i]); + } + + if (in_array($option, array_merge($this->shortOptions, $this->longOptions))) { + $this->options[$option] = true; + continue; + } + + if (!$this->isValidOptionArg($argv, $i + 1)) { + throw new rtMissingArgumentException('Missing argument for command line option ' . $argv[$i]); + } + + $i++; + $this->options[$option] = $argv[$i]; } - - if (!$this->isValidOptionArg($argv, $i + 1)) { - throw new rtMissingArgumentException('Missing argument for command line option ' . $argv[$i]); - } - - $i++; - $this->options[$option] = $argv[$i]; - } } @@ -132,10 +131,11 @@ class rtCommandLineOptions */ public function isValidOptionArg($array, $index) { - if (!isset($array[$index])) { - return false; - } - return substr($array[$index], 0, 1) != '-'; + if (!isset($array[$index])) { + return false; + } + + return substr($array[$index], 0, 1) != '-'; } @@ -146,14 +146,15 @@ class rtCommandLineOptions */ protected function stripSpaces($argv) { - $result = array(); + $result = array(); - for ($i=1; $i<count($argv); $i++) { - if ($argv[$i] != "") { - $result[] = $argv[$i]; + for ($i=1; $i<count($argv); $i++) { + if ($argv[$i] != "") { + $result[] = $argv[$i]; + } } - } - return $result; + + return $result; } @@ -162,11 +163,11 @@ class rtCommandLineOptions */ public function getOption($option) { - if (!isset($this->options[$option])) { - return false; - } + if (!isset($this->options[$option])) { + return false; + } - return $this->options[$option]; + return $this->options[$option]; } diff --git a/src/configuration/rtEnvironmentVariables.php b/src/configuration/rtEnvironmentVariables.php index 227ab0a..eec63bd 100644 --- a/src/configuration/rtEnvironmentVariables.php +++ b/src/configuration/rtEnvironmentVariables.php @@ -30,11 +30,11 @@ class rtEnvironmentVariables static public function getInstance ($os = 'Unix') { - if ($os == 'Windows') { - return new rtWinEnvironmentVariables(); - } else { - return new rtUnixEnvironmentVariables(); - } + if ($os == 'Windows') { + return new rtWinEnvironmentVariables(); + } else { + return new rtUnixEnvironmentVariables(); + } } public function getUserSuppliedVariables() @@ -45,8 +45,8 @@ class rtEnvironmentVariables $this->environmentVariables = array(); } - foreach($this->userSuppliedVariables as $variable) { - if(getenv($variable)) { + foreach ($this->userSuppliedVariables as $variable) { + if (getenv($variable)) { $this->environmentVariables[$variable] = getenv($variable); } } diff --git a/src/configuration/rtIniAsCommandLineArgs.php b/src/configuration/rtIniAsCommandLineArgs.php index 1951b6a..5ed38cf 100644 --- a/src/configuration/rtIniAsCommandLineArgs.php +++ b/src/configuration/rtIniAsCommandLineArgs.php @@ -3,31 +3,31 @@ class rtIniAsCommandLineArgs { protected $iniOverwrites = array( - 'output_handler=', - 'open_basedir=', - 'safe_mode=0', - 'disable_functions=', - 'output_buffering=Off', - "error_reporting= 32767", - 'display_errors=1', - 'display_startup_errors=1', - 'log_errors=0', - 'html_errors=0', - 'track_errors=1', - 'report_memleaks=1', - 'report_zend_debug=0', - 'docref_root=', - 'docref_ext=.html', - 'error_prepend_string=', - 'error_append_string=', - 'auto_prepend_file=', - 'auto_append_file=', - 'magic_quotes_runtime=0', - 'ignore_repeated_errors=0', - 'unicode.runtime_encoding=ISO-8859-1', - 'unicode.script_encoding=UTF-8', - 'unicode.output_encoding=UTF-8', - 'unicode.from_error_mode=U_INVALID_SUBSTITUTE', + 'output_handler=', + 'open_basedir=', + 'safe_mode=0', + 'disable_functions=', + 'output_buffering=Off', + "error_reporting= 32767", + 'display_errors=1', + 'display_startup_errors=1', + 'log_errors=0', + 'html_errors=0', + 'track_errors=1', + 'report_memleaks=1', + 'report_zend_debug=0', + 'docref_root=', + 'docref_ext=.html', + 'error_prepend_string=', + 'error_append_string=', + 'auto_prepend_file=', + 'auto_append_file=', + 'magic_quotes_runtime=0', + 'ignore_repeated_errors=0', + 'unicode.runtime_encoding=ISO-8859-1', + 'unicode.script_encoding=UTF-8', + 'unicode.output_encoding=UTF-8', + 'unicode.from_error_mode=U_INVALID_SUBSTITUTE', ); protected $basePhpDArgs; @@ -50,8 +50,8 @@ class rtIniAsCommandLineArgs */ public function settingsToArguments($array, $args="") { - foreach($array as $setting) { - if($this->isValidSetting($setting)) { + foreach ($array as $setting) { + if ($this->isValidSetting($setting)) { $setting = $this->stripSpaces($setting); $args .= " -d \"$setting\""; } else { @@ -78,15 +78,15 @@ class rtIniAsCommandLineArgs } //test for == - if(strncmp($parts[1], '=', 1) === 0) { + if (strncmp($parts[1], '=', 1) === 0) { return false; } //test for a=b=c - if(strstr($parts[1], '=') == false) { - return true; + if (strstr($parts[1], '=') == false) { + return true; } else { - return false; + return false; } } diff --git a/src/configuration/rtPreConditionList.php b/src/configuration/rtPreConditionList.php index 2eab2e7..7e9bd7e 100644 --- a/src/configuration/rtPreConditionList.php +++ b/src/configuration/rtPreConditionList.php @@ -37,10 +37,11 @@ abstract class rtPreConditionList * @param rtEnvironmentVariables $environmentVariables * @return boolean */ - public function check($commandLine, $environmentVariables) { - foreach($this->preConditions as $preCon) { + public function check($commandLine, $environmentVariables) + { + foreach ($this->preConditions as $preCon) { $p = new $preCon; - if(!$p->check($commandLine, $environmentVariables)) { + if (!$p->check($commandLine, $environmentVariables)) { die($p->getMessage()); } } @@ -56,7 +57,7 @@ abstract class rtPreConditionList */ public function hasPreCondition($pc) { - if(in_array($pc, $this->preConditions)) { + if (in_array($pc, $this->preConditions)) { return true; } diff --git a/src/configuration/rtRuntestsConfiguration.php b/src/configuration/rtRuntestsConfiguration.php index 37a5b36..cc58310 100644 --- a/src/configuration/rtRuntestsConfiguration.php +++ b/src/configuration/rtRuntestsConfiguration.php @@ -1,19 +1,18 @@ <?php - /** * Contains onfiguration for test run. Includes: * Command line option, environment variables, ini overrides and settings which are * derived from one or more command line options or environment variables. * */ - abstract class rtRuntestsConfiguration { + protected $commandLineArgs; + private $settings; private $setters; private $environmentVariables; private $commandLine; - protected $commandLineArgs; private $settingNames = array ( 'CurrentDirectory' => 'rtCurrentDirectorySetting', @@ -48,14 +47,12 @@ abstract class rtRuntestsConfiguration $preConditionList = rtPreConditionList::getInstance(); $preConditionList->check($this->commandLine, $this->environmentVariables); - //set configuration - foreach($this->settingNames as $name => $setting) { + foreach ($this->settingNames as $name => $setting) { $this->setters[$name] = new $setting($this); } - - foreach($this->settingNames as $name => $setting) { + foreach ($this->settingNames as $name => $setting) { $methodName = 'set' . $name; $this->$methodName(); } @@ -79,7 +76,8 @@ abstract class rtRuntestsConfiguration * Sets the directory that run-tests was started from * */ - private function setCurrentDirectory() { + private function setCurrentDirectory() + { $this->settings['CurrentDirectory']= $this->setters['CurrentDirectory']->get(); } @@ -87,7 +85,8 @@ abstract class rtRuntestsConfiguration * Sets the directory that run-tests is run from * */ - private function setWorkingDirectory() { + private function setWorkingDirectory() + { $this->settings['WorkingDirectory']= $this->setters['WorkingDirectory']->get(); } @@ -95,7 +94,8 @@ abstract class rtRuntestsConfiguration * Sets the PHP executable being used to run teh tests * */ - private function setPhpExecutable() { + private function setPhpExecutable() + { $this->settings['PhpExecutable']= $this->setters['PhpExecutable']->get(); } @@ -103,7 +103,8 @@ abstract class rtRuntestsConfiguration * Sets the PHP GGI executable being used to run the tests * */ - private function setPhpCgiExecutable() { + private function setPhpCgiExecutable() + { $this->settings['PhpCgiExecutable']= $this->setters['PhpCgiExecutable']->get(); } @@ -111,15 +112,17 @@ abstract class rtRuntestsConfiguration * Sets the log format * */ - private function setLogFormat() { - $this->settings['LogFormat']= $this->setters['LogFormat']->get(); + private function setLogFormat() + { + $this->settings['LogFormat']= $this->setters['LogFormat']->get(); } /** * Sets the command line arguments for PHP * */ - private function setPhpCommandLineArguments() { + private function setPhpCommandLineArguments() + { $this->settings['PhpCommandLineArguments']= $this->setters['PhpCommandLineArguments']->get(); } @@ -127,8 +130,9 @@ abstract class rtRuntestsConfiguration * Sets the names of directories to be tested * */ - private function setTestDirectories() { - $this->settings['TestDirectories'] = $this->setters['TestDirectories']->get(); + private function setTestDirectories() + { + $this->settings['TestDirectories'] = $this->setters['TestDirectories']->get(); } /** @@ -136,11 +140,11 @@ abstract class rtRuntestsConfiguration * * @param array $testFiles */ - private function setTestFiles() { - $this->settings['TestFiles'] = $this->setters['TestFiles']->get(); + private function setTestFiles() + { + $this->settings['TestFiles'] = $this->setters['TestFiles']->get(); } - /** * Returns the value of a setting * @@ -148,39 +152,44 @@ abstract class rtRuntestsConfiguration * @param mixed (may be array or string) */ - public function getSetting($settingName) { - return $this->settings[$settingName]; + public function getSetting($settingName) + { + return $this->settings[$settingName]; } - /** * Returns the entire settings array * * @return array $settings */ - public function getSettings() { - return $this->settings; + public function getSettings() + { + return $this->settings; } - public function getEnvironmentVariable($name) { - return $this->environmentVariables->getVariable($name); + public function getEnvironmentVariable($name) + { + return $this->environmentVariables->getVariable($name); } - public function getEnvironmentVariables() { - return $this->environmentVariables->getVariables(); + public function getEnvironmentVariables() + { + return $this->environmentVariables->getVariables(); } - public function hasCommandLineOption($option) { - return $this->commandLine->hasOption($option); + public function hasCommandLineOption($option) + { + return $this->commandLine->hasOption($option); } - public function getCommandLineOption($option) { - return $this->commandLine->getOption($option); + public function getCommandLineOption($option) + { + return $this->commandLine->getOption($option); } - - public function hasEnvironmentVariable($name) { - return $this->environmentVariables->hasVariable($name); + public function hasEnvironmentVariable($name) + { + return $this->environmentVariables->hasVariable($name); } /** @@ -190,12 +199,14 @@ abstract class rtRuntestsConfiguration * @param unknown_type $value * @return unknown */ - public function setEnvironmentVariable($name, $value) { - $this->environmentVariables->setVariable($name, $value); + public function setEnvironmentVariable($name, $value) + { + $this->environmentVariables->setVariable($name, $value); } - public function getTestFilename() { - return $this->commandLine->getTestFilename(); + public function getTestFilename() + { + return $this->commandLine->getTestFilename(); } } ?> diff --git a/src/configuration/rtSetting.php b/src/configuration/rtSetting.php index 42dc71c..30d10d2 100644 --- a/src/configuration/rtSetting.php +++ b/src/configuration/rtSetting.php @@ -6,7 +6,8 @@ */ abstract class rtSetting { - public function __construct(rtRuntestsConfiguration $configuration) { + public function __construct(rtRuntestsConfiguration $configuration) + { $this->init($configuration); } diff --git a/src/configuration/settings/rtPhpCgiExecutableSetting.php b/src/configuration/settings/rtPhpCgiExecutableSetting.php index 728b95c..47f0912 100644 --- a/src/configuration/settings/rtPhpCgiExecutableSetting.php +++ b/src/configuration/settings/rtPhpCgiExecutableSetting.php @@ -23,7 +23,7 @@ class rtPhpCgiExecutableSetting extends rtSetting } if ($configuration->hasEnvironmentVariable('TEST_PHP_CGI_EXECUTABLE')) { - if($configuration->getEnvironmentVariable('TEST_PHP_CGI_EXECUTABLE') == 'auto') { + if ($configuration->getEnvironmentVariable('TEST_PHP_CGI_EXECUTABLE') == 'auto') { $this->phpCgiExecutable = $workingDir . self::SAPI_CGI; } else { $this->phpCgiExecutable = $configuration->getEnvironmentVariable('TEST_PHP_CGI_EXECUTABLE'); diff --git a/src/configuration/settings/rtPhpCommandLineArgSetting.php b/src/configuration/settings/rtPhpCommandLineArgSetting.php index d502d4d..d5eee8c 100644 --- a/src/configuration/settings/rtPhpCommandLineArgSetting.php +++ b/src/configuration/settings/rtPhpCommandLineArgSetting.php @@ -28,7 +28,8 @@ class rtPhpCommandLineArgSetting extends rtSetting * Supply commandline arguments setting to the run configuration * */ - public function get() { + public function get() + { return $this->phpCommandLineArguments; } } diff --git a/src/configuration/settings/rtPhpExecutableSetting.php b/src/configuration/settings/rtPhpExecutableSetting.php index b24bc30..08beed8 100644 --- a/src/configuration/settings/rtPhpExecutableSetting.php +++ b/src/configuration/settings/rtPhpExecutableSetting.php @@ -24,7 +24,7 @@ class rtPhpExecutableSetting extends rtSetting if ($configuration->hasEnvironmentVariable('TEST_PHP_EXECUTABLE')) { - if($configuration->getEnvironmentVariable('TEST_PHP_EXECUTABLE') == 'auto') { + if ($configuration->getEnvironmentVariable('TEST_PHP_EXECUTABLE') == 'auto') { $this->phpExecutable = $workingDir.self::SAPI_CLI; } else { $this->phpExecutable = $configuration->getEnvironmentVariable('TEST_PHP_EXECUTABLE'); diff --git a/src/configuration/settings/rtTestDirectorySetting.php b/src/configuration/settings/rtTestDirectorySetting.php index 6f572db..97c6deb 100644 --- a/src/configuration/settings/rtTestDirectorySetting.php +++ b/src/configuration/settings/rtTestDirectorySetting.php @@ -20,16 +20,16 @@ class rtTestDirectorySetting extends rtSetting { $fileArray = $configuration->getTestFilename(); - foreach($fileArray as $file) { - if( is_dir($file)) { + foreach ($fileArray as $file) { + if (is_dir($file)) { $this->testDir[]= $file; } } - if($configuration->hasEnvironmentVariable('TEST_PHP_USER')) { + if ($configuration->hasEnvironmentVariable('TEST_PHP_USER')) { $fileArray = trim($configuration->getEnvironmentVariable('TEST_PHP_USER')); - foreach($fileArray as $file) { - if( is_dir($file)) { + foreach ($fileArray as $file) { + if (is_dir($file)) { $this->testDir[]= $file; } } @@ -42,7 +42,7 @@ class rtTestDirectorySetting extends rtSetting */ public function get() { - return $this->testDir; + return $this->testDir; } } ?> diff --git a/src/configuration/settings/rtTestFileSetting.php b/src/configuration/settings/rtTestFileSetting.php index 1146663..08b2ac4 100644 --- a/src/configuration/settings/rtTestFileSetting.php +++ b/src/configuration/settings/rtTestFileSetting.php @@ -16,31 +16,32 @@ class rtTestFileSetting extends rtSetting * @param rtCommandLine $commandLine * */ - public function init(rtRuntestsConfiguration $configuration) { + public function init(rtRuntestsConfiguration $configuration) + { $fileArray = $configuration->getTestFilename(); - foreach($fileArray as $fn) { - if( !is_dir($fn) && substr($fn, -5) == ".phpt") { + foreach ($fileArray as $fn) { + if (!is_dir($fn) && substr($fn, -5) == ".phpt") { $this->testFiles[] = $fn; } } - if($configuration->hasCommandLineOption('l')) { + if ($configuration->hasCommandLineOption('l')) { $fileArray = file($configuration->getCommandLineOption('l')); - foreach($fileArray as $file) { - if(substr(trim($file), -5) == ".phpt") { + foreach ($fileArray as $file) { + if (substr(trim($file), -5) == ".phpt") { $this->testFiles[] = trim($file); } } } - if($configuration->hasCommandLineOption('r')) { - $fileArray = file($configuration->getCommandLineOption('r')); - foreach($fileArray as $file) { - if(substr(trim($file), -5) == ".phpt") { - $this->testFiles[] = trim($file); + if ($configuration->hasCommandLineOption('r')) { + $fileArray = file($configuration->getCommandLineOption('r')); + foreach ($fileArray as $file) { + if (substr(trim($file), -5) == ".phpt") { + $this->testFiles[] = trim($file); + } } - } } } @@ -48,7 +49,8 @@ class rtTestFileSetting extends rtSetting * Reurns a list of test files * */ - public function get() { + public function get() + { return $this->testFiles; } } diff --git a/src/configuration/settings/rtWorkingDirectorySetting.php b/src/configuration/settings/rtWorkingDirectorySetting.php index 2c3408c..a54b2c3 100644 --- a/src/configuration/settings/rtWorkingDirectorySetting.php +++ b/src/configuration/settings/rtWorkingDirectorySetting.php @@ -15,7 +15,7 @@ class rtWorkingDirectorySetting extends rtSetting */ public function init(rtRuntestsConfiguration $configuration) { - if($configuration->hasEnvironmentVariable('TEST_PHP_SRCDIR')) { + if ($configuration->hasEnvironmentVariable('TEST_PHP_SRCDIR')) { $this->workingDirectory = $configuration->getEnvironmentVariable('TEST_PHP_SRCDIR'); } else { $this->workingDirectory = getcwd(); diff --git a/src/configuration/unix/rtUnixConfiguration.php b/src/configuration/unix/rtUnixConfiguration.php index bd97d12..15a9441 100644 --- a/src/configuration/unix/rtUnixConfiguration.php +++ b/src/configuration/unix/rtUnixConfiguration.php @@ -1,16 +1,15 @@ <?php - /** * Class to adapt global environment to Unix * */ - class rtUnixConfiguration extends rtRuntestsConfiguration - { - - public function __construct($cmdlineArgs) { - $this->commandLineArgs = $cmdlineArgs; - $this->init(); - } +class rtUnixConfiguration extends rtRuntestsConfiguration +{ + public function __construct($cmdlineArgs) + { + $this->commandLineArgs = $cmdlineArgs; + $this->init(); + } /** * Adapts the configuration to Unix @@ -19,6 +18,5 @@ protected function adaptConfiguration() { } - } - +} ?> diff --git a/src/configuration/unix/rtUnixEnvironmentVariables.php b/src/configuration/unix/rtUnixEnvironmentVariables.php index 4d660fb..0a15deb 100644 --- a/src/configuration/unix/rtUnixEnvironmentVariables.php +++ b/src/configuration/unix/rtUnixEnvironmentVariables.php @@ -1,20 +1,17 @@ <?php - /** * Class to adapt global environment to Unix * */ - class rtUnixEnvironmentVariables extends rtEnvironmentVariables - { - +class rtUnixEnvironmentVariables extends rtEnvironmentVariables +{ /** * Adapts the global environment to Unix * */ public function adaptEnvironment() { - array_push($this->userSuppliedVariables, 'TEST_PHP_PARALLEL'); + array_push($this->userSuppliedVariables, 'TEST_PHP_PARALLEL'); } - } - -?> \ No newline at end of file +} +?> diff --git a/src/configuration/unix/rtUnixPreConditionList.php b/src/configuration/unix/rtUnixPreConditionList.php index 6ba8b34..a969d4a 100644 --- a/src/configuration/unix/rtUnixPreConditionList.php +++ b/src/configuration/unix/rtUnixPreConditionList.php @@ -1,19 +1,17 @@ <?php - /** * Unix specific pre-condition list * */ -class rtUnixPreConditionList extends rtPreconditionList{ - - - /** - * Adapts the list of pre-conditions to include those that relate to Unix only - * - */ - public function adaptList() { - array_push( $this->preConditions, 'rtIfParallelHasPcntl'); - } +class rtUnixPreConditionList extends rtPreconditionList +{ + /** + * Adapts the list of pre-conditions to include those that relate to Unix only + * + */ + public function adaptList() + { + array_push($this->preConditions, 'rtIfParallelHasPcntl'); + } } - -?> \ No newline at end of file +?> diff --git a/src/configuration/unix/rtUnixSettingList.php b/src/configuration/unix/rtUnixSettingList.php index 04f44b9..b95743f 100644 --- a/src/configuration/unix/rtUnixSettingList.php +++ b/src/configuration/unix/rtUnixSettingList.php @@ -1,18 +1,16 @@ <?php - /** * Unix specific setting list * */ -class rtUnixSettingList extends rtSettingList{ - - - /** - * Adapt the list of settings for things that only need to be set on Unix - * - */ - public function adaptList() { - - } +class rtUnixSettingList extends rtSettingList +{ + /** + * Adapt the list of settings for things that only need to be set on Unix + * + */ + public function adaptList() + { + } } -?> \ No newline at end of file +?> diff --git a/src/configuration/windows/rtWinConfiguration.php b/src/configuration/windows/rtWinConfiguration.php index a2a2006..ed5f27c 100644 --- a/src/configuration/windows/rtWinConfiguration.php +++ b/src/configuration/windows/rtWinConfiguration.php @@ -1,15 +1,16 @@ <?php - /** * Class to adapt global environment to Windows * */ - class rtWinConfiguration extends rtRuntestsConfiguration - { - public function __construct($cmdlineArgs) { - $this->commandLineArgs = $cmdlineArgs; - $this->init(); - } +class rtWinConfiguration extends rtRuntestsConfiguration +{ + public function __construct($cmdlineArgs) + { + $this->commandLineArgs = $cmdlineArgs; + $this->init(); + } + /** * Adapt the environmnet to Windows * @@ -17,6 +18,5 @@ protected function adaptConfiguration() { } - } - +} ?> diff --git a/src/configuration/windows/rtWinEnvironmentVariables.php b/src/configuration/windows/rtWinEnvironmentVariables.php index a44578c..21e8678 100644 --- a/src/configuration/windows/rtWinEnvironmentVariables.php +++ b/src/configuration/windows/rtWinEnvironmentVariables.php @@ -1,20 +1,17 @@ <?php - /** * Class to adapt environment variable list to Windows * */ - class rtWinEnvironmentVariables extends rtEnvironmentVariables - { - +class rtWinEnvironmentVariables extends rtEnvironmentVariables +{ /** * Adapts the environment variables for Windows * */ public function adaptEnvironment() { - array_push($this->userSuppliedVariables, 'SystemRoot'); + array_push($this->userSuppliedVariables, 'SystemRoot'); } - } - -?> \ No newline at end of file +} +?> diff --git a/src/configuration/windows/rtWinPreConditionList.php b/src/configuration/windows/rtWinPreConditionList.php index 19ed2fe..6ef4408 100644 --- a/src/configuration/windows/rtWinPreConditionList.php +++ b/src/configuration/windows/rtWinPreConditionList.php @@ -1,19 +1,16 @@ <?php - /** * Windows specific pre-condition list * */ -class rtWinPreConditionList extends rtPreconditionList{ - - - /** - * Extends list of pre-conditions for those that are specific to Windows - * - */ - public function adaptList() { - - } - +class rtWinPreConditionList extends rtPreconditionList +{ + /** + * Extends list of pre-conditions for those that are specific to Windows + * + */ + public function adaptList() + { + } } -?> \ No newline at end of file +?> diff --git a/src/configuration/windows/rtWinSettingList.php b/src/configuration/windows/rtWinSettingList.php index 762859e..0b641eb 100644 --- a/src/configuration/windows/rtWinSettingList.php +++ b/src/configuration/windows/rtWinSettingList.php @@ -1,20 +1,16 @@ <?php - /** * Windows specific setting list * */ -class rtWinSettingList extends rtSettingList{ - - - /** - * Adapt the list to include things that only need to be set on Windows - * - */ - public function adaptList() { - - } - +class rtWinSettingList extends rtSettingList +{ + /** + * Adapt the list to include things that only need to be set on Windows + * + */ + public function adaptList() + { + } } - -?> \ No newline at end of file +?> diff --git a/src/rtText.php b/src/rtText.php index 3b3cc6a..886b123 100644 --- a/src/rtText.php +++ b/src/rtText.php @@ -1,10 +1,16 @@ <?php /** - * + * rtText reads named texts from texts/ subdirectory. */ class rtText { + /** + * Get a named text from texts/ subdirectory. + * + * @param string $name Text name to return + * @return string + */ public static function get($name) { $filename = dirname(__FILE__) . '/texts/' . $name . '.txt'; diff --git a/src/testcase/exceptions/rtCodeRunnerException.php b/src/testcase/exceptions/rtCodeRunnerException.php index 23fe087..42e90f3 100644 --- a/src/testcase/exceptions/rtCodeRunnerException.php +++ b/src/testcase/exceptions/rtCodeRunnerException.php @@ -1,5 +1,8 @@ <?php -class rtPhpRunnerException extends RunTimeException { - +/** + * + */ +class rtPhpRunnerException extends RunTimeException +{ } -?> \ No newline at end of file +?> diff --git a/src/testcase/output/rtTestOutputWriterList.php b/src/testcase/output/rtTestOutputWriterList.php index f309499..5b0249b 100644 --- a/src/testcase/output/rtTestOutputWriterList.php +++ b/src/testcase/output/rtTestOutputWriterList.php @@ -1,50 +1,50 @@ <?php - - - -class rtTestOutputWriterList extends rtTestOutputWriter { - - protected $testOutput = array(); - - public function __construct(array $testResults) { - $this->init($testResults); - } - - /** - * - * - * @param array of rtTestResults - * - */ - public function init (array $testResults) { - foreach ($testResults as $testResult) { - $outputString = ""; - $testStatus = $testResult->getStatus(); - ksort($testStatus); - //Status can be PASS and WARN or FAIL and WARN. I think these are the olny two combinations - //but there may be more - foreach($testStatus as $status => $message){ - $outputString .= strtoupper($status); - $outputString .= " ". $message; - } - $outputString .= " ". $testResult->getTitle(); - $outputString .= " [". $testResult->getName().".phpt]"; - $this->testOutput[] = $outputString; +/** + * + */ +class rtTestOutputWriterList extends rtTestOutputWriter +{ + protected $testOutput = array(); + + public function __construct(array $testResults) + { + $this->init($testResults); } - } - - public function write($testDirectory = null) { - if($testDirectory != null) { - echo "\n\nTest output for tests in ". $testDirectory."\n"; - } - sort ($this->testOutput); - foreach($this->testOutput as $line) { - echo $line ."\n"; + /** + * + * + * @param array of rtTestResults + * + */ + public function init (array $testResults) + { + foreach ($testResults as $testResult) { + $outputString = ""; + $testStatus = $testResult->getStatus(); + ksort($testStatus); + //Status can be PASS and WARN or FAIL and WARN. I think these are the olny two combinations + //but there may be more + foreach ($testStatus as $status => $message) { + $outputString .= strtoupper($status); + $outputString .= " " . $message; + } + $outputString .= " " . $testResult->getTitle(); + $outputString .= " [" . $testResult->getName() . ".phpt]"; + $this->testOutput[] = $outputString; + } } - } - + public function write($testDirectory = null) + { + if ($testDirectory != null) { + echo "\n\nTest output for tests in " . $testDirectory . "\n"; + } + sort($this->testOutput); + foreach ($this->testOutput as $line) { + echo $line ."\n"; + } + } } -?> \ No newline at end of file +?> diff --git a/src/testcase/output/rtTestOutputWriterXML.php b/src/testcase/output/rtTestOutputWriterXML.php index 4251441..410c9eb 100644 --- a/src/testcase/output/rtTestOutputWriterXML.php +++ b/src/testcase/output/rtTestOutputWriterXML.php @@ -1,20 +1,15 @@ <?php - - -class rtTestOutputWriterXML extends rtTestOutputWriter { - - -public function assemble(rtPhpTest $testCase) { - - - } - - public function write() { - - - - } - - +/** + * + */ +class rtTestOutputWriterXML extends rtTestOutputWriter +{ + public function assemble(rtPhpTest $testCase) + { + } + + public function write() + { + } } -?> \ No newline at end of file +?> diff --git a/src/testcase/preconditions/rtHasMandatorySections.php b/src/testcase/preconditions/rtHasMandatorySections.php index 6b0dcaa..fd05ad9 100644 --- a/src/testcase/preconditions/rtHasMandatorySections.php +++ b/src/testcase/preconditions/rtHasMandatorySections.php @@ -1,33 +1,37 @@ <?php +/** + * + */ +class rtHasMandatorySections implements rtTestPreCondition +{ + /** + * Return the message associated with a missing test section + * + * @return text + */ + public function getMessage() + { + return rtText::get('missingTestSection'); + } -class rtHasMandatorySections implements rtTestPreCondition { - - /** Return the message associated with a missing test section - * - * @return text - */ - public function getMessage() { - return rtText::get('missingTestSection'); - } - - - /** - * Check that the test has valid sections - * - * @param array $testCaseContents - * @return boolean - */ - public function isMet(array $sectionHeadings) { + /** + * Check that the test has valid sections + * + * @param array $testCaseContents + * @return boolean + */ + public function isMet(array $sectionHeadings) + { - if(in_array('TEST', $sectionHeadings )) { - if(in_array('FILE', $sectionHeadings ) || in_array('FILEOF', $sectionHeadings) || in_array('FILE_EXTERNAL', $sectionHeadings)) { - if(in_array('EXPECT', $sectionHeadings ) || in_array('EXPECTF', $sectionHeadings) || in_array('EXPECTREGEX', $sectionHeadings)) { - return true; + if (in_array('TEST', $sectionHeadings )) { + if (in_array('FILE', $sectionHeadings ) || in_array('FILEOF', $sectionHeadings) || in_array('FILE_EXTERNAL', $sectionHeadings)) { + if (in_array('EXPECT', $sectionHeadings ) || in_array('EXPECTF', $sectionHeadings) || in_array('EXPECTREGEX', $sectionHeadings)) { + return true; + } + } } - } - } - return false; - } - + + return false; + } } ?> diff --git a/src/testcase/preconditions/rtHasNoDuplicateSections.php b/src/testcase/preconditions/rtHasNoDuplicateSections.php index 7c5e4ae..78e14df 100644 --- a/src/testcase/preconditions/rtHasNoDuplicateSections.php +++ b/src/testcase/preconditions/rtHasNoDuplicateSections.php @@ -1,30 +1,34 @@ <?php -class rtHasNoDuplicateSections implements rtTestPreCondition { - - - /** Return the message associated with a duplicate test section - * - * @return text - */ - public function getMessage() { - return rtText::get('duplicateTestSection'); - } - +/** + * + */ +class rtHasNoDuplicateSections implements rtTestPreCondition +{ + /** + * Return the message associated with a duplicate test section + * + * @return text + */ + public function getMessage() + { + return rtText::get('duplicateTestSection'); + } - /** - * Check that the PHP executable is a valid executable - * - * @param array $testCaseContents - * @return boolean - */ - public function isMet(array $sectionHeadings) { + /** + * Check that the PHP executable is a valid executable + * + * @param array $testCaseContents + * @return boolean + */ + public function isMet(array $sectionHeadings) + { + $uniqueSections = array_unique($sectionHeadings); + + if (count($uniqueSections) < count($sectionHeadings)) { + return false; + } - $uniqueSections = array_unique($sectionHeadings); - - if (count($uniqueSections) < count($sectionHeadings)) { - return false; + return true; } - return true; - } } -?> \ No newline at end of file +?> diff --git a/src/testcase/preconditions/rtIsSectionImplemented.php b/src/testcase/preconditions/rtIsSectionImplemented.php index 66b3ec6..a99acae 100644 --- a/src/testcase/preconditions/rtIsSectionImplemented.php +++ b/src/testcase/preconditions/rtIsSectionImplemented.php @@ -1,46 +1,47 @@ <?php +/** + * + */ +class rtIsSectionImplemented implements rtTestPreCondition +{ + private $sectionMap = array( + 'TEST' => 'rtTestHeaderSection', + 'SKIPIF' => 'rtSkipIfSection', + 'FILE' => 'rtFileSection', + 'EXPECT' => 'rtExpectSection', + 'EXPECTF' => 'rtExpectFSection', + 'EXPECTREGEX' => 'rtExpectRegexSection', + 'INI' => 'rtIniSection', + 'ARGS' => 'rtArgsSection', + 'ENV' => 'rtEnvSection', + 'CREDITS' => 'rtCreditsSection', + 'CLEAN' => 'rtCleanSection', + 'XFAIL' => 'rtXfailSection', + ); + /** Return the message associated with an unimplemented test section + * + * @return text + */ + public function getMessage() + { + return rtText::get('sectionNotImplemented'); + } -class rtIsSectionImplemented implements rtTestPreCondition { - - private $sectionMap = array ( - 'TEST' => 'rtTestHeaderSection', - 'SKIPIF' => 'rtSkipIfSection', - 'FILE' => 'rtFileSection', - 'EXPECT' => 'rtExpectSection', - 'EXPECTF' => 'rtExpectFSection', - 'EXPECTREGEX' => 'rtExpectRegexSection', - 'INI' => 'rtIniSection', - 'ARGS' => 'rtArgsSection', - 'ENV' => 'rtEnvSection', - 'CREDITS' => 'rtCreditsSection', - 'CLEAN' => 'rtCleanSection', - 'XFAIL' => 'rtXfailSection', - ); - - - /** Return the message associated with an unimplemented test section - * - * @return text - */ - public function getMessage() { - return rtText::get('sectionNotImplemented'); - } - - - /** - * Check that the section has been implemented - * - * @param array $testCaseContents - * @return boolean - */ - public function isMet(array $sectionHeaders) { - foreach($sectionHeaders as $section) { - if(!array_key_exists($section, $this->sectionMap)) { - return false; + /** + * Check that the section has been implemented + * + * @param array $testCaseContents + * @return boolean + */ + public function isMet(array $sectionHeaders) + { + foreach ($sectionHeaders as $section) { + if (!array_key_exists($section, $this->sectionMap)) { + return false; + } } + return true; } - return true; - } } -?> \ No newline at end of file +?> diff --git a/src/testcase/preconditions/rtIsValidSectionName.php b/src/testcase/preconditions/rtIsValidSectionName.php index 75fdd00..2a0ff47 100644 --- a/src/testcase/preconditions/rtIsValidSectionName.php +++ b/src/testcase/preconditions/rtIsValidSectionName.php @@ -1,59 +1,61 @@ <?php +/** + * + */ +class rtIsValidSectionName implements rtTestPreCondition +{ + private $validSectionNames = array( + 'TEST', + 'SKIPIF', + 'FILE', + 'FILEEOF', + 'FILE_EXTERNAL', + 'EXPECT', + 'EXPECTF', + 'EXPECTREGEX', + 'INI', + 'ARGS', + 'ENV', + 'XFAIL', + 'STDIN', + 'CREDITS', + 'CLEAN', + 'POST', + 'GZIP_POST', + 'DEFLATE_POST', + 'POST_RAW', + 'GET', + 'COOKIE', + 'REDIRECTTEST', + 'HEADERS', + 'EXPECTHEADERS', + '===DONE===', + ); + /** + * Return the message associated with a duplicate test section + * + * @return text + */ + public function getMessage() + { + return rtText::get('invalidTestSection'); + } -class rtIsValidSectionName implements rtTestPreCondition { - - - private $validSectionNames = array ( - 'TEST', - 'SKIPIF', - 'FILE', - 'FILEEOF', - 'FILE_EXTERNAL', - 'EXPECT', - 'EXPECTF', - 'EXPECTREGEX', - 'INI', - 'ARGS', - 'ENV', - 'XFAIL', - 'STDIN', - 'CREDITS', - 'CLEAN', - 'POST', - 'GZIP_POST', - 'DEFLATE_POST', - 'POST_RAW', - 'GET', - 'COOKIE', - 'REDIRECTTEST', - 'HEADERS', - 'EXPECTHEADERS', - '===DONE===', - ); - - /** Return the message associated with a duplicate test section - * - * @return text - */ - public function getMessage() { - return rtText::get('invalidTestSection'); - } - - - /** - * Check that the section name is valid - * - * @param array $testCaseContents - * @return boolean - */ - public function isMet(array $sectionHeadings) { - foreach ($sectionHeadings as $section) { - if(!in_array($section, $this->validSectionNames)) { - return false; - } - return true; + /** + * Check that the section name is valid + * + * @param array $testCaseContents + * @return boolean + */ + public function isMet(array $sectionHeadings) + { + foreach ($sectionHeadings as $section) { + if (!in_array($section, $this->validSectionNames)) { + return false; + } + return true; + } } - } } - ?> \ No newline at end of file +?> diff --git a/src/testcase/rtPhpRunner.php b/src/testcase/rtPhpRunner.php index 0d208b5..31575db 100644 --- a/src/testcase/rtPhpRunner.php +++ b/src/testcase/rtPhpRunner.php @@ -1,89 +1,84 @@ <?php - - - /** * Execution of PHP code. * */ -class rtPhpRunner { - - private $phpCommand; - private $environmentVariables; - private $currentWorkingDirectory; - private $stdin; - private $timeOut; - - - public function __construct($phpCommand, $environmentVariables, $currentWorkingDirectory, $stdin = null, $timeOut = 60) { - $this->phpCommand = $phpCommand; - $this->environmentVariables = $environmentVariables; - $this->currentWorkingDirectory = $currentWorkingDirectory; - $this->timeOut = $timeOut; - $this->stdin = $stdin; - } - - - /** - * Runs the PHP code. - * - * @return string - the output from the code - */ - public function runphp() - { - $data = ''; - - $proc = proc_open($this->phpCommand, array( - 0 => array('pipe', 'r'), - 1 => array('pipe', 'w'), - 2 => array('pipe', 'w') - ), $pipes, $this->currentWorkingDirectory, $this->environmentVariables, array('suppress_errors' => true, 'binary_pipes' => true)); - - if (!$proc) { - throw new rtPhpRunnerException('Failed to open process to run PHP code in rtPhpRunner'); +class rtPhpRunner +{ + private $phpCommand; + private $environmentVariables; + private $currentWorkingDirectory; + private $stdin; + private $timeOut; + + public function __construct($phpCommand, $environmentVariables, $currentWorkingDirectory, $stdin = null, $timeOut = 60) + { + $this->phpCommand = $phpCommand; + $this->environmentVariables = $environmentVariables; + $this->currentWorkingDirectory = $currentWorkingDirectory; + $this->timeOut = $timeOut; + $this->stdin = $stdin; } - if (!is_null($this->stdin)) { - fwrite($pipes[0], (binary) $this->stdin); - } - fclose($pipes[0]); - - while (true) { - /* hide errors from interrupted syscalls */ - $r = $pipes; - $w = null; - $e = null; - - $n = @stream_select($r, $w, $e, $this->timeOut); + /** + * Runs the PHP code. + * + * @return string - the output from the code + */ + public function runphp() + { + $data = ''; + + $proc = proc_open( + $this->phpCommand, + array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'), 2 => array('pipe', 'w')), + $pipes, + $this->currentWorkingDirectory, + $this->environmentVariables, + array('suppress_errors' => true, 'binary_pipes' => true) + ); + + if (!$proc) { + throw new rtPhpRunnerException('Failed to open process to run PHP code in rtPhpRunner'); + } - if ($n === false) { - - throw new rtPhpRunnerException('Stream select failure in rtPhpRunner'); + if (!is_null($this->stdin)) { + fwrite($pipes[0], (binary) $this->stdin); + } - } else if ($n === 0) { - - proc_terminate($proc); - throw new rtPhpRunnerException ('The process running test code has timed out in rtPhpRunner'); + fclose($pipes[0]); + + while (true) { + /* hide errors from interrupted syscalls */ + $r = $pipes; + $w = null; + $e = null; + + $n = @stream_select($r, $w, $e, $this->timeOut); + + if ($n === false) { + throw new rtPhpRunnerException('Stream select failure in rtPhpRunner'); + } else if ($n === 0) { + proc_terminate($proc); + throw new rtPhpRunnerException ('The process running test code has timed out in rtPhpRunner'); + } else if ($n > 0) { + $line = fread($pipes[1], 8192); + if (strlen($line) == 0) { + /* EOF */ + break; + } + $data .= (binary) $line; + } + } - } else if ($n > 0) { - $line = fread($pipes[1], 8192); - if (strlen($line) == 0) { - /* EOF */ - break; + /* check the process status. Note that this will always be FALSE on windows */ + $stat = proc_get_status($proc); + if ($stat['signaled']) { + throw new rtPhpRunnerException('The process was terminated by uncaught signal number in rtPhpRunners'); } - $data .= (binary) $line; - } - } - /* check the process status. Note that this will always be FALSE on windows */ - $stat = proc_get_status($proc); - if ($stat['signaled']) { - throw new rtPhpRunnerException('The process was terminated by uncaught signal number in rtPhpRunners'); + $code = proc_close($proc); + return $data; } - - $code = proc_close($proc); - return $data; - } } - ?> diff --git a/src/testcase/rtPhpTest.php b/src/testcase/rtPhpTest.php index d0d2762..3ddba9f 100644 --- a/src/testcase/rtPhpTest.php +++ b/src/testcase/rtPhpTest.php @@ -1,164 +1,167 @@ <?php - - -class rtPhpTest { - - private $testName; - public $testConfiguration; - private $contents; - private $status; - private $output; - private $sections; - private $fileSection; - private $expectSection; - private $sectionHeadings; - - - public function __construct(array $contents, $testName, $sectionHeadings, $runConfiguration) { - $this->contents = $contents; - $this->testName = $testName; - $this->sectionHeadings = $sectionHeadings; - $this->parse(); - $this->init($runConfiguration); - } - - public function parse() { - - for ($i=0; $i<count($this->contents); $i++) { - //Create an array of section objects - if($this->isSectionKey($this->contents[$i])) { - $sectionKey = $this->contents[$i]; - - $tempArray = array(); - for($j=$i+1; $j<count($this->contents); $j++) { - - if ($this->isSectionKey($this->contents[$j])) { - $testSection = rtSection::getInstance($sectionKey, $tempArray); - $this->sections[$sectionKey] = $testSection; - break; - } - $tempArray[] = $this->contents[$j]; - } - } +/** + * + */ +class rtPhpTest +{ + public $testConfiguration; + + private $testName; + private $contents; + private $status; + private $output; + private $sections; + private $fileSection; + private $expectSection; + private $sectionHeadings; + + public function __construct(array $contents, $testName, $sectionHeadings, $runConfiguration) + { + $this->contents = $contents; + $this->testName = $testName; + $this->sectionHeadings = $sectionHeadings; + $this->parse(); + $this->init($runConfiguration); } - $testSection = rtSection::getInstance($sectionKey, $tempArray); - $this->sections[$sectionKey] = $testSection; - - //Identify the file and expect section types - $this->fileSection = $this->setFileSection(); - $this->expectSection = $this->setExpectSection(); + public function parse() + { + for ($i=0; $i<count($this->contents); $i++) { + //Create an array of section objects + if ($this->isSectionKey($this->contents[$i])) { + $sectionKey = $this->contents[$i]; + + $tempArray = array(); + for ($j=$i+1; $j<count($this->contents); $j++) { + + if ($this->isSectionKey($this->contents[$j])) { + $testSection = rtSection::getInstance($sectionKey, $tempArray); + $this->sections[$sectionKey] = $testSection; + break; + } + $tempArray[] = $this->contents[$j]; + } + } + } - } + $testSection = rtSection::getInstance($sectionKey, $tempArray); + $this->sections[$sectionKey] = $testSection; + //Identify the file and expect section types + $this->fileSection = $this->setFileSection(); + $this->expectSection = $this->setExpectSection(); + } - public function init(rtRuntestsConfiguration $runConfiguration) { - $this->testConfiguration = new rtTestConfiguration($runConfiguration, $this->sections); - } + public function init(rtRuntestsConfiguration $runConfiguration) + { + $this->testConfiguration = new rtTestConfiguration($runConfiguration, $this->sections); + } + //run + public function executeTest(rtRuntestsConfiguration $runConfiguration) + { + $this->status = array(); - //run - public function executeTest(rtRuntestsConfiguration $runConfiguration) { + if (array_key_exists('SKIPIF', $this->sections)) { + $this->status = $this->sections['SKIPIF']->run($this, $runConfiguration); + } - $this->status = array(); + 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(); + - if(array_key_exists('SKIPIF', $this->sections)) { - $this->status = $this->sections['SKIPIF']->run($this, $runConfiguration); + if (array_key_exists('CLEAN', $this->sections)) { + $cleanStatus = $this->sections['CLEAN']->run($this, $runConfiguration); + $this->status = array_merge($this->status, $cleanStatus); + } + } } - 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(); - + public function compareOutput() + { + $result = $this->expectSection->compare($this->output); - if(array_key_exists('CLEAN', $this->sections)) { - $cleanStatus = $this->sections['CLEAN']->run($this, $runConfiguration); - $this->status = array_merge($this->status, $cleanStatus); - } + if ($result) { + $this->status['pass'] = ''; + } else { + $this->status['fail'] = ''; + } + } + private function isSectionKey($line) + { + if (in_array($line, $this->sectionHeadings)) { + return true; + } + return false; } - } - public function compareOutput() { + private function setFileSection() + { + if (array_key_exists('FILE', $this->sections)) { + return $this->sections['FILE']; + } - $result = $this->expectSection->compare($this->output); + if (array_key_exists('FILEEOF', $this->sections)) { + return $this->sections['FILEEOF']; + } - if($result) { - $this->status['pass'] = ''; - } else { - $this->status['fail'] = ''; + if (array_key_exists('FILE_EXTERNAL', $this->sections)) { + return $this->sections['FILE_EXTERNAL']; + } } - } - private function isSectionKey($line) { - if(in_array($line, $this->sectionHeadings)) { - return true; - } - return false; - } + private function setExpectSection() + { + if (array_key_exists('EXPECT', $this->sections)) { + return $this->sections['EXPECT']; + } + if (array_key_exists('EXPECTF', $this->sections)) { + return $this->sections['EXPECTF']; + } - private function setFileSection() { - if(array_key_exists('FILE', $this->sections)) { - return $this->sections['FILE']; + if (array_key_exists('EXPECTREGEX', $this->sections)) { + return $this->sections['EXPECTREGEX']; + } } - if(array_key_exists('FILEEOF', $this->sections)) { - return $this->sections['FILEEOF']; + public function getName() + { + return $this->testName; } - if(array_key_exists('FILE_EXTERNAL', $this->sections)) { - return $this->sections['FILE_EXTERNAL']; + public function getOutput() + { + return $this->output; } - } - private function setExpectSection() { - if(array_key_exists('EXPECT', $this->sections)) { - return $this->sections['EXPECT']; + public function hasSection($sectionKey) + { + return array_key_exists($sectionKey, $this->sections); } - if(array_key_exists('EXPECTF', $this->sections)) { - return $this->sections['EXPECTF']; + public function getSection($sectionKey) + { + return $this->sections[$sectionKey]; } - if(array_key_exists('EXPECTREGEX', $this->sections)) { - return $this->sections['EXPECTREGEX']; + public function getStatus() + { + return $this->status; } - } - - - - public function getName() { - return $this->testName; - } - - public function getOutput() { - return $this->output; - } - - public function hasSection($sectionKey) { - return array_key_exists($sectionKey, $this->sections); - } - - public function getSection($sectionKey) { - return $this->sections[$sectionKey]; - } - - public function getStatus() { - return $this->status; - } - - public function getFileSection() { - return $this->fileSection; - } - - public function getExpectSection() { - return $this->expectSection; - } - + public function getFileSection() + { + return $this->fileSection; + } + public function getExpectSection() + { + return $this->expectSection; + } } ?> diff --git a/src/testcase/rtPhpTestFile.php b/src/testcase/rtPhpTestFile.php index e293669..c7da798 100644 --- a/src/testcase/rtPhpTestFile.php +++ b/src/testcase/rtPhpTestFile.php @@ -1,88 +1,89 @@ <?php - /** * Class to deal with all file system operations for a test case * */ -class rtPhpTestFile { - - private $fileName; - private $testName; - private $testContents; - private $testExitMessage; - private $sectionHeadings = array(); - - - private $carriageReturn = "\r"; - private $newLine = "\n"; - - - private $preConditions = array ( - 'rtHasMandatorySections', - 'rtHasNoDuplicateSections', - 'rtIsValidSectionName', - 'rtIsSectionImplemented' - ); - - - /** - * Reads the contents of the test file and creates an array of the contents. - * - * @param string $testFile (file name) - */ - public function doRead($testFile) { +class rtPhpTestFile +{ + private $fileName; + private $testName; + private $testContents; + private $testExitMessage; + private $sectionHeadings = array(); + + private $carriageReturn = "\r"; + private $newLine = "\n"; + + private $preConditions = array ( + 'rtHasMandatorySections', + 'rtHasNoDuplicateSections', + 'rtIsValidSectionName', + 'rtIsSectionImplemented' + ); + + /** + * Reads the contents of the test file and creates an array of the contents. + * + * @param string $testFile (file name) + */ + public function doRead($testFile) + { $this->testFileName = realpath($testFile); $this->testName= dirname($this->testFileName).DIRECTORY_SEPARATOR.basename($this->testFileName, ".phpt"); $this->testContents = file($this->testFileName); - } - - public function normaliseLineEndings() { - - for($i=0; $i<count($this->testContents); $i++) { - //This is not nice but there are a huge number of tests with random spacs at the end of the section header - if(preg_match("/--([A-Z]+(_[A-Z]+|))--/", $this->testContents[$i], $matches)) { - $this->sectionHeadings[] = $matches[1]; - $this->testContents[$i] = $matches[1]; - } else { - $this->testContents[$i] = rtrim($this->testContents[$i], $this->carriageReturn.$this->newLine); - } + } + + public function normaliseLineEndings() + { + for ($i=0; $i<count($this->testContents); $i++) { + //This is not nice but there are a huge number of tests with random spacs at the end of the section header + if (preg_match("/--([A-Z]+(_[A-Z]+|))--/", $this->testContents[$i], $matches)) { + $this->sectionHeadings[] = $matches[1]; + $this->testContents[$i] = $matches[1]; + } else { + $this->testContents[$i] = rtrim($this->testContents[$i], $this->carriageReturn.$this->newLine); + } } - } - - public function arePreConditionsMet() { - foreach($this->preConditions as $preCondition) { - $condition = new $preCondition; - if(!$condition->isMet($this->sectionHeadings)) { - $this->testExitMessage = $condition->getMessage(); - return false; - } + } + + public function arePreConditionsMet() + { + foreach ($this->preConditions as $preCondition) { + $condition = new $preCondition; + if (!$condition->isMet($this->sectionHeadings)) { + $this->testExitMessage = $condition->getMessage(); + return false; + } } return true; - } + } - public function getContents() { + public function getContents() + { return $this->testContents; - } - - public function getSectionHeadings() { + } + + public function getSectionHeadings() + { return $this->sectionHeadings; - } + } - public function getTestName() { + public function getTestName() + { return $this->testName; - } + } - public function getTestFileName() { + public function getTestFileName() + { return $this->testFileName; - } + } - public function getExitMessage() { + public function getExitMessage() + { return $this->testExitMessage; - } - - + } } -?> \ No newline at end of file +?> diff --git a/src/testcase/rtTestConfiguration.php b/src/testcase/rtTestConfiguration.php index 76e7414..5c3ea35 100644 --- a/src/testcase/rtTestConfiguration.php +++ b/src/testcase/rtTestConfiguration.php @@ -4,57 +4,64 @@ * 1. RuntestsConfiguration * 2. Sections which modify the Runtests configuration */ +class rtTestConfiguration +{ + private $environmentVariables; + private $phpCommandLineArguments; + private $testCommandLineArguments; -class rtTestConfiguration { - - private $environmentVariables; - private $phpCommandLineArguments; - private $testCommandLineArguments; - - public function __construct(rtRuntestsConfiguration $runConfiguration, $sections) { - $this->init($runConfiguration, $sections); - } - - private function init(rtRuntestsConfiguration $runConfiguration, $sections) { - $this->setEnvironmentVariables($runConfiguration, $sections); - $this->setPhpCommandLineArguments($runConfiguration, $sections); - $this->setTestCommandLineArguments($sections); - } - - private function setEnvironmentVariables(rtRuntestsConfiguration $runConfiguration, $sections) { - $this->environmentVariables = $runConfiguration->getEnvironmentVariables(); - if(array_key_exists('ENV', $sections)) { - $this->environmentVariables = array_merge($this->environmentVariables, $sections['ENV']->getTestEnvironmentVariables()); - } - } - - private function setPhpCommandLineArguments(rtRuntestsConfiguration $runConfiguration, $sections) { - $this->phpCommandLineArguments = $runConfiguration->getSetting('PhpCommandLineArguments'); - if(array_key_exists('INI', $sections)) { - $additionalArguments = $sections['INI']->getCommandLineArguments(); - $args = new rtIniAsCommandLineArgs(); - $this->phpCommandLineArguments = $args->settingsToArguments($additionalArguments, $this->phpCommandLineArguments); - } - } - - private function setTestCommandLineArguments($sections) { - $this->testCommandLineArguments = ''; - if(array_key_exists('ARGS', $sections)) { - $this->testCommandLineArguments = $sections['ARGS']->getTestCommandLineArguments(); - } - } - - public function getEnvironmentVariables() { - return $this->environmentVariables; - } - - public function getPhpCommandLineArguments() { - return $this->phpCommandLineArguments; - } - - public function getTestCommandLineArguments() { - return $this->testCommandLineArguments; - } - + public function __construct(rtRuntestsConfiguration $runConfiguration, $sections) + { + $this->init($runConfiguration, $sections); + } + + private function init(rtRuntestsConfiguration $runConfiguration, $sections) + { + $this->setEnvironmentVariables($runConfiguration, $sections); + $this->setPhpCommandLineArguments($runConfiguration, $sections); + $this->setTestCommandLineArguments($sections); + } + + private function setEnvironmentVariables(rtRuntestsConfiguration $runConfiguration, $sections) + { + $this->environmentVariables = $runConfiguration->getEnvironmentVariables(); + if (array_key_exists('ENV', $sections)) { + $this->environmentVariables = array_merge($this->environmentVariables, $sections['ENV']->getTestEnvironmentVariables()); + } + } + + private function setPhpCommandLineArguments(rtRuntestsConfiguration $runConfiguration, $sections) + { + $this->phpCommandLineArguments = $runConfiguration->getSetting('PhpCommandLineArguments'); + if (array_key_exists('INI', $sections)) { + $additionalArguments = $sections['INI']->getCommandLineArguments(); + $args = new rtIniAsCommandLineArgs(); + $this->phpCommandLineArguments = $args->settingsToArguments($additionalArguments, $this->phpCommandLineArguments); + } + } + + private function setTestCommandLineArguments($sections) + { + $this->testCommandLineArguments = ''; + + if (array_key_exists('ARGS', $sections)) { + $this->testCommandLineArguments = $sections['ARGS']->getTestCommandLineArguments(); + } + } + + public function getEnvironmentVariables() + { + return $this->environmentVariables; + } + + public function getPhpCommandLineArguments() + { + return $this->phpCommandLineArguments; + } + + public function getTestCommandLineArguments() + { + return $this->testCommandLineArguments; + } } -?> \ No newline at end of file +?> diff --git a/src/testcase/rtTestDifference.php b/src/testcase/rtTestDifference.php index 60d3bbd..975fb4b 100644 --- a/src/testcase/rtTestDifference.php +++ b/src/testcase/rtTestDifference.php @@ -1,190 +1,188 @@ <?php - /** * Calculates the difference between the expected and actual output * */ -class rtTestDifference { - - private $difference; - private $expectedOutput; - private $output; - private $expectedRegularExpression; - - public function __construct(rtOutputSection $expectedOutput, $output) { - $this->expectedOutput = $expectedOutput->getContents(); - $this->expectedRegularExpression = explode(b"\n",$expectedOutput->getPattern()); - $this->output = explode(b"\n", $output); - - $this->generateDiff(); - } - - public function generateDiff() { - $this->difference = $this->generateArrayDiff($this->expectedRegularExpression, $this->output, true, $this->expectedOutput); - } - - - /** - * Return the difference - * - * @return array - */ - public function getDifference() { - return $this->difference; - } - - - /** - * Unmodified from the original run-tests.php - * - * @param array $ar1 - * @param array $ar2 - * @param boolean $is_reg - * @param array $w - * @return array - */ - public function generateArrayDiff($ar1, $ar2, $is_reg, $w) { - - $idx1 = 0; $ofs1 = 0; $cnt1 = @count($ar1); - $idx2 = 0; $ofs2 = 0; $cnt2 = @count($ar2); - $diff = array(); - $old1 = array(); - $old2 = array(); - - while ($idx1 < $cnt1 && $idx2 < $cnt2) { - - if ($this->compLine($ar1[$idx1], $ar2[$idx2], $is_reg)) { - $idx1++; - $idx2++; - continue; - } else { - - $c1 = @$this->countArrayDiff($ar1, $ar2, $is_reg, $w, $idx1+1, $idx2, $cnt1, $cnt2, 10); - $c2 = @$this->countArrayDiff($ar1, $ar2, $is_reg, $w, $idx1, $idx2+1, $cnt1, $cnt2, 10); - - if ($c1 > $c2) { - $old1[$idx1] = (binary) sprintf("%03d- ", $idx1+1) . $w[$idx1++]; - $last = 1; - } else if ($c2 > 0) { - $old2[$idx2] = (binary) sprintf("%03d+ ", $idx2+1) . $ar2[$idx2++]; - $last = 2; - } else { - $old1[$idx1] = (binary) sprintf("%03d- ", $idx1+1) . $w[$idx1++]; - $old2[$idx2] = (binary) sprintf("%03d+ ", $idx2+1) . $ar2[$idx2++]; - } - } - } - - reset($old1); $k1 = key($old1); $l1 = -2; - reset($old2); $k2 = key($old2); $l2 = -2; - - while ($k1 !== null || $k2 !== null) { - - if ($k1 == $l1 + 1 || $k2 === null) { - $l1 = $k1; - $diff[] = current($old1); - $k1 = next($old1) ? key($old1) : null; - } else if ($k2 == $l2 + 1 || $k1 === null) { - $l2 = $k2; - $diff[] = current($old2); - $k2 = next($old2) ? key($old2) : null; - } else if ($k1 < $k2) { - $l1 = $k1; - $diff[] = current($old1); - $k1 = next($old1) ? key($old1) : null; - } else { - $l2 = $k2; - $diff[] = current($old2); - $k2 = next($old2) ? key($old2) : null; - } - } - - while ($idx1 < $cnt1) { - $diff[] = (binary) sprintf("%03d- ", $idx1 + 1) . $w[$idx1++]; +class rtTestDifference +{ + private $difference; + private $expectedOutput; + private $output; + private $expectedRegularExpression; + + public function __construct(rtOutputSection $expectedOutput, $output) + { + $this->expectedOutput = $expectedOutput->getContents(); + $this->expectedRegularExpression = explode(b"\n", $expectedOutput->getPattern()); + $this->output = explode(b"\n", $output); + + $this->generateDiff(); } - while ($idx2 < $cnt2) { - $diff[] = (binary) sprintf("%03d+ ", $idx2 + 1) . $ar2[$idx2++]; + public function generateDiff() + { + $this->difference = $this->generateArrayDiff($this->expectedRegularExpression, $this->output, true, $this->expectedOutput); } - return $diff; - } - - - /** - * Unmodified from the original version of runt-tests.php - * - * @param array $ar1 - * @param array $ar2 - * @param boolean $is_reg - * @param array $w - * @param int $idx1 - * @param int $idx2 - * @param int $cnt1 - * @param int $cnt2 - * @param int $steps - * @return unknown - */ - public function countArrayDiff($ar1, $ar2, $is_reg, $w, $idx1, $idx2, $cnt1, $cnt2, $steps) { - - $equal = 0; - - while ($idx1 < $cnt1 && $idx2 < $cnt2 && $this->compLine($ar1[$idx1], $ar2[$idx2], $is_reg)) { - $idx1++; - $idx2++; - $equal++; - $steps--; + /** + * Return the difference + * + * @return array + */ + public function getDifference() + { + return $this->difference; } - if (--$steps > 0) { - $eq1 = 0; - $st = $steps / 2; - for ($ofs1 = $idx1 + 1; $ofs1 < $cnt1 && $st-- > 0; $ofs1++) { - $eq = @$this->countArrayDiff($ar1, $ar2, $is_reg, $w, $ofs1, $idx2, $cnt1, $cnt2, $st); + /** + * Unmodified from the original run-tests.php + * + * @param array $ar1 + * @param array $ar2 + * @param boolean $is_reg + * @param array $w + * @return array + */ + public function generateArrayDiff($ar1, $ar2, $is_reg, $w) + { + $idx1 = 0; $ofs1 = 0; $cnt1 = @count($ar1); + $idx2 = 0; $ofs2 = 0; $cnt2 = @count($ar2); + $diff = array(); + $old1 = array(); + $old2 = array(); + + while ($idx1 < $cnt1 && $idx2 < $cnt2) { + + if ($this->compLine($ar1[$idx1], $ar2[$idx2], $is_reg)) { + $idx1++; + $idx2++; + continue; + } else { + + $c1 = @$this->countArrayDiff($ar1, $ar2, $is_reg, $w, $idx1+1, $idx2, $cnt1, $cnt2, 10); + $c2 = @$this->countArrayDiff($ar1, $ar2, $is_reg, $w, $idx1, $idx2+1, $cnt1, $cnt2, 10); + + if ($c1 > $c2) { + $old1[$idx1] = (binary) sprintf("%03d- ", $idx1+1) . $w[$idx1++]; + $last = 1; + } else if ($c2 > 0) { + $old2[$idx2] = (binary) sprintf("%03d+ ", $idx2+1) . $ar2[$idx2++]; + $last = 2; + } else { + $old1[$idx1] = (binary) sprintf("%03d- ", $idx1+1) . $w[$idx1++]; + $old2[$idx2] = (binary) sprintf("%03d+ ", $idx2+1) . $ar2[$idx2++]; + } + } + } - if ($eq > $eq1) { - $eq1 = $eq; + reset($old1); $k1 = key($old1); $l1 = -2; + reset($old2); $k2 = key($old2); $l2 = -2; + + while ($k1 !== null || $k2 !== null) { + + if ($k1 == $l1 + 1 || $k2 === null) { + $l1 = $k1; + $diff[] = current($old1); + $k1 = next($old1) ? key($old1) : null; + } else if ($k2 == $l2 + 1 || $k1 === null) { + $l2 = $k2; + $diff[] = current($old2); + $k2 = next($old2) ? key($old2) : null; + } else if ($k1 < $k2) { + $l1 = $k1; + $diff[] = current($old1); + $k1 = next($old1) ? key($old1) : null; + } else { + $l2 = $k2; + $diff[] = current($old2); + $k2 = next($old2) ? key($old2) : null; + } } - } - $eq2 = 0; - $st = $steps; + while ($idx1 < $cnt1) { + $diff[] = (binary) sprintf("%03d- ", $idx1 + 1) . $w[$idx1++]; + } - for ($ofs2 = $idx2 + 1; $ofs2 < $cnt2 && $st-- > 0; $ofs2++) { - $eq = @$this->countArrayDiff($ar1, $ar2, $is_reg, $w, $idx1, $ofs2, $cnt1, $cnt2, $st); - if ($eq > $eq2) { - $eq2 = $eq; + while ($idx2 < $cnt2) { + $diff[] = (binary) sprintf("%03d+ ", $idx2 + 1) . $ar2[$idx2++]; } - } - if ($eq1 > $eq2) { - $equal += $eq1; - } else if ($eq2 > 0) { - $equal += $eq2; - } + return $diff; } - return $equal; - } - + /** + * Unmodified from the original version of runt-tests.php + * + * @param array $ar1 + * @param array $ar2 + * @param boolean $is_reg + * @param array $w + * @param int $idx1 + * @param int $idx2 + * @param int $cnt1 + * @param int $cnt2 + * @param int $steps + * @return unknown + */ + public function countArrayDiff($ar1, $ar2, $is_reg, $w, $idx1, $idx2, $cnt1, $cnt2, $steps) + { + $equal = 0; + + while ($idx1 < $cnt1 && $idx2 < $cnt2 && $this->compLine($ar1[$idx1], $ar2[$idx2], $is_reg)) { + $idx1++; + $idx2++; + $equal++; + $steps--; + } - /** - * Copied unmodified from run-tests.php - * - * @param string $l1 - * @param string $l2 - * @param boolean $is_reg - * @return boolean - */ - public function compLine($l1, $l2, $is_reg) { + if (--$steps > 0) { + $eq1 = 0; + $st = $steps / 2; + + for ($ofs1 = $idx1 + 1; $ofs1 < $cnt1 && $st-- > 0; $ofs1++) { + $eq = @$this->countArrayDiff($ar1, $ar2, $is_reg, $w, $ofs1, $idx2, $cnt1, $cnt2, $st); + + if ($eq > $eq1) { + $eq1 = $eq; + } + } + + $eq2 = 0; + $st = $steps; + + for ($ofs2 = $idx2 + 1; $ofs2 < $cnt2 && $st-- > 0; $ofs2++) { + $eq = @$this->countArrayDiff($ar1, $ar2, $is_reg, $w, $idx1, $ofs2, $cnt1, $cnt2, $st); + if ($eq > $eq2) { + $eq2 = $eq; + } + } + + if ($eq1 > $eq2) { + $equal += $eq1; + } else if ($eq2 > 0) { + $equal += $eq2; + } + } - if ($is_reg) { - return preg_match((binary) "/^$l1$/s", (binary) $l2); - } else { - return !strcmp((binary) $l1, (binary) $l2); + return $equal; } - } + /** + * Copied unmodified from run-tests.php + * + * @param string $l1 + * @param string $l2 + * @param boolean $is_reg + * @return boolean + */ + public function compLine($l1, $l2, $is_reg) + { + if ($is_reg) { + return preg_match((binary) "/^$l1$/s", (binary) $l2); + } else { + return !strcmp((binary) $l1, (binary) $l2); + } + } } -?> \ No newline at end of file +?> diff --git a/src/testcase/rtTestOutputWriter.php b/src/testcase/rtTestOutputWriter.php index eed4761..62149c7 100644 --- a/src/testcase/rtTestOutputWriter.php +++ b/src/testcase/rtTestOutputWriter.php @@ -1,45 +1,39 @@ <?php - /** * Class for writing the output from a test * */ - -abstract class rtTestOutputWriter { - - - protected $testOutput; - protected $testExitStatus; - protected $testExitMessage; - - - - public static function getInstance (array $testResults, $outputType) { +abstract class rtTestOutputWriter +{ + protected $testOutput; + protected $testExitStatus; + protected $testExitMessage; - if($outputType == 'list') { - return new rtTestOutputWriterList($testResults); - } + public static function getInstance (array $testResults, $outputType) + { + if ($outputType == 'list') { + return new rtTestOutputWriterList($testResults); + } + + if ($outputType == 'xml') { + return new rtTestOutputWriterXML($testresults); + } + } - if($outputType == 'xml') { - return new rtTestOutputWriterXML($testresults); - } + abstract function init(array $testResults); - } - - abstract function init(array $testResults); - - /** - * Write the output to standard out - * - */ - abstract function write(); - - - /** - * - */ - public function getOutput() { - return $this->testOutput; - } + /** + * Write the output to standard out + * + */ + abstract function write(); + + /** + * + */ + public function getOutput() + { + return $this->testOutput; + } } ?> diff --git a/src/testcase/rtTestPreCondition.php b/src/testcase/rtTestPreCondition.php index f0901b5..a2822b3 100644 --- a/src/testcase/rtTestPreCondition.php +++ b/src/testcase/rtTestPreCondition.php @@ -1,11 +1,10 @@ <?php +interface rtTestPreCondition +{ + public function isMet(array $testContents); -interface rtTestPreCondition { - - public function isMet(array $testContents); - - public function getMessage(); + public function getMessage(); } ?> diff --git a/src/testcase/rtTestResults.php b/src/testcase/rtTestResults.php index 1f10e47..2785080 100644 --- a/src/testcase/rtTestResults.php +++ b/src/testcase/rtTestResults.php @@ -1,172 +1,159 @@ <?php - /** * Class to store test results. - * Ensures that files are either deleted or saved depending on the test results - * Maintains an array of files names that have been saved - * Maintains (adds to) the tests case status to give a final status array - * Request calculation of difference between expected/actual output if the test has failed. + * + * Ensures that files are either deleted or saved depending on the test results + * Maintains an array of files names that have been saved + * Maintains (adds to) the tests case status to give a final status array + * Request calculation of difference between expected/actual output if the test has failed. * */ - -class rtTestResults { - - private $status = array(); - private $testName = ''; - private $savedResultsFiles = array(); - private $title = ''; - - public function __construct(rtPhpTest $testCase = null, $borkErrorString = null, $borkedFile = null) { - $this->init($testCase,$borkErrorString, $borkedFile); - } - - public function init(rtPhpTest $testCase = null, $borkErrorString = null, $borkedFile = null) { - if($testCase != null) { - $this->title = implode('',$testCase->getSection('TEST')->getContents()); - $this->status = $testCase->getStatus(); - $this->testName = $testCase->getName(); - } else { - $this->status['bork'] = $borkErrorString; - $this->testName = $borkedFile; - } - } - - public function processResults(rtPhpTest $testCase, rtRuntestsConfiguration $runConfiguration) { - - if (array_key_exists('pass', $this->status)) { - $this->onPass($testCase, $runConfiguration); - } - - elseif (array_key_exists('fail', $this->status)) { - $this->onFail($testCase); - } - - elseif (array_key_exists('skip', $this->status)) { - $this->onSkip($testCase, $runConfiguration); - } - - elseif (array_key_exists('bork', $this->status)) { - //what to do here? - } - else { - echo "no status? something wrong here\n"; - } - - - } - - - /** - * Actions is a test passes - */ - private function onPass(rtPhpTest $testCase, rtRuntestsConfiguration $runConfiguration) { - - if(!$runConfiguration->hasCommandLineOption('keep-all') && !$runConfiguration->hasCommandLineOption('keep-php')) { - $testCase->getFileSection()->deleteFile(); - } else { - $this->savedFileNames['php'] = $this->testName. ".php"; - } - - if($runConfiguration->hasCommandLineOption('keep-all') || $runConfiguration->hasCommandLineOption('keep-out')){ - $outputFileName = $this->testName.".out"; - file_put_contents($outputFileName, $testCase->getOutput()); - $this->savedFileNames['out'] = $outputFileName; - } - - if($runConfiguration->hasCommandLineOption('keep-all') || $runConfiguration->hasCommandLineOption('keep-exp')){ - $expectedFileName = $this->testName.".exp"; - file_put_contents($expectedFileName, implode(b"\n", $testCase->getExpectSection()->getContents())); - $this->savedFileNames['exp'] = $expectedFileName; - } - - if($testCase->hasSection('XFAIL')) { - $this->status['warn'] = 'Test passeses but has an XFAIL section'; - } - - if($testCase->hasSection('CLEAN')) { - if(!$runConfiguration->hasCommandLineOption('keep-all') && !$runConfiguration->hasCommandLineOption('keep-clean')) { - $testCase->getSection('CLEAN')->deleteFile(); - } else { - $this->savedFileNames['clean'] = $this->testName. ".clean"; - } - } - - if($testCase->hasSection('SKIPIF')) { - $testCase->getSection('SKIPIF')->deleteFile(); - - } - } - - private function onFail(rtPhpTest $testCase) { - - $testDifference = new rtTestDifference($testCase->getExpectSection(), $testCase->getOutput()); - $difference = implode(b"\n",$testDifference->getDifference()); - - $differenceFileName = $this->testName.".diff"; - $outputFileName = $this->testName.".out"; - $expectedFileName = $this->testName.".exp"; - - file_put_contents($differenceFileName, $difference); - file_put_contents($outputFileName, $testCase->getOutput()); - file_put_contents($expectedFileName, implode(b"\n", $testCase->getExpectSection()->getContents())); - - $this->savedFileNames['out'] = $outputFileName; - $this->savedFileNames['exp'] = $expectedFileName; - $this->savedFileNames['diff'] = $differenceFileName; - - if($testCase->hasSection('XFAIL')) { - $this->status['xfail'] = $testCase->getSection('XFAIL')->getReason(); - - } - - //Note: if there are clean and skipif files they will not be deleted if the test fails - if($testCase->hasSection('CLEAN')) { - $this->savedFileNames['clean'] = $this->testName. 'clean.php'; - } - - if($testCase->hasSection('SKIPIF')) { - $this->savedFileNames['skipif'] = $this->testName. 'skipif.php'; - } - - } - - private function onSkip(rtPhpTest $testCase, rtRuntestsConfiguration $runConfiguration) { - - if($runConfiguration->hasCommandLineOption('keep-all') || $runConfiguration->hasCommandLineOption('keep-skip')) { - $this->savedFileNames['skipif'] = $this->testName. 'skipif.php'; - } else { - - $skipSection = $testCase->getSection('SKIPIF'); - $skipSection->deleteFile(); +class rtTestResults +{ + private $status = array(); + private $testName = ''; + private $savedResultsFiles = array(); + private $title = ''; + + public function __construct(rtPhpTest $testCase = null, $borkErrorString = null, $borkedFile = null) + { + $this->init($testCase,$borkErrorString, $borkedFile); + } + + public function init(rtPhpTest $testCase = null, $borkErrorString = null, $borkedFile = null) + { + if ($testCase != null) { + $this->title = implode('',$testCase->getSection('TEST')->getContents()); + $this->status = $testCase->getStatus(); + $this->testName = $testCase->getName(); + } else { + $this->status['bork'] = $borkErrorString; + $this->testName = $borkedFile; + } + } + + public function processResults(rtPhpTest $testCase, rtRuntestsConfiguration $runConfiguration) + { + + if (array_key_exists('pass', $this->status)) { + $this->onPass($testCase, $runConfiguration); + } elseif (array_key_exists('fail', $this->status)) { + $this->onFail($testCase); + } elseif (array_key_exists('skip', $this->status)) { + $this->onSkip($testCase, $runConfiguration); + } elseif (array_key_exists('bork', $this->status)) { + //what to do here? + } else { + echo "no status? something wrong here\n"; + } + } + + /** + * Actions is a test passes + */ + private function onPass(rtPhpTest $testCase, rtRuntestsConfiguration $runConfiguration) + { + if (!$runConfiguration->hasCommandLineOption('keep-all') && !$runConfiguration->hasCommandLineOption('keep-php')) { + $testCase->getFileSection()->deleteFile(); + } else { + $this->savedFileNames['php'] = $this->testName. ".php"; + } + + if ($runConfiguration->hasCommandLineOption('keep-all') || $runConfiguration->hasCommandLineOption('keep-out')) { + $outputFileName = $this->testName.".out"; + file_put_contents($outputFileName, $testCase->getOutput()); + $this->savedFileNames['out'] = $outputFileName; + } + + if ($runConfiguration->hasCommandLineOption('keep-all') || $runConfiguration->hasCommandLineOption('keep-exp')) { + $expectedFileName = $this->testName.".exp"; + file_put_contents($expectedFileName, implode(b"\n", $testCase->getExpectSection()->getContents())); + $this->savedFileNames['exp'] = $expectedFileName; + } + + if ($testCase->hasSection('XFAIL')) { + $this->status['warn'] = 'Test passeses but has an XFAIL section'; + } + + if ($testCase->hasSection('CLEAN')) { + if (!$runConfiguration->hasCommandLineOption('keep-all') && !$runConfiguration->hasCommandLineOption('keep-clean')) { + $testCase->getSection('CLEAN')->deleteFile(); + } else { + $this->savedFileNames['clean'] = $this->testName. ".clean"; + } + } + + if ($testCase->hasSection('SKIPIF')) { + $testCase->getSection('SKIPIF')->deleteFile(); + } + } + + private function onFail(rtPhpTest $testCase) + { + $testDifference = new rtTestDifference($testCase->getExpectSection(), $testCase->getOutput()); + $difference = implode(b"\n",$testDifference->getDifference()); + + $differenceFileName = $this->testName.".diff"; + $outputFileName = $this->testName.".out"; + $expectedFileName = $this->testName.".exp"; + + file_put_contents($differenceFileName, $difference); + file_put_contents($outputFileName, $testCase->getOutput()); + file_put_contents($expectedFileName, implode(b"\n", $testCase->getExpectSection()->getContents())); + + $this->savedFileNames['out'] = $outputFileName; + $this->savedFileNames['exp'] = $expectedFileName; + $this->savedFileNames['diff'] = $differenceFileName; + + if ($testCase->hasSection('XFAIL')) { + $this->status['xfail'] = $testCase->getSection('XFAIL')->getReason(); + } + + //Note: if there are clean and skipif files they will not be deleted if the test fails + if ($testCase->hasSection('CLEAN')) { + $this->savedFileNames['clean'] = $this->testName. 'clean.php'; + } + + if ($testCase->hasSection('SKIPIF')) { + $this->savedFileNames['skipif'] = $this->testName. 'skipif.php'; + } + } + + private function onSkip(rtPhpTest $testCase, rtRuntestsConfiguration $runConfiguration) + { + if ($runConfiguration->hasCommandLineOption('keep-all') || $runConfiguration->hasCommandLineOption('keep-skip')) { + $this->savedFileNames['skipif'] = $this->testName. 'skipif.php'; + } else { + $skipSection = $testCase->getSection('SKIPIF'); + $skipSection->deleteFile(); + } + + //It may seem odd to check for an XFAIL if we are skipping the test, on the other hand I found + //a few windows tests with blank XFAIL sections and wanted to know about those. + + if ($testCase->hasSection('XFAIL')) { + $this->status['xfail'] = $testCase->getSection('XFAIL')->getReason(); + } + } + + public function getStatus() + { + return $this->status; + } + + public function getSavedFileNames() + { + return $this->savedFileNames; + } + + public function getName() + { + return $this->testName; + } + + public function getTitle() + { + return $this->title; } - - //It may seem odd to check for an XFAIL if we are skipping the test, on the other hand I found - //a few windows tests with blank XFAIL sections and wanted to know about those. - - if($testCase->hasSection('XFAIL')) { - $this->status['xfail'] = $testCase->getSection('XFAIL')->getReason(); - } - - } - - - public function getStatus() { - return $this->status; - } - - public function getSavedFileNames() { - return $this->savedFileNames; - } - - public function getName() { - return $this->testName; - } - - public function getTitle() { - return $this->title; - } - - - } -?> \ No newline at end of file +?> diff --git a/src/testcase/sections/configurationsections/rtArgsSection.php b/src/testcase/sections/configurationsections/rtArgsSection.php index 8409e47..47ae97b 100644 --- a/src/testcase/sections/configurationsections/rtArgsSection.php +++ b/src/testcase/sections/configurationsections/rtArgsSection.php @@ -1,21 +1,24 @@ <?php -class rtArgsSection extends rtConfigurationSection { - - private $testCommandLineArguments; - - - protected function init() { - $this->testCommandLineArguments = '-- ' . $this->sectionContents[0]; - } - - /** - * Return additional arguments to be added to the PHP Test command line - * - * @return string - */ - public function getTestCommandLineArguments() { - return $this->testCommandLineArguments; - } - +/** + * + */ +class rtArgsSection extends rtConfigurationSection +{ + private $testCommandLineArguments; + + protected function init() + { + $this->testCommandLineArguments = '-- ' . $this->sectionContents[0]; + } + + /** + * Return additional arguments to be added to the PHP Test command line + * + * @return string + */ + public function getTestCommandLineArguments() + { + return $this->testCommandLineArguments; + } } -?> \ No newline at end of file +?> diff --git a/src/testcase/sections/configurationsections/rtEnvSection.php b/src/testcase/sections/configurationsections/rtEnvSection.php index 8758819..602893b 100644 --- a/src/testcase/sections/configurationsections/rtEnvSection.php +++ b/src/testcase/sections/configurationsections/rtEnvSection.php @@ -1,23 +1,27 @@ <?php -class rtEnvSection extends rtConfigurationSection { +/** + * + */ +class rtEnvSection extends rtConfigurationSection +{ + private $testEnvironmentVariables = array(); - private $testEnvironmentVariables = array(); - - - protected function init() { - foreach($this->sectionContents as $line) { - $tempArray = explode('=', $line); - $this->testEnvironmentVariables[trim($tempArray[0])] = trim($tempArray[1]); + protected function init() + { + foreach ($this->sectionContents as $line) { + $tempArray = explode('=', $line); + $this->testEnvironmentVariables[trim($tempArray[0])] = trim($tempArray[1]); + } } - } - /** - * Additional environment variables required by the test - * - * @return array - */ - public function getTestEnvironmentVariables() { - return $this->testEnvironmentVariables; - } + /** + * Additional environment variables required by the test + * + * @return array + */ + public function getTestEnvironmentVariables() + { + return $this->testEnvironmentVariables; + } } -?> \ No newline at end of file +?> diff --git a/src/testcase/sections/configurationsections/rtIniSection.php b/src/testcase/sections/configurationsections/rtIniSection.php index 932ac74..85fe279 100644 --- a/src/testcase/sections/configurationsections/rtIniSection.php +++ b/src/testcase/sections/configurationsections/rtIniSection.php @@ -1,24 +1,26 @@ <?php +/** + * + */ +class rtIniSection extends rtConfigurationSection +{ + private $commandLineArguments = array(); -class rtIniSection extends rtConfigurationSection { - - private $commandLineArguments = array(); - - - public function init() { - foreach ($this->sectionContents as $line) { - $this->commandLineArguments[] = addslashes($line); + public function init() + { + foreach ($this->sectionContents as $line) { + $this->commandLineArguments[] = addslashes($line); + } + } + + /** + * Returns any additional PHP commandline arguments + * + * @return array + */ + public function getCommandLineArguments() + { + return $this->commandLineArguments; } - } - - /** - * Returns any additional PHP commandline arguments - * - * @return array - */ - public function getCommandLineArguments() { - return $this->commandLineArguments; - } - } -?> \ No newline at end of file +?> diff --git a/src/testcase/sections/executablesections/rtCleanSection.php b/src/testcase/sections/executablesections/rtCleanSection.php index d7627b7..d4a8eff 100644 --- a/src/testcase/sections/executablesections/rtCleanSection.php +++ b/src/testcase/sections/executablesections/rtCleanSection.php @@ -1,44 +1,41 @@ <?php - /** * Class representing the clean test section */ -class rtCleanSection extends rtExecutableSection { - - - public function setExecutableFileName($testName) { - $this->fileName = $testName.".clean.php"; - } - - public function run(rtPhpTest $testCase, rtRuntestsConfiguration $runConfiguration) { - - $this->status = array(); - - $this->setExecutableFileName($testCase->getName()); - $this->writeExecutableFile(); - - $phpCommand = $runConfiguration->getSetting('PhpExecutable'); - $phpCommand .= ' '.$runConfiguration->getSetting('PhpCommandLineArguments'); - $phpCommand .= ' -f '.$this->fileName; - - $PhpRunner = new rtPhpRunner($phpCommand, - $runConfiguration->getEnvironmentVariables(), - $runConfiguration->getSetting('WorkingDirectory') - ); - +class rtCleanSection extends rtExecutableSection +{ + public function setExecutableFileName($testName) + { + $this->fileName = $testName.".clean.php"; + } - try { - $this->output = $PhpRunner->runphp(); - //if the CLEAN section has worked the result should be a blank line - if(trim($this->output) != "") { - $this->status['warn'] = 'Execution of clean section failed: '.trim($this->output); - } - } catch (rtPhpRunnerException $e) { - $this->status['warn'] = 'Failed to execute clean section'; + public function run(rtPhpTest $testCase, rtRuntestsConfiguration $runConfiguration) + { + $this->status = array(); + + $this->setExecutableFileName($testCase->getName()); + $this->writeExecutableFile(); + + $phpCommand = $runConfiguration->getSetting('PhpExecutable'); + $phpCommand .= ' '.$runConfiguration->getSetting('PhpCommandLineArguments'); + $phpCommand .= ' -f '.$this->fileName; + + $PhpRunner = new rtPhpRunner($phpCommand, + $runConfiguration->getEnvironmentVariables(), + $runConfiguration->getSetting('WorkingDirectory') + ); + + try { + $this->output = $PhpRunner->runphp(); + //if the CLEAN section has worked the result should be a blank line + if (trim($this->output) != "") { + $this->status['warn'] = 'Execution of clean section failed: '.trim($this->output); + } + } catch (rtPhpRunnerException $e) { + $this->status['warn'] = 'Failed to execute clean section'; + } + + return $this->status; } - - return $this->status; - } } - -?> \ No newline at end of file +?> diff --git a/src/testcase/sections/executablesections/rtFileSection.php b/src/testcase/sections/executablesections/rtFileSection.php index f9dc95c..4120d60 100644 --- a/src/testcase/sections/executablesections/rtFileSection.php +++ b/src/testcase/sections/executablesections/rtFileSection.php @@ -1,41 +1,38 @@ <?php - /** * Class for the --FILE-- section */ -class rtFileSection extends rtExecutableSection { - - - public function setExecutableFileName($testName) { - $this->fileName = $testName.".php"; - } +class rtFileSection extends rtExecutableSection +{ + public function setExecutableFileName($testName) + { + $this->fileName = $testName.".php"; + } - public function run(rtPhpTest $testCase, rtRuntestsConfiguration $runConfiguration) { - - $this->status = array(); + public function run(rtPhpTest $testCase, rtRuntestsConfiguration $runConfiguration) + { + $this->status = array(); - $this->setExecutableFileName($testCase->getName()); - $this->writeExecutableFile(); + $this->setExecutableFileName($testCase->getName()); + $this->writeExecutableFile(); - $phpCommand = $runConfiguration->getSetting('PhpExecutable'); - $phpCommand .= ' '.$testCase->testConfiguration->getPhpCommandLineArguments(); - $phpCommand .= ' -f '.$this->fileName; - $phpCommand .= ' '.$testCase->testConfiguration->getTestCommandLineArguments(); - - $PhpRunner = new rtPhpRunner($phpCommand, - $testCase->testConfiguration->getEnvironmentVariables(), - $runConfiguration->getSetting('WorkingDirectory') - ); - - try { - $this->output = $PhpRunner->runphp(); - } catch (rtPhpRunnerException $e) { - $this->status['fail'] = $e->getMessage(); + $phpCommand = $runConfiguration->getSetting('PhpExecutable'); + $phpCommand .= ' '.$testCase->testConfiguration->getPhpCommandLineArguments(); + $phpCommand .= ' -f '.$this->fileName; + $phpCommand .= ' '.$testCase->testConfiguration->getTestCommandLineArguments(); + + $PhpRunner = new rtPhpRunner($phpCommand, + $testCase->testConfiguration->getEnvironmentVariables(), + $runConfiguration->getSetting('WorkingDirectory') + ); + + try { + $this->output = $PhpRunner->runphp(); + } catch (rtPhpRunnerException $e) { + $this->status['fail'] = $e->getMessage(); + } + + return $this->status; } - - return $this->status; - - } - } -?> \ No newline at end of file +?> diff --git a/src/testcase/sections/executablesections/rtSkipIfSection.php b/src/testcase/sections/executablesections/rtSkipIfSection.php index 146ec63..e706e96 100644 --- a/src/testcase/sections/executablesections/rtSkipIfSection.php +++ b/src/testcase/sections/executablesections/rtSkipIfSection.php @@ -1,60 +1,53 @@ <?php - /** * Class representing the SkipIf test section */ -class rtSkipIfSection extends rtExecutableSection { - - - public function setExecutableFileName($testName) { - $this->fileName = $testName.".skipif.php"; - } - - - public function run(rtPhpTest $testCase, rtRuntestsConfiguration $runConfiguration) { - - $this->status = array(); - - $this->setExecutableFileName($testCase->getName()); - $this->writeExecutableFile(); - - $phpCommand = $runConfiguration->getSetting('PhpExecutable'); - $phpCommand .= ' '.$runConfiguration->getSetting('PhpCommandLineArguments'); - $phpCommand .= ' -f '.$this->fileName; - - $PhpRunner = new rtPhpRunner($phpCommand, - $runConfiguration->getEnvironmentVariables(), - $runConfiguration->getSetting('WorkingDirectory') - ); - - try { - $this->output = $PhpRunner->runphp(); - - if (!strncasecmp('skip', ltrim($this->output), 4)) { - if(preg_match('/^\s*skip\s*(.+)\s*/i', $this->output, $matches)) { - $this->status['skip'] = $matches[1]; - } - else { - $this->status['skip'] = ''; - } - } +class rtSkipIfSection extends rtExecutableSection +{ + public function setExecutableFileName($testName) + { + $this->fileName = $testName.".skipif.php"; + } - if (!strncasecmp('warn', ltrim($this->output), 4)) { - if(preg_match('/^\s*warn\s*(.+)\s*/i', $this->output, $matches)) { - $this->status['warn'] = $matches[1]; + public function run(rtPhpTest $testCase, rtRuntestsConfiguration $runConfiguration) + { + $this->status = array(); + + $this->setExecutableFileName($testCase->getName()); + $this->writeExecutableFile(); + + $phpCommand = $runConfiguration->getSetting('PhpExecutable'); + $phpCommand .= ' '.$runConfiguration->getSetting('PhpCommandLineArguments'); + $phpCommand .= ' -f '.$this->fileName; + + $PhpRunner = new rtPhpRunner($phpCommand, + $runConfiguration->getEnvironmentVariables(), + $runConfiguration->getSetting('WorkingDirectory') + ); + + try { + $this->output = $PhpRunner->runphp(); + + if (!strncasecmp('skip', ltrim($this->output), 4)) { + if (preg_match('/^\s*skip\s*(.+)\s*/i', $this->output, $matches)) { + $this->status['skip'] = $matches[1]; + } else { + $this->status['skip'] = ''; + } + } + + if (!strncasecmp('warn', ltrim($this->output), 4)) { + if (preg_match('/^\s*warn\s*(.+)\s*/i', $this->output, $matches)) { + $this->status['warn'] = $matches[1]; + } else { + $this->status['warn'] = ''; + } + } + } catch (rtPhpRunnerException $e) { + $this->status['bork'] = 'Failed to execute skipif section'; } - else { - $this->status['warn'] = ''; - } - } - - } catch (rtPhpRunnerException $e) { - $this->status['bork'] = 'Failed to execute skipif section'; + + return $this->status; } - - return $this->status; - } - - } -?> \ No newline at end of file +?> diff --git a/src/testcase/sections/informationsections/rtCreditsSection.php b/src/testcase/sections/informationsections/rtCreditsSection.php index 15d6197..e86336b 100644 --- a/src/testcase/sections/informationsections/rtCreditsSection.php +++ b/src/testcase/sections/informationsections/rtCreditsSection.php @@ -1,11 +1,9 @@ <?php - - /** * Class for --CREDITS-- section * */ -class rtCreditsSection extends rtInformationSection { - +class rtCreditsSection extends rtInformationSection +{ } -?> \ No newline at end of file +?> diff --git a/src/testcase/sections/informationsections/rtTestHeaderSection.php b/src/testcase/sections/informationsections/rtTestHeaderSection.php index ba0290c..9da8d69 100644 --- a/src/testcase/sections/informationsections/rtTestHeaderSection.php +++ b/src/testcase/sections/informationsections/rtTestHeaderSection.php @@ -1,19 +1,20 @@ <?php - /** * Class for the --TEST-- section */ -class rtTestHeaderSection extends rtInformationSection { - - protected $testHeader; - - protected function init() { - //Only a single line heading is allowed. Ingore any more lines. - $this->testHeader = $this->sectionContents[0]; - } - - public function getHeader() { - return $this->testHeader; - } +class rtTestHeaderSection extends rtInformationSection +{ + protected $testHeader; + + protected function init() + { + //Only a single line heading is allowed. Ingore any more lines. + $this->testHeader = $this->sectionContents[0]; + } + + public function getHeader() + { + return $this->testHeader; + } } -?> \ No newline at end of file +?> diff --git a/src/testcase/sections/informationsections/rtXfailSection.php b/src/testcase/sections/informationsections/rtXfailSection.php index d60cdc7..5c196f0 100644 --- a/src/testcase/sections/informationsections/rtXfailSection.php +++ b/src/testcase/sections/informationsections/rtXfailSection.php @@ -1,25 +1,25 @@ <?php - - /** * Class for the --XFAIL-- section * */ -class rtXfailSection extends rtInformationSection { +class rtXfailSection extends rtInformationSection +{ + protected $failReason; - protected $failReason; - - protected function init() { - //Only a single line reason is allowed. Ingore any more lines. - if(isset($this->sectionContents[0])){ - $this->failReason = $this->sectionContents[0]; - } else { - $this->failReason = "This test is apparently expected to fail but the author did not say why"; + protected function init() + { + //Only a single line reason is allowed. Ingore any more lines. + if (isset($this->sectionContents[0])) { + $this->failReason = $this->sectionContents[0]; + } else { + $this->failReason = "This test is apparently expected to fail but the author did not say why"; + } } - } - public function getReason() { - return $this->failReason; - } + public function getReason() + { + return $this->failReason; + } } -?> \ No newline at end of file +?> diff --git a/src/testcase/sections/outputsections/rtExpectFSection.php b/src/testcase/sections/outputsections/rtExpectFSection.php index 693c947..40de4df 100644 --- a/src/testcase/sections/outputsections/rtExpectFSection.php +++ b/src/testcase/sections/outputsections/rtExpectFSection.php @@ -1,96 +1,97 @@ <?php - - /** * Class representing expected and actual output from a test */ -class rtExpectFSection extends rtOutputSection { - - protected function init() { - parent::createPattern(); - $this->createPattern(); - } - - /** - * Create the pattern used to match against actual output - * - */ - protected function createPattern() { - $this->expectedPattern = preg_quote($this->expectedPattern, '/'); - $this->expectedPattern = $this->expectfUnicodeSubstitutions ($this->expectedPattern); - $this->expectedPattern = $this->expectfRegexSubstitutions($this->expectedPattern); - } - - - /* - * Replaces string with unicode and vice versa. Allows same tests for PHP5 and PHP6 - * @param string - * @return string - */ - private function expectfUnicodeSubstitutions($string) { - $string = str_replace( - array('%unicode_string_optional%'), - version_compare(PHP_VERSION, '6.0.0-dev') == -1 ? 'string' : 'Unicode string', $string ); +class rtExpectFSection extends rtOutputSection +{ + protected function init() + { + parent::createPattern(); + $this->createPattern(); + } + + /** + * Create the pattern used to match against actual output + * + */ + protected function createPattern() + { + $this->expectedPattern = preg_quote($this->expectedPattern, '/'); + $this->expectedPattern = $this->expectfUnicodeSubstitutions ($this->expectedPattern); + $this->expectedPattern = $this->expectfRegexSubstitutions($this->expectedPattern); + } - $string = str_replace( - array('%unicode\|string%', '%string\|unicode%'), - version_compare(PHP_VERSION, '6.0.0-dev') == -1 ? 'string' : 'unicode', - $string - ); + /* + * Replaces string with unicode and vice versa. Allows same tests for PHP5 and PHP6 + * @param string + * @return string + */ + private function expectfUnicodeSubstitutions($string) + { + $string = str_replace( + array('%unicode_string_optional%'), + version_compare(PHP_VERSION, '6.0.0-dev') == -1 ? 'string' : 'Unicode string', $string + ); + + $string = str_replace( + array('%unicode\|string%', '%string\|unicode%'), + version_compare(PHP_VERSION, '6.0.0-dev') == -1 ? 'string' : 'unicode', + $string + ); + + $string = str_replace( + array('%u\|b%', '%b\|u%'), + version_compare(PHP_VERSION, '6.0.0-dev') == -1 ? '' : 'u', + $string + ); + + return $string; + } - $string = str_replace( - array('%u\|b%', '%b\|u%'), - version_compare(PHP_VERSION, '6.0.0-dev') == -1 ? '' : 'u', - $string - ); - return $string; - } + /* + * Substitute the %strings used in EXPECTF sections with a regular expression + * @param string + * @return string + */ + private function expectfRegexSubstitutions($string) + { + $string = str_replace('%e', '\\' . DIRECTORY_SEPARATOR, $string); + $string = str_replace('%s', '[^\r\n]+', $string); + $string = str_replace('%S', '[^\r\n]*', $string); + $string = str_replace('%a', '.+', $string); + $string = str_replace('%A', '.*', $string); + $string = str_replace('%w', '\s*', $string); + $string = str_replace('%i', '[+-]?\d+', $string); + $string = str_replace('%d', '\d+', $string); + $string = str_replace('%x', '[0-9a-fA-F]+', $string); + $string = str_replace('%f', '[+-]?\.?\d+\.?\d*(?:[Ee][+-]?\d+)?', $string); + $string = str_replace('%c', '.', $string); - - /* - * Substitute the %strings used in EXPECTF sections with a regular expression - * @param string - * @return string - */ - private function expectfRegexSubstitutions($string) { + return $string; + } - $string = str_replace('%e', '\\' . DIRECTORY_SEPARATOR, $string); - $string = str_replace('%s', '[^\r\n]+', $string); - $string = str_replace('%S', '[^\r\n]*', $string); - $string = str_replace('%a', '.+', $string); - $string = str_replace('%A', '.*', $string); - $string = str_replace('%w', '\s*', $string); - $string = str_replace('%i', '[+-]?\d+', $string); - $string = str_replace('%d', '\d+', $string); - $string = str_replace('%x', '[0-9a-fA-F]+', $string); - $string = str_replace('%f', '[+-]?\.?\d+\.?\d*(?:[Ee][+-]?\d+)?', $string); - $string = str_replace('%c', '.', $string); - return $string; - } - - - - /** - * Compare the test output with the expected pattern - * - * @param string $testOutput - * @return boolean - */ - public function compare($testOutput) { - $testOutput = trim(preg_replace("/$this->carriageReturnLineFeed/", $this->lineFeed, $testOutput)); - - /*For debugging: - - file_put_contents(sys_get_temp_dir().'/zrtexp',$this->expectedPattern ); - file_put_contents(sys_get_temp_dir().'/zrtout', $testOutput ); + /** + * Compare the test output with the expected pattern + * + * @param string $testOutput + * @return boolean + */ + public function compare($testOutput) + { + $testOutput = trim(preg_replace("/$this->carriageReturnLineFeed/", $this->lineFeed, $testOutput)); + + /*For debugging: + + file_put_contents(sys_get_temp_dir().'/zrtexp',$this->expectedPattern ); + file_put_contents(sys_get_temp_dir().'/zrtout', $testOutput ); - */ - - if (preg_match((binary) "/^$this->expectedPattern\$/s", $testOutput)) { - return true; - } else { - return false; + */ + + if (preg_match((binary) "/^$this->expectedPattern\$/s", $testOutput)) { + return true; + } else { + return false; + } } - } } -?> \ No newline at end of file +?> diff --git a/src/testcase/sections/outputsections/rtExpectRegexSection.php b/src/testcase/sections/outputsections/rtExpectRegexSection.php index f18ef1f..0dca266 100644 --- a/src/testcase/sections/outputsections/rtExpectRegexSection.php +++ b/src/testcase/sections/outputsections/rtExpectRegexSection.php @@ -1,37 +1,36 @@ <?php - /** * Class representing expected output and actual output */ -class rtExpectRegexSection extends rtOutputSection { - - protected function init() { - parent::createPattern(); - } - - - /** - * Compare the test output with the expected pattern - * - * @param string $testOutput - * @return boolean - */ - public function compare($testOutput) { - - $testOutput = trim(preg_replace("/$this->carriageReturnLineFeed/", $this->lineFeed, $testOutput)); - - /*For debugging: +class rtExpectRegexSection extends rtOutputSection +{ + protected function init() + { + parent::createPattern(); + } - file_put_contents(sys_get_temp_dir().'/zrtexp',$this->expectedPattern ); - file_put_contents(sys_get_temp_dir().'/zrtout', $testOutput ); + /** + * Compare the test output with the expected pattern + * + * @param string $testOutput + * @return boolean + */ + public function compare($testOutput) + { + $testOutput = trim(preg_replace("/$this->carriageReturnLineFeed/", $this->lineFeed, $testOutput)); + + /*For debugging: + + file_put_contents(sys_get_temp_dir().'/zrtexp',$this->expectedPattern ); + file_put_contents(sys_get_temp_dir().'/zrtout', $testOutput ); - */ - - if (preg_match((binary) "/^$this->expectedPattern\$/s", $testOutput)) { - return true; - } else { - return false; + */ + + if (preg_match((binary) "/^$this->expectedPattern\$/s", $testOutput)) { + return true; + } else { + return false; + } } - } } -?> \ No newline at end of file +?> diff --git a/src/testcase/sections/outputsections/rtExpectSection.php b/src/testcase/sections/outputsections/rtExpectSection.php index df59033..e2d789f 100644 --- a/src/testcase/sections/outputsections/rtExpectSection.php +++ b/src/testcase/sections/outputsections/rtExpectSection.php @@ -1,29 +1,29 @@ <?php - /** * Class representing expected output and actual output */ -class rtExpectSection extends rtOutputSection { +class rtExpectSection extends rtOutputSection +{ + protected function init() + { + parent::createPattern(); + } - protected function init() { - parent::createPattern(); - } - + /** + * Compare the test output with the expected pattern + * + * @param string $testOutput + * @return boolean + */ + public function compare($testOutput) + { + $testOutput = trim(preg_replace("/$this->carriageReturnLineFeed/", $this->lineFeed, $testOutput)); - /** - * Compare the test output with the expected pattern - * - * @param string $testOutput - * @return boolean - */ - public function compare($testOutput) { - $testOutput = trim(preg_replace("/$this->carriageReturnLineFeed/", $this->lineFeed, $testOutput)); - if (strcmp($this->expectedPattern, $testOutput) == 0) { - return true; - } else { - return false; + if (strcmp($this->expectedPattern, $testOutput) == 0) { + return true; + } else { + return false; + } } - } - } -?> \ No newline at end of file +?> diff --git a/src/testcase/sections/rtConfigurationSection.php b/src/testcase/sections/rtConfigurationSection.php index 996833d..a1a34f2 100644 --- a/src/testcase/sections/rtConfigurationSection.php +++ b/src/testcase/sections/rtConfigurationSection.php @@ -1,8 +1,8 @@ <?php - - -abstract class rtConfigurationSection extends rtSection { - +/** + * + */ +abstract class rtConfigurationSection extends rtSection +{ } - -?> \ No newline at end of file +?> diff --git a/src/testcase/sections/rtExecutableSection.php b/src/testcase/sections/rtExecutableSection.php index cfed6c6..e145321 100644 --- a/src/testcase/sections/rtExecutableSection.php +++ b/src/testcase/sections/rtExecutableSection.php @@ -1,34 +1,38 @@ <?php - - -abstract class rtExecutableSection extends rtSection { - - protected $fileName; - protected $output; - protected $status; - - protected function init() { +/** + * + */ +abstract class rtExecutableSection extends rtSection +{ + protected $fileName; + protected $output; + protected $status; - } - - protected function writeExecutableFile() { - $contentsAsString = implode("\n", $this->sectionContents) ."\n"; - file_put_contents($this->fileName, (binary) $contentsAsString); - } - - public function getFileName() { - return $this->fileName; - } - - public function deleteFile() { - @unlink($this->fileName); - } - - public function getOutput() { - return $this->output; - } - - - abstract function run(rtPhpTest $testcase, rtRuntestsConfiguration $runConfiguration); + protected function init() + { + } + + protected function writeExecutableFile() + { + $contentsAsString = implode("\n", $this->sectionContents) ."\n"; + file_put_contents($this->fileName, (binary) $contentsAsString); + } + + public function getFileName() + { + return $this->fileName; + } + + public function deleteFile() + { + @unlink($this->fileName); + } + + public function getOutput() + { + return $this->output; + } + + abstract function run(rtPhpTest $testcase, rtRuntestsConfiguration $runConfiguration); } ?> diff --git a/src/testcase/sections/rtInformationSection.php b/src/testcase/sections/rtInformationSection.php index 9f1dac9..eeaf93a 100644 --- a/src/testcase/sections/rtInformationSection.php +++ b/src/testcase/sections/rtInformationSection.php @@ -1,13 +1,12 @@ <?php - /** * Class for all information sections * */ -class rtInformationSection extends rtSection { - - protected function init() { - - } +class rtInformationSection extends rtSection +{ + protected function init() + { + } } -?> \ No newline at end of file +?> diff --git a/src/testcase/sections/rtOutputSection.php b/src/testcase/sections/rtOutputSection.php index bbce322..a204f0b 100644 --- a/src/testcase/sections/rtOutputSection.php +++ b/src/testcase/sections/rtOutputSection.php @@ -1,34 +1,35 @@ <?php - /** * parent class for all expected output sections * */ +abstract class rtOutputSection extends rtSection +{ + protected $expectedPattern; + + protected function init() + { + $this->createPattern(); + } + + /** + * Create the pattern used to match against actual output + * + */ + protected function createPattern() + { + $this->expectedPattern = implode($this->lineFeed, $this->sectionContents); + $this->expectedPattern = str_replace($this->carriageReturnLineFeed, $this->lineFeed, $this->expectedPattern); -abstract class rtOutputSection extends rtSection { - - protected $expectedPattern; - - protected function init() { - $this->createPattern(); - } - - /** - * Create the pattern used to match against actual output - * - */ - protected function createPattern() { - $this->expectedPattern = implode ($this->lineFeed, $this->sectionContents ); - $this->expectedPattern = str_replace($this->carriageReturnLineFeed, $this->lineFeed, $this->expectedPattern); - - //remove any blank lines from the start and end - $this->expectedPattern = trim($this->expectedPattern); - } + //remove any blank lines from the start and end + $this->expectedPattern = trim($this->expectedPattern); + } - public function getPattern() { - return $this->expectedPattern; - } + public function getPattern() + { + return $this->expectedPattern; + } - abstract function compare($testOutput); + abstract function compare($testOutput); } ?> diff --git a/src/testcase/sections/rtSection.php b/src/testcase/sections/rtSection.php index 58378ba..cf2de24 100644 --- a/src/testcase/sections/rtSection.php +++ b/src/testcase/sections/rtSection.php @@ -1,58 +1,57 @@ <?php - /** * Parent class for all test case sections * */ -abstract class rtSection { - - private static $sectionMap = array ( - 'TEST' => 'rtTestHeaderSection', - 'SKIPIF' => 'rtSkipIfSection', - 'FILE' => 'rtFileSection', - 'EXPECT' => 'rtExpectSection', - 'EXPECTF' => 'rtExpectFSection', - 'EXPECTREGEX' => 'rtExpectRegexSection', - 'INI' => 'rtIniSection', - 'ARGS' => 'rtArgsSection', - 'ENV' => 'rtEnvSection', - 'CREDITS' => 'rtCreditsSection', - 'CLEAN' => 'rtCleanSection', - 'XFAIL' => 'rtXfailSection', - ); - - protected $sectionName; - protected $sectionContents; - - protected $carriageReturnLineFeed = "\r\n"; - protected $lineFeed = "\n"; - - - public function __construct($sectionName, $contents) - { - $this->sectionName = $sectionName; - $this->sectionContents = $contents; - $this->init(); - } - - abstract protected function init(); - - public static function getInstance($sectionName, $contents) { - - if (!isset(self::$sectionMap[$sectionName])) { - throw new RuntimeException('Unknown section type ' . $sectionName); +abstract class rtSection +{ + private static $sectionMap = array ( + 'TEST' => 'rtTestHeaderSection', + 'SKIPIF' => 'rtSkipIfSection', + 'FILE' => 'rtFileSection', + 'EXPECT' => 'rtExpectSection', + 'EXPECTF' => 'rtExpectFSection', + 'EXPECTREGEX' => 'rtExpectRegexSection', + 'INI' => 'rtIniSection', + 'ARGS' => 'rtArgsSection', + 'ENV' => 'rtEnvSection', + 'CREDITS' => 'rtCreditsSection', + 'CLEAN' => 'rtCleanSection', + 'XFAIL' => 'rtXfailSection', + ); + + protected $sectionName; + protected $sectionContents; + + protected $carriageReturnLineFeed = "\r\n"; + protected $lineFeed = "\n"; + + public function __construct($sectionName, $contents) + { + $this->sectionName = $sectionName; + $this->sectionContents = $contents; + $this->init(); } - return new rtSection::$sectionMap[$sectionName]($sectionName, $contents); - } + abstract protected function init(); - public function getName() { - return $this->sectionName; - } + public static function getInstance($sectionName, $contents) + { + if (!isset(self::$sectionMap[$sectionName])) { + throw new RuntimeException('Unknown section type ' . $sectionName); + } - public function getContents() { - return $this->sectionContents; - } + return new rtSection::$sectionMap[$sectionName]($sectionName, $contents); + } + public function getName() + { + return $this->sectionName; + } + + public function getContents() + { + return $this->sectionContents; + } } ?> diff --git a/src/testgroup/rtPhpTestGroup.php b/src/testgroup/rtPhpTestGroup.php index fb6fd4a..ad2a542 100644 --- a/src/testgroup/rtPhpTestGroup.php +++ b/src/testgroup/rtPhpTestGroup.php @@ -1,68 +1,62 @@ <?php - - /** * Runs a 'group of tests'. A 'group' is all or the tests in a single directory. * */ -class rtPhpTestGroup { - - - private $testDirectory; - private $testCases; - private $results; - - - public function __construct(rtRuntestsConfiguration $runConfiguration, $directory) { - $this->testDirectory = $directory; - $this->init($runConfiguration); - } - - - public function init(rtRuntestsConfiguration $runConfiguration) { - - $this->testFiles = rtUtil::getTestList($this->testDirectory); - - foreach($this->testFiles as $testName) { - - if(!file_exists($testName)) { - echo $testName . " "; - echo rtText::get('invalidTestFileName'); - exit(); - } - - //Create a new test file object; - $testFile = new rtPhpTestFile(); - $testFile->doRead($testName); - $testFile->normaliseLineEndings(); - - if($testFile->arePreconditionsMet() ) { - //Create a new test case - $this->testCases[] = new rtPhpTest($testFile->getContents(), $testFile->getTestName(), $testFile->getSectionHeadings(), $runConfiguration); - } else { - $this->results[] = new rtTestResults(null, $testFile->getExitMessage(), $testFile->getTestName()); - } +class rtPhpTestGroup +{ + private $testDirectory; + private $testCases; + private $results; + + public function __construct(rtRuntestsConfiguration $runConfiguration, $directory) + { + $this->testDirectory = $directory; + $this->init($runConfiguration); } - } - public function runGroup(rtRuntestsConfiguration $runConfiguration) { - - foreach ($this->testCases as $testCase) { - - $testCase->executeTest($runConfiguration); - - $testResult = new rtTestResults($testCase); - $testResult->processResults($testCase, $runConfiguration); - $this->results[] = $testResult; + public function init(rtRuntestsConfiguration $runConfiguration) + { + $this->testFiles = rtUtil::getTestList($this->testDirectory); + + foreach ($this->testFiles as $testName) { + + if (!file_exists($testName)) { + echo $testName . " "; + echo rtText::get('invalidTestFileName'); + exit(); + } + + // Create a new test file object; + $testFile = new rtPhpTestFile(); + $testFile->doRead($testName); + $testFile->normaliseLineEndings(); + + if ($testFile->arePreconditionsMet() ) { + // Create a new test case + $this->testCases[] = new rtPhpTest($testFile->getContents(), $testFile->getTestName(), $testFile->getSectionHeadings(), $runConfiguration); + } else { + $this->results[] = new rtTestResults(null, $testFile->getExitMessage(), $testFile->getTestName()); + } + } } - } - - public function writeGroup() { - $testOutputWriter = rtTestOutputWriter::getInstance($this->results, 'list'); - $testOutputWriter->write($this->testDirectory); + public function runGroup(rtRuntestsConfiguration $runConfiguration) + { + foreach ($this->testCases as $testCase) { - } + $testCase->executeTest($runConfiguration); + + $testResult = new rtTestResults($testCase); + $testResult->processResults($testCase, $runConfiguration); + $this->results[] = $testResult; + } + } + public function writeGroup() + { + $testOutputWriter = rtTestOutputWriter::getInstance($this->results, 'list'); + $testOutputWriter->write($this->testDirectory); + } } ?> diff --git a/src/testrun/rtPhpTestRun.php b/src/testrun/rtPhpTestRun.php index f75a0be..a0122e2 100644 --- a/src/testrun/rtPhpTestRun.php +++ b/src/testrun/rtPhpTestRun.php @@ -1,100 +1,98 @@ -<?php - +i<?php /** * Main class for a test run * */ -class rtPhpTestRun { - - private $commandLineArguments; - - public function __construct($argv) { - $this->commandLineArguments = $argv; - } - - public function run() { - //Set SSH variables - - //Configure the test environment - - $runConfiguration = rtRuntestsConfiguration::getInstance($this->commandLineArguments); - $runConfiguration->configure(); +class rtPhpTestRun +{ + private $commandLineArguments; + public function __construct($argv) + { + $this->commandLineArguments = $argv; + } - if($runConfiguration->getSetting('TestDirectories') != null) { - foreach($runConfiguration->getSetting('TestDirectories') as $testDirectory) { - - //make list of subdirectories which contain tests, includes the top level directory - $subDirectories = rtUtil::getDirectoryList($testDirectory); - - //Run tests in each subdirectory in sequence - foreach ($subDirectories as $subDirectory) { - $testGroup = new rtPhpTestGroup($runConfiguration, $subDirectory); - $testGroup->runGroup($runConfiguration); - $testGroup->writeGroup(); - } - } - - //*have a directory or list of directories to test. - /* if (single directory) { - * if(contains sub-directories with .phpt files) { - * if (parallel) { - * initate parallel run - * } else { - * initaite sequential run - * } - * } else { - * initiate sequential run - * } - * } else { //multiple directories - * if (parallel) { - * initiate parallel (runs the list of dirs in parallel - * } else { - * run each directory in sequence - * } - * } - * - */ - } else { - if($runConfiguration->getSetting('TestFiles') == null) { - echo rtText::get('invalidTestFileName'); - exit(); - } else { - foreach($runConfiguration->getSetting('TestFiles') as $testName) { - - if(!file_exists($testName)) { - echo $testName . " "; - echo rtText::get('invalidTestFileName'); - exit(); - } - - //Read the test file - $testFile =new rtPhpTestFile(); - $testFile->doRead($testName); - $testFile->normaliseLineEndings($testName); - if($testFile->arePreconditionsMet()) { - - $testCase = new rtPhpTest($testFile->getContents(), $testFile->getTestName(), $testFile->getSectionHeadings(), $runConfiguration); - - //Setup and set the local environment for the test case - $testCase->executeTest($runConfiguration); - - - $results = new rtTestResults($testCase); - $results->processResults($testCase, $runConfiguration); - - - - } else { - $results = new rtTestResults(null, $testFile->getExitMessage(), $testFile->getTestName()); - } - $testOutputWriter = rtTestOutputWriter::getInstance(array($results), 'list'); - $testOutputWriter->write(); - - + public function run() + { + //Set SSH variables + + //Configure the test environment + $runConfiguration = rtRuntestsConfiguration::getInstance($this->commandLineArguments); + $runConfiguration->configure(); + + if ($runConfiguration->getSetting('TestDirectories') != null) { + + foreach ($runConfiguration->getSetting('TestDirectories') as $testDirectory) { + + //make list of subdirectories which contain tests, includes the top level directory + $subDirectories = rtUtil::getDirectoryList($testDirectory); + + //Run tests in each subdirectory in sequence + foreach ($subDirectories as $subDirectory) { + $testGroup = new rtPhpTestGroup($runConfiguration, $subDirectory); + $testGroup->runGroup($runConfiguration); + $testGroup->writeGroup(); + } + } + + //*have a directory or list of directories to test. + /* if (single directory) { + * if(contains sub-directories with .phpt files) { + * if (parallel) { + * initate parallel run + * } else { + * initaite sequential run + * } + * } else { + * initiate sequential run + * } + * } else { //multiple directories + * if (parallel) { + * initiate parallel (runs the list of dirs in parallel + * } else { + * run each directory in sequence + * } + * } + * + */ + } else { + + if ($runConfiguration->getSetting('TestFiles') == null) { + echo rtText::get('invalidTestFileName'); + exit(); + } else { + foreach ($runConfiguration->getSetting('TestFiles') as $testName) { + + if (!file_exists($testName)) { + echo $testName . " "; + echo rtText::get('invalidTestFileName'); + exit(); + } + + //Read the test file + $testFile = new rtPhpTestFile(); + $testFile->doRead($testName); + $testFile->normaliseLineEndings($testName); + + if ($testFile->arePreconditionsMet()) { + + $testCase = new rtPhpTest($testFile->getContents(), $testFile->getTestName(), $testFile->getSectionHeadings(), $runConfiguration); + + //Setup and set the local environment for the test case + $testCase->executeTest($runConfiguration); + + $results = new rtTestResults($testCase); + $results->processResults($testCase, $runConfiguration); + + } else { + $results = new rtTestResults(null, $testFile->getExitMessage(), $testFile->getTestName()); + } + + $testOutputWriter = rtTestOutputWriter::getInstance(array($results), 'list'); + $testOutputWriter->write(); + } + } } - } } - } } -?> \ No newline at end of file +?>
diff --git a/src/BuildClassMap.php b/src/BuildClassMap.php index 30e837d..7c6ff42 100644 --- a/src/BuildClassMap.php +++ b/src/BuildClassMap.php @@ -1,5 +1,4 @@ <?php - /* * This is stand alone code to build the file rtClassMap used by rtAutoload to find classes. * It assumes that all classes have the same name at the file name (less .php) and all are prefixed by 'rt' @@ -9,69 +8,70 @@ $map = new BuildClassMap(); $map->buildMap(); -class BuildClassMap { - - public function buildMap() { - - $thisDir = getcwd(); - - $sourceFiles = $this->getSourceList($thisDir); - - $mapString = '<?php'."\n"; - - $mapString .= ' $rtClassMap = array('."\n"; - sort($sourceFiles); - foreach($sourceFiles as $class) { - $relativeLocation = substr($class, strlen($thisDir.'/')); - - $className = basename($class, '.php'); - - $spaces = $this->getSpaces(strlen($className)); - - $mapString .= " ".'\''.$className.'\''. $spaces. " => ".'\''.$relativeLocation.'\','."\n"; - - } - $mapString .= ' );'."\n"; - $mapString .= '?>'."\n"; - - file_put_contents($thisDir.'/rtClassMap.php', $mapString); - - } - - public function getSpaces($length) { - $spaces = ""; - $nspaces = 40 - $length; - for($i=0; $i < $nspaces; $i++) { - $spaces .=" "; - } - return $spaces; - } +class BuildClassMap +{ + public function buildMap() + { + $thisDir = getcwd(); - public function getSourceList($aDirectory) - { - $files = array(); + $sourceFiles = $this->getSourceList($thisDir); - foreach (new PhpFilterIterator(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($aDirectory))) as $item) + $mapString = '<?php'."\n"; + $mapString .= ' $rtClassMap = array('."\n"; + + sort($sourceFiles); + + foreach ($sourceFiles as $class) { + $relativeLocation = substr($class, strlen($thisDir.'/')); + + $className = basename($class, '.php'); + + $spaces = $this->getSpaces(strlen($className)); + + $mapString .= " ".'\''.$className.'\''. $spaces. " => ".'\''.$relativeLocation.'\','."\n"; + } + + $mapString .= ' );'."\n"; + $mapString .= '?>'."\n"; + + file_put_contents($thisDir.'/rtClassMap.php', $mapString); + } + + public function getSpaces($length) { - $files[] = $item->getPathname(); + $spaces = ""; + $nspaces = 40 - $length; + + for ($i=0; $i < $nspaces; $i++) { + $spaces .=" "; + } + + return $spaces; } - return $files; - } + public function getSourceList($aDirectory) + { + $files = array(); -} + foreach (new PhpFilterIterator(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($aDirectory))) as $item) { + $files[] = $item->getPathname(); + } + return $files; + } +} class PhpFilterIterator extends FilterIterator { - public function accept() - { - if(substr($this->current(), -strlen('.php')) == '.php') { - if(substr(basename($this->current()), 0, strlen('rt')) == 'rt') { - return true; - } + public function accept() + { + if (substr($this->current(), -strlen('.php')) == '.php') { + if (substr(basename($this->current()), 0, strlen('rt')) == 'rt') { + return true; + } + } + + return false; } - return false; - } } -?> \ No newline at end of file +?> diff --git a/src/configuration/preconditions/rtIsProcOpenAvailable.php b/src/configuration/preconditions/rtIsProcOpenAvailable.php index 21bc802..ce3556c 100644 --- a/src/configuration/preconditions/rtIsProcOpenAvailable.php +++ b/src/configuration/preconditions/rtIsProcOpenAvailable.php @@ -13,7 +13,7 @@ class rtIsProcOpenAvailable extends rtPreCondition */ public function getMessage() { - return rtText::get('procOpenNotAvailable'); + return rtText::get('procOpenNotAvailable'); } /** @@ -24,7 +24,7 @@ class rtIsProcOpenAvailable extends rtPreCondition public function check(rtCommandLineOptions $commandLine = null, rtEnvironmentVariables $environmentVariables = null) { if (function_exists('proc_open')) { - return true; + return true; } return false; diff --git a/src/configuration/preconditions/rtIsTestFileSpecified.php b/src/configuration/preconditions/rtIsTestFileSpecified.php index bdf79eb..4dfd1e8 100644 --- a/src/configuration/preconditions/rtIsTestFileSpecified.php +++ b/src/configuration/preconditions/rtIsTestFileSpecified.php @@ -1,5 +1,4 @@ <?php - /** * Class for checking that a test file, or directory has been specified * @@ -25,20 +24,20 @@ class rtIsTestFileSpecified extends rtPreCondition */ public function check(rtCommandLineOptions $commandLine = null, rtEnvironmentVariables $environmentVariables = null) { - if($commandLine->hasOption('l')) { - return true; + if ($commandLine->hasOption('l')) { + return true; } - if($commandLine->hasOption('r')) { - return true; + if ($commandLine->hasOption('r')) { + return true; } - if($commandLine->getTestFilename() != null) { - return true; + if ($commandLine->getTestFilename() != null) { + return true; } - if($environmentVariables->hasVariable('TEST_PHP_USER')) { - return true; + if ($environmentVariables->hasVariable('TEST_PHP_USER')) { + return true; } return false; diff --git a/src/configuration/rtCommandLineOptions.php b/src/configuration/rtCommandLineOptions.php index 4a42880..30d699f 100644 --- a/src/configuration/rtCommandLineOptions.php +++ b/src/configuration/rtCommandLineOptions.php @@ -1,11 +1,10 @@ <?php - /** * Parse command line options * - * @package control - * @author Zoe Slattery <zoe.slattery@googlemail.com> - * @license PHP http://www.php.net/license/3_01.txt + * @package control + * @author Zoe Slattery <zoe.slattery@googlemail.com> + * @license PHP http://www.php.net/license/3_01.txt * */ class rtCommandLineOptions @@ -93,35 +92,35 @@ class rtCommandLineOptions */ public function parseCommandLineOptions($argv) { - for ($i=0; $i<count($argv); $i++) { - - if (!$this->isShortOption($argv[$i]) && !$this->isLongOption($argv[$i])) { - $this->testFilename[] = $argv[$i]; - continue; - } - - if ($this->isShortOption($argv[$i])) { - $option = substr($argv[$i], 1); - } else { - $option = substr($argv[$i], 2); - } - - if (!in_array($option, array_merge($this->shortOptions, $this->shortOptionsWithArgs, $this->longOptions, $this->longOptionsWithArgs))) { - throw new rtUnknownOptionException('Unknown option ' . $argv[$i]); - } - - if (in_array($option, array_merge($this->shortOptions, $this->longOptions))) { - $this->options[$option] = true; - continue; + for ($i=0; $i<count($argv); $i++) { + + if (!$this->isShortOption($argv[$i]) && !$this->isLongOption($argv[$i])) { + $this->testFilename[] = $argv[$i]; + continue; + } + + if ($this->isShortOption($argv[$i])) { + $option = substr($argv[$i], 1); + } else { + $option = substr($argv[$i], 2); + } + + if (!in_array($option, array_merge($this->shortOptions, $this->shortOptionsWithArgs, $this->longOptions, $this->longOptionsWithArgs))) { + throw new rtUnknownOptionException('Unknown option ' . $argv[$i]); + } + + if (in_array($option, array_merge($this->shortOptions, $this->longOptions))) { + $this->options[$option] = true; + continue; + } + + if (!$this->isValidOptionArg($argv, $i + 1)) { + throw new rtMissingArgumentException('Missing argument for command line option ' . $argv[$i]); + } + + $i++; + $this->options[$option] = $argv[$i]; } - - if (!$this->isValidOptionArg($argv, $i + 1)) { - throw new rtMissingArgumentException('Missing argument for command line option ' . $argv[$i]); - } - - $i++; - $this->options[$option] = $argv[$i]; - } } @@ -132,10 +131,11 @@ class rtCommandLineOptions */ public function isValidOptionArg($array, $index) { - if (!isset($array[$index])) { - return false; - } - return substr($array[$index], 0, 1) != '-'; + if (!isset($array[$index])) { + return false; + } + + return substr($array[$index], 0, 1) != '-'; } @@ -146,14 +146,15 @@ class rtCommandLineOptions */ protected function stripSpaces($argv) { - $result = array(); + $result = array(); - for ($i=1; $i<count($argv); $i++) { - if ($argv[$i] != "") { - $result[] = $argv[$i]; + for ($i=1; $i<count($argv); $i++) { + if ($argv[$i] != "") { + $result[] = $argv[$i]; + } } - } - return $result; + + return $result; } @@ -162,11 +163,11 @@ class rtCommandLineOptions */ public function getOption($option) { - if (!isset($this->options[$option])) { - return false; - } + if (!isset($this->options[$option])) { + return false; + } - return $this->options[$option]; + return $this->options[$option]; } diff --git a/src/configuration/rtEnvironmentVariables.php b/src/configuration/rtEnvironmentVariables.php index 227ab0a..eec63bd 100644 --- a/src/configuration/rtEnvironmentVariables.php +++ b/src/configuration/rtEnvironmentVariables.php @@ -30,11 +30,11 @@ class rtEnvironmentVariables static public function getInstance ($os = 'Unix') { - if ($os == 'Windows') { - return new rtWinEnvironmentVariables(); - } else { - return new rtUnixEnvironmentVariables(); - } + if ($os == 'Windows') { + return new rtWinEnvironmentVariables(); + } else { + return new rtUnixEnvironmentVariables(); + } } public function getUserSuppliedVariables() @@ -45,8 +45,8 @@ class rtEnvironmentVariables $this->environmentVariables = array(); } - foreach($this->userSuppliedVariables as $variable) { - if(getenv($variable)) { + foreach ($this->userSuppliedVariables as $variable) { + if (getenv($variable)) { $this->environmentVariables[$variable] = getenv($variable); } } diff --git a/src/configuration/rtIniAsCommandLineArgs.php b/src/configuration/rtIniAsCommandLineArgs.php index 1951b6a..5ed38cf 100644 --- a/src/configuration/rtIniAsCommandLineArgs.php +++ b/src/configuration/rtIniAsCommandLineArgs.php @@ -3,31 +3,31 @@ class rtIniAsCommandLineArgs { protected $iniOverwrites = array( - 'output_handler=', - 'open_basedir=', - 'safe_mode=0', - 'disable_functions=', - 'output_buffering=Off', - "error_reporting= 32767", - 'display_errors=1', - 'display_startup_errors=1', - 'log_errors=0', - 'html_errors=0', - 'track_errors=1', - 'report_memleaks=1', - 'report_zend_debug=0', - 'docref_root=', - 'docref_ext=.html', - 'error_prepend_string=', - 'error_append_string=', - 'auto_prepend_file=', - 'auto_append_file=', - 'magic_quotes_runtime=0', - 'ignore_repeated_errors=0', - 'unicode.runtime_encoding=ISO-8859-1', - 'unicode.script_encoding=UTF-8', - 'unicode.output_encoding=UTF-8', - 'unicode.from_error_mode=U_INVALID_SUBSTITUTE', + 'output_handler=', + 'open_basedir=', + 'safe_mode=0', + 'disable_functions=', + 'output_buffering=Off', + "error_reporting= 32767", + 'display_errors=1', + 'display_startup_errors=1', + 'log_errors=0', + 'html_errors=0', + 'track_errors=1', + 'report_memleaks=1', + 'report_zend_debug=0', + 'docref_root=', + 'docref_ext=.html', + 'error_prepend_string=', + 'error_append_string=', + 'auto_prepend_file=', + 'auto_append_file=', + 'magic_quotes_runtime=0', + 'ignore_repeated_errors=0', + 'unicode.runtime_encoding=ISO-8859-1', + 'unicode.script_encoding=UTF-8', + 'unicode.output_encoding=UTF-8', + 'unicode.from_error_mode=U_INVALID_SUBSTITUTE', ); protected $basePhpDArgs; @@ -50,8 +50,8 @@ class rtIniAsCommandLineArgs */ public function settingsToArguments($array, $args="") { - foreach($array as $setting) { - if($this->isValidSetting($setting)) { + foreach ($array as $setting) { + if ($this->isValidSetting($setting)) { $setting = $this->stripSpaces($setting); $args .= " -d \"$setting\""; } else { @@ -78,15 +78,15 @@ class rtIniAsCommandLineArgs } //test for == - if(strncmp($parts[1], '=', 1) === 0) { + if (strncmp($parts[1], '=', 1) === 0) { return false; } //test for a=b=c - if(strstr($parts[1], '=') == false) { - return true; + if (strstr($parts[1], '=') == false) { + return true; } else { - return false; + return false; } } diff --git a/src/configuration/rtPreConditionList.php b/src/configuration/rtPreConditionList.php index 2eab2e7..7e9bd7e 100644 --- a/src/configuration/rtPreConditionList.php +++ b/src/configuration/rtPreConditionList.php @@ -37,10 +37,11 @@ abstract class rtPreConditionList * @param rtEnvironmentVariables $environmentVariables * @return boolean */ - public function check($commandLine, $environmentVariables) { - foreach($this->preConditions as $preCon) { + public function check($commandLine, $environmentVariables) + { + foreach ($this->preConditions as $preCon) { $p = new $preCon; - if(!$p->check($commandLine, $environmentVariables)) { + if (!$p->check($commandLine, $environmentVariables)) { die($p->getMessage()); } } @@ -56,7 +57,7 @@ abstract class rtPreConditionList */ public function hasPreCondition($pc) { - if(in_array($pc, $this->preConditions)) { + if (in_array($pc, $this->preConditions)) { return true; } diff --git a/src/configuration/rtRuntestsConfiguration.php b/src/configuration/rtRuntestsConfiguration.php index 37a5b36..cc58310 100644 --- a/src/configuration/rtRuntestsConfiguration.php +++ b/src/configuration/rtRuntestsConfiguration.php @@ -1,19 +1,18 @@ <?php - /** * Contains onfiguration for test run. Includes: * Command line option, environment variables, ini overrides and settings which are * derived from one or more command line options or environment variables. * */ - abstract class rtRuntestsConfiguration { + protected $commandLineArgs; + private $settings; private $setters; private $environmentVariables; private $commandLine; - protected $commandLineArgs; private $settingNames = array ( 'CurrentDirectory' => 'rtCurrentDirectorySetting', @@ -48,14 +47,12 @@ abstract class rtRuntestsConfiguration $preConditionList = rtPreConditionList::getInstance(); $preConditionList->check($this->commandLine, $this->environmentVariables); - //set configuration - foreach($this->settingNames as $name => $setting) { + foreach ($this->settingNames as $name => $setting) { $this->setters[$name] = new $setting($this); } - - foreach($this->settingNames as $name => $setting) { + foreach ($this->settingNames as $name => $setting) { $methodName = 'set' . $name; $this->$methodName(); } @@ -79,7 +76,8 @@ abstract class rtRuntestsConfiguration * Sets the directory that run-tests was started from * */ - private function setCurrentDirectory() { + private function setCurrentDirectory() + { $this->settings['CurrentDirectory']= $this->setters['CurrentDirectory']->get(); } @@ -87,7 +85,8 @@ abstract class rtRuntestsConfiguration * Sets the directory that run-tests is run from * */ - private function setWorkingDirectory() { + private function setWorkingDirectory() + { $this->settings['WorkingDirectory']= $this->setters['WorkingDirectory']->get(); } @@ -95,7 +94,8 @@ abstract class rtRuntestsConfiguration * Sets the PHP executable being used to run teh tests * */ - private function setPhpExecutable() { + private function setPhpExecutable() + { $this->settings['PhpExecutable']= $this->setters['PhpExecutable']->get(); } @@ -103,7 +103,8 @@ abstract class rtRuntestsConfiguration * Sets the PHP GGI executable being used to run the tests * */ - private function setPhpCgiExecutable() { + private function setPhpCgiExecutable() + { $this->settings['PhpCgiExecutable']= $this->setters['PhpCgiExecutable']->get(); } @@ -111,15 +112,17 @@ abstract class rtRuntestsConfiguration * Sets the log format * */ - private function setLogFormat() { - $this->settings['LogFormat']= $this->setters['LogFormat']->get(); + private function setLogFormat() + { + $this->settings['LogFormat']= $this->setters['LogFormat']->get(); } /** * Sets the command line arguments for PHP * */ - private function setPhpCommandLineArguments() { + private function setPhpCommandLineArguments() + { $this->settings['PhpCommandLineArguments']= $this->setters['PhpCommandLineArguments']->get(); } @@ -127,8 +130,9 @@ abstract class rtRuntestsConfiguration * Sets the names of directories to be tested * */ - private function setTestDirectories() { - $this->settings['TestDirectories'] = $this->setters['TestDirectories']->get(); + private function setTestDirectories() + { + $this->settings['TestDirectories'] = $this->setters['TestDirectories']->get(); } /** @@ -136,11 +140,11 @@ abstract class rtRuntestsConfiguration * * @param array $testFiles */ - private function setTestFiles() { - $this->settings['TestFiles'] = $this->setters['TestFiles']->get(); + private function setTestFiles() + { + $this->settings['TestFiles'] = $this->setters['TestFiles']->get(); } - /** * Returns the value of a setting * @@ -148,39 +152,44 @@ abstract class rtRuntestsConfiguration * @param mixed (may be array or string) */ - public function getSetting($settingName) { - return $this->settings[$settingName]; + public function getSetting($settingName) + { + return $this->settings[$settingName]; } - /** * Returns the entire settings array * * @return array $settings */ - public function getSettings() { - return $this->settings; + public function getSettings() + { + return $this->settings; } - public function getEnvironmentVariable($name) { - return $this->environmentVariables->getVariable($name); + public function getEnvironmentVariable($name) + { + return $this->environmentVariables->getVariable($name); } - public function getEnvironmentVariables() { - return $this->environmentVariables->getVariables(); + public function getEnvironmentVariables() + { + return $this->environmentVariables->getVariables(); } - public function hasCommandLineOption($option) { - return $this->commandLine->hasOption($option); + public function hasCommandLineOption($option) + { + return $this->commandLine->hasOption($option); } - public function getCommandLineOption($option) { - return $this->commandLine->getOption($option); + public function getCommandLineOption($option) + { + return $this->commandLine->getOption($option); } - - public function hasEnvironmentVariable($name) { - return $this->environmentVariables->hasVariable($name); + public function hasEnvironmentVariable($name) + { + return $this->environmentVariables->hasVariable($name); } /** @@ -190,12 +199,14 @@ abstract class rtRuntestsConfiguration * @param unknown_type $value * @return unknown */ - public function setEnvironmentVariable($name, $value) { - $this->environmentVariables->setVariable($name, $value); + public function setEnvironmentVariable($name, $value) + { + $this->environmentVariables->setVariable($name, $value); } - public function getTestFilename() { - return $this->commandLine->getTestFilename(); + public function getTestFilename() + { + return $this->commandLine->getTestFilename(); } } ?> diff --git a/src/configuration/rtSetting.php b/src/configuration/rtSetting.php index 42dc71c..30d10d2 100644 --- a/src/configuration/rtSetting.php +++ b/src/configuration/rtSetting.php @@ -6,7 +6,8 @@ */ abstract class rtSetting { - public function __construct(rtRuntestsConfiguration $configuration) { + public function __construct(rtRuntestsConfiguration $configuration) + { $this->init($configuration); } diff --git a/src/configuration/settings/rtPhpCgiExecutableSetting.php b/src/configuration/settings/rtPhpCgiExecutableSetting.php index 728b95c..47f0912 100644 --- a/src/configuration/settings/rtPhpCgiExecutableSetting.php +++ b/src/configuration/settings/rtPhpCgiExecutableSetting.php @@ -23,7 +23,7 @@ class rtPhpCgiExecutableSetting extends rtSetting } if ($configuration->hasEnvironmentVariable('TEST_PHP_CGI_EXECUTABLE')) { - if($configuration->getEnvironmentVariable('TEST_PHP_CGI_EXECUTABLE') == 'auto') { + if ($configuration->getEnvironmentVariable('TEST_PHP_CGI_EXECUTABLE') == 'auto') { $this->phpCgiExecutable = $workingDir . self::SAPI_CGI; } else { $this->phpCgiExecutable = $configuration->getEnvironmentVariable('TEST_PHP_CGI_EXECUTABLE'); diff --git a/src/configuration/settings/rtPhpCommandLineArgSetting.php b/src/configuration/settings/rtPhpCommandLineArgSetting.php index d502d4d..d5eee8c 100644 --- a/src/configuration/settings/rtPhpCommandLineArgSetting.php +++ b/src/configuration/settings/rtPhpCommandLineArgSetting.php @@ -28,7 +28,8 @@ class rtPhpCommandLineArgSetting extends rtSetting * Supply commandline arguments setting to the run configuration * */ - public function get() { + public function get() + { return $this->phpCommandLineArguments; } } diff --git a/src/configuration/settings/rtPhpExecutableSetting.php b/src/configuration/settings/rtPhpExecutableSetting.php index b24bc30..08beed8 100644 --- a/src/configuration/settings/rtPhpExecutableSetting.php +++ b/src/configuration/settings/rtPhpExecutableSetting.php @@ -24,7 +24,7 @@ class rtPhpExecutableSetting extends rtSetting if ($configuration->hasEnvironmentVariable('TEST_PHP_EXECUTABLE')) { - if($configuration->getEnvironmentVariable('TEST_PHP_EXECUTABLE') == 'auto') { + if ($configuration->getEnvironmentVariable('TEST_PHP_EXECUTABLE') == 'auto') { $this->phpExecutable = $workingDir.self::SAPI_CLI; } else { $this->phpExecutable = $configuration->getEnvironmentVariable('TEST_PHP_EXECUTABLE'); diff --git a/src/configuration/settings/rtTestDirectorySetting.php b/src/configuration/settings/rtTestDirectorySetting.php index 6f572db..97c6deb 100644 --- a/src/configuration/settings/rtTestDirectorySetting.php +++ b/src/configuration/settings/rtTestDirectorySetting.php @@ -20,16 +20,16 @@ class rtTestDirectorySetting extends rtSetting { $fileArray = $configuration->getTestFilename(); - foreach($fileArray as $file) { - if( is_dir($file)) { + foreach ($fileArray as $file) { + if (is_dir($file)) { $this->testDir[]= $file; } } - if($configuration->hasEnvironmentVariable('TEST_PHP_USER')) { + if ($configuration->hasEnvironmentVariable('TEST_PHP_USER')) { $fileArray = trim($configuration->getEnvironmentVariable('TEST_PHP_USER')); - foreach($fileArray as $file) { - if( is_dir($file)) { + foreach ($fileArray as $file) { + if (is_dir($file)) { $this->testDir[]= $file; } } @@ -42,7 +42,7 @@ class rtTestDirectorySetting extends rtSetting */ public function get() { - return $this->testDir; + return $this->testDir; } } ?> diff --git a/src/configuration/settings/rtTestFileSetting.php b/src/configuration/settings/rtTestFileSetting.php index 1146663..08b2ac4 100644 --- a/src/configuration/settings/rtTestFileSetting.php +++ b/src/configuration/settings/rtTestFileSetting.php @@ -16,31 +16,32 @@ class rtTestFileSetting extends rtSetting * @param rtCommandLine $commandLine * */ - public function init(rtRuntestsConfiguration $configuration) { + public function init(rtRuntestsConfiguration $configuration) + { $fileArray = $configuration->getTestFilename(); - foreach($fileArray as $fn) { - if( !is_dir($fn) && substr($fn, -5) == ".phpt") { + foreach ($fileArray as $fn) { + if (!is_dir($fn) && substr($fn, -5) == ".phpt") { $this->testFiles[] = $fn; } } - if($configuration->hasCommandLineOption('l')) { + if ($configuration->hasCommandLineOption('l')) { $fileArray = file($configuration->getCommandLineOption('l')); - foreach($fileArray as $file) { - if(substr(trim($file), -5) == ".phpt") { + foreach ($fileArray as $file) { + if (substr(trim($file), -5) == ".phpt") { $this->testFiles[] = trim($file); } } } - if($configuration->hasCommandLineOption('r')) { - $fileArray = file($configuration->getCommandLineOption('r')); - foreach($fileArray as $file) { - if(substr(trim($file), -5) == ".phpt") { - $this->testFiles[] = trim($file); + if ($configuration->hasCommandLineOption('r')) { + $fileArray = file($configuration->getCommandLineOption('r')); + foreach ($fileArray as $file) { + if (substr(trim($file), -5) == ".phpt") { + $this->testFiles[] = trim($file); + } } - } } } @@ -48,7 +49,8 @@ class rtTestFileSetting extends rtSetting * Reurns a list of test files * */ - public function get() { + public function get() + { return $this->testFiles; } } diff --git a/src/configuration/settings/rtWorkingDirectorySetting.php b/src/configuration/settings/rtWorkingDirectorySetting.php index 2c3408c..a54b2c3 100644 --- a/src/configuration/settings/rtWorkingDirectorySetting.php +++ b/src/configuration/settings/rtWorkingDirectorySetting.php @@ -15,7 +15,7 @@ class rtWorkingDirectorySetting extends rtSetting */ public function init(rtRuntestsConfiguration $configuration) { - if($configuration->hasEnvironmentVariable('TEST_PHP_SRCDIR')) { + if ($configuration->hasEnvironmentVariable('TEST_PHP_SRCDIR')) { $this->workingDirectory = $configuration->getEnvironmentVariable('TEST_PHP_SRCDIR'); } else { $this->workingDirectory = getcwd(); diff --git a/src/configuration/unix/rtUnixConfiguration.php b/src/configuration/unix/rtUnixConfiguration.php index bd97d12..15a9441 100644 --- a/src/configuration/unix/rtUnixConfiguration.php +++ b/src/configuration/unix/rtUnixConfiguration.php @@ -1,16 +1,15 @@ <?php - /** * Class to adapt global environment to Unix * */ - class rtUnixConfiguration extends rtRuntestsConfiguration - { - - public function __construct($cmdlineArgs) { - $this->commandLineArgs = $cmdlineArgs; - $this->init(); - } +class rtUnixConfiguration extends rtRuntestsConfiguration +{ + public function __construct($cmdlineArgs) + { + $this->commandLineArgs = $cmdlineArgs; + $this->init(); + } /** * Adapts the configuration to Unix @@ -19,6 +18,5 @@ protected function adaptConfiguration() { } - } - +} ?> diff --git a/src/configuration/unix/rtUnixEnvironmentVariables.php b/src/configuration/unix/rtUnixEnvironmentVariables.php index 4d660fb..0a15deb 100644 --- a/src/configuration/unix/rtUnixEnvironmentVariables.php +++ b/src/configuration/unix/rtUnixEnvironmentVariables.php @@ -1,20 +1,17 @@ <?php - /** * Class to adapt global environment to Unix * */ - class rtUnixEnvironmentVariables extends rtEnvironmentVariables - { - +class rtUnixEnvironmentVariables extends rtEnvironmentVariables +{ /** * Adapts the global environment to Unix * */ public function adaptEnvironment() { - array_push($this->userSuppliedVariables, 'TEST_PHP_PARALLEL'); + array_push($this->userSuppliedVariables, 'TEST_PHP_PARALLEL'); } - } - -?> \ No newline at end of file +} +?> diff --git a/src/configuration/unix/rtUnixPreConditionList.php b/src/configuration/unix/rtUnixPreConditionList.php index 6ba8b34..a969d4a 100644 --- a/src/configuration/unix/rtUnixPreConditionList.php +++ b/src/configuration/unix/rtUnixPreConditionList.php @@ -1,19 +1,17 @@ <?php - /** * Unix specific pre-condition list * */ -class rtUnixPreConditionList extends rtPreconditionList{ - - - /** - * Adapts the list of pre-conditions to include those that relate to Unix only - * - */ - public function adaptList() { - array_push( $this->preConditions, 'rtIfParallelHasPcntl'); - } +class rtUnixPreConditionList extends rtPreconditionList +{ + /** + * Adapts the list of pre-conditions to include those that relate to Unix only + * + */ + public function adaptList() + { + array_push($this->preConditions, 'rtIfParallelHasPcntl'); + } } - -?> \ No newline at end of file +?> diff --git a/src/configuration/unix/rtUnixSettingList.php b/src/configuration/unix/rtUnixSettingList.php index 04f44b9..b95743f 100644 --- a/src/configuration/unix/rtUnixSettingList.php +++ b/src/configuration/unix/rtUnixSettingList.php @@ -1,18 +1,16 @@ <?php - /** * Unix specific setting list * */ -class rtUnixSettingList extends rtSettingList{ - - - /** - * Adapt the list of settings for things that only need to be set on Unix - * - */ - public function adaptList() { - - } +class rtUnixSettingList extends rtSettingList +{ + /** + * Adapt the list of settings for things that only need to be set on Unix + * + */ + public function adaptList() + { + } } -?> \ No newline at end of file +?> diff --git a/src/configuration/windows/rtWinConfiguration.php b/src/configuration/windows/rtWinConfiguration.php index a2a2006..ed5f27c 100644 --- a/src/configuration/windows/rtWinConfiguration.php +++ b/src/configuration/windows/rtWinConfiguration.php @@ -1,15 +1,16 @@ <?php - /** * Class to adapt global environment to Windows * */ - class rtWinConfiguration extends rtRuntestsConfiguration - { - public function __construct($cmdlineArgs) { - $this->commandLineArgs = $cmdlineArgs; - $this->init(); - } +class rtWinConfiguration extends rtRuntestsConfiguration +{ + public function __construct($cmdlineArgs) + { + $this->commandLineArgs = $cmdlineArgs; + $this->init(); + } + /** * Adapt the environmnet to Windows * @@ -17,6 +18,5 @@ protected function adaptConfiguration() { } - } - +} ?> diff --git a/src/configuration/windows/rtWinEnvironmentVariables.php b/src/configuration/windows/rtWinEnvironmentVariables.php index a44578c..21e8678 100644 --- a/src/configuration/windows/rtWinEnvironmentVariables.php +++ b/src/configuration/windows/rtWinEnvironmentVariables.php @@ -1,20 +1,17 @@ <?php - /** * Class to adapt environment variable list to Windows * */ - class rtWinEnvironmentVariables extends rtEnvironmentVariables - { - +class rtWinEnvironmentVariables extends rtEnvironmentVariables +{ /** * Adapts the environment variables for Windows * */ public function adaptEnvironment() { - array_push($this->userSuppliedVariables, 'SystemRoot'); + array_push($this->userSuppliedVariables, 'SystemRoot'); } - } - -?> \ No newline at end of file +} +?> diff --git a/src/configuration/windows/rtWinPreConditionList.php b/src/configuration/windows/rtWinPreConditionList.php index 19ed2fe..6ef4408 100644 --- a/src/configuration/windows/rtWinPreConditionList.php +++ b/src/configuration/windows/rtWinPreConditionList.php @@ -1,19 +1,16 @@ <?php - /** * Windows specific pre-condition list * */ -class rtWinPreConditionList extends rtPreconditionList{ - - - /** - * Extends list of pre-conditions for those that are specific to Windows - * - */ - public function adaptList() { - - } - +class rtWinPreConditionList extends rtPreconditionList +{ + /** + * Extends list of pre-conditions for those that are specific to Windows + * + */ + public function adaptList() + { + } } -?> \ No newline at end of file +?> diff --git a/src/configuration/windows/rtWinSettingList.php b/src/configuration/windows/rtWinSettingList.php index 762859e..0b641eb 100644 --- a/src/configuration/windows/rtWinSettingList.php +++ b/src/configuration/windows/rtWinSettingList.php @@ -1,20 +1,16 @@ <?php - /** * Windows specific setting list * */ -class rtWinSettingList extends rtSettingList{ - - - /** - * Adapt the list to include things that only need to be set on Windows - * - */ - public function adaptList() { - - } - +class rtWinSettingList extends rtSettingList +{ + /** + * Adapt the list to include things that only need to be set on Windows + * + */ + public function adaptList() + { + } } - -?> \ No newline at end of file +?> diff --git a/src/rtText.php b/src/rtText.php index 3b3cc6a..886b123 100644 --- a/src/rtText.php +++ b/src/rtText.php @@ -1,10 +1,16 @@ <?php /** - * + * rtText reads named texts from texts/ subdirectory. */ class rtText { + /** + * Get a named text from texts/ subdirectory. + * + * @param string $name Text name to return + * @return string + */ public static function get($name) { $filename = dirname(__FILE__) . '/texts/' . $name . '.txt'; diff --git a/src/testcase/exceptions/rtCodeRunnerException.php b/src/testcase/exceptions/rtCodeRunnerException.php index 23fe087..42e90f3 100644 --- a/src/testcase/exceptions/rtCodeRunnerException.php +++ b/src/testcase/exceptions/rtCodeRunnerException.php @@ -1,5 +1,8 @@ <?php -class rtPhpRunnerException extends RunTimeException { - +/** + * + */ +class rtPhpRunnerException extends RunTimeException +{ } -?> \ No newline at end of file +?> diff --git a/src/testcase/output/rtTestOutputWriterList.php b/src/testcase/output/rtTestOutputWriterList.php index f309499..5b0249b 100644 --- a/src/testcase/output/rtTestOutputWriterList.php +++ b/src/testcase/output/rtTestOutputWriterList.php @@ -1,50 +1,50 @@ <?php - - - -class rtTestOutputWriterList extends rtTestOutputWriter { - - protected $testOutput = array(); - - public function __construct(array $testResults) { - $this->init($testResults); - } - - /** - * - * - * @param array of rtTestResults - * - */ - public function init (array $testResults) { - foreach ($testResults as $testResult) { - $outputString = ""; - $testStatus = $testResult->getStatus(); - ksort($testStatus); - //Status can be PASS and WARN or FAIL and WARN. I think these are the olny two combinations - //but there may be more - foreach($testStatus as $status => $message){ - $outputString .= strtoupper($status); - $outputString .= " ". $message; - } - $outputString .= " ". $testResult->getTitle(); - $outputString .= " [". $testResult->getName().".phpt]"; - $this->testOutput[] = $outputString; +/** + * + */ +class rtTestOutputWriterList extends rtTestOutputWriter +{ + protected $testOutput = array(); + + public function __construct(array $testResults) + { + $this->init($testResults); } - } - - public function write($testDirectory = null) { - if($testDirectory != null) { - echo "\n\nTest output for tests in ". $testDirectory."\n"; - } - sort ($this->testOutput); - foreach($this->testOutput as $line) { - echo $line ."\n"; + /** + * + * + * @param array of rtTestResults + * + */ + public function init (array $testResults) + { + foreach ($testResults as $testResult) { + $outputString = ""; + $testStatus = $testResult->getStatus(); + ksort($testStatus); + //Status can be PASS and WARN or FAIL and WARN. I think these are the olny two combinations + //but there may be more + foreach ($testStatus as $status => $message) { + $outputString .= strtoupper($status); + $outputString .= " " . $message; + } + $outputString .= " " . $testResult->getTitle(); + $outputString .= " [" . $testResult->getName() . ".phpt]"; + $this->testOutput[] = $outputString; + } } - } - + public function write($testDirectory = null) + { + if ($testDirectory != null) { + echo "\n\nTest output for tests in " . $testDirectory . "\n"; + } + sort($this->testOutput); + foreach ($this->testOutput as $line) { + echo $line ."\n"; + } + } } -?> \ No newline at end of file +?> diff --git a/src/testcase/output/rtTestOutputWriterXML.php b/src/testcase/output/rtTestOutputWriterXML.php index 4251441..410c9eb 100644 --- a/src/testcase/output/rtTestOutputWriterXML.php +++ b/src/testcase/output/rtTestOutputWriterXML.php @@ -1,20 +1,15 @@ <?php - - -class rtTestOutputWriterXML extends rtTestOutputWriter { - - -public function assemble(rtPhpTest $testCase) { - - - } - - public function write() { - - - - } - - +/** + * + */ +class rtTestOutputWriterXML extends rtTestOutputWriter +{ + public function assemble(rtPhpTest $testCase) + { + } + + public function write() + { + } } -?> \ No newline at end of file +?> diff --git a/src/testcase/preconditions/rtHasMandatorySections.php b/src/testcase/preconditions/rtHasMandatorySections.php index 6b0dcaa..fd05ad9 100644 --- a/src/testcase/preconditions/rtHasMandatorySections.php +++ b/src/testcase/preconditions/rtHasMandatorySections.php @@ -1,33 +1,37 @@ <?php +/** + * + */ +class rtHasMandatorySections implements rtTestPreCondition +{ + /** + * Return the message associated with a missing test section + * + * @return text + */ + public function getMessage() + { + return rtText::get('missingTestSection'); + } -class rtHasMandatorySections implements rtTestPreCondition { - - /** Return the message associated with a missing test section - * - * @return text - */ - public function getMessage() { - return rtText::get('missingTestSection'); - } - - - /** - * Check that the test has valid sections - * - * @param array $testCaseContents - * @return boolean - */ - public function isMet(array $sectionHeadings) { + /** + * Check that the test has valid sections + * + * @param array $testCaseContents + * @return boolean + */ + public function isMet(array $sectionHeadings) + { - if(in_array('TEST', $sectionHeadings )) { - if(in_array('FILE', $sectionHeadings ) || in_array('FILEOF', $sectionHeadings) || in_array('FILE_EXTERNAL', $sectionHeadings)) { - if(in_array('EXPECT', $sectionHeadings ) || in_array('EXPECTF', $sectionHeadings) || in_array('EXPECTREGEX', $sectionHeadings)) { - return true; + if (in_array('TEST', $sectionHeadings )) { + if (in_array('FILE', $sectionHeadings ) || in_array('FILEOF', $sectionHeadings) || in_array('FILE_EXTERNAL', $sectionHeadings)) { + if (in_array('EXPECT', $sectionHeadings ) || in_array('EXPECTF', $sectionHeadings) || in_array('EXPECTREGEX', $sectionHeadings)) { + return true; + } + } } - } - } - return false; - } - + + return false; + } } ?> diff --git a/src/testcase/preconditions/rtHasNoDuplicateSections.php b/src/testcase/preconditions/rtHasNoDuplicateSections.php index 7c5e4ae..78e14df 100644 --- a/src/testcase/preconditions/rtHasNoDuplicateSections.php +++ b/src/testcase/preconditions/rtHasNoDuplicateSections.php @@ -1,30 +1,34 @@ <?php -class rtHasNoDuplicateSections implements rtTestPreCondition { - - - /** Return the message associated with a duplicate test section - * - * @return text - */ - public function getMessage() { - return rtText::get('duplicateTestSection'); - } - +/** + * + */ +class rtHasNoDuplicateSections implements rtTestPreCondition +{ + /** + * Return the message associated with a duplicate test section + * + * @return text + */ + public function getMessage() + { + return rtText::get('duplicateTestSection'); + } - /** - * Check that the PHP executable is a valid executable - * - * @param array $testCaseContents - * @return boolean - */ - public function isMet(array $sectionHeadings) { + /** + * Check that the PHP executable is a valid executable + * + * @param array $testCaseContents + * @return boolean + */ + public function isMet(array $sectionHeadings) + { + $uniqueSections = array_unique($sectionHeadings); + + if (count($uniqueSections) < count($sectionHeadings)) { + return false; + } - $uniqueSections = array_unique($sectionHeadings); - - if (count($uniqueSections) < count($sectionHeadings)) { - return false; + return true; } - return true; - } } -?> \ No newline at end of file +?> diff --git a/src/testcase/preconditions/rtIsSectionImplemented.php b/src/testcase/preconditions/rtIsSectionImplemented.php index 66b3ec6..a99acae 100644 --- a/src/testcase/preconditions/rtIsSectionImplemented.php +++ b/src/testcase/preconditions/rtIsSectionImplemented.php @@ -1,46 +1,47 @@ <?php +/** + * + */ +class rtIsSectionImplemented implements rtTestPreCondition +{ + private $sectionMap = array( + 'TEST' => 'rtTestHeaderSection', + 'SKIPIF' => 'rtSkipIfSection', + 'FILE' => 'rtFileSection', + 'EXPECT' => 'rtExpectSection', + 'EXPECTF' => 'rtExpectFSection', + 'EXPECTREGEX' => 'rtExpectRegexSection', + 'INI' => 'rtIniSection', + 'ARGS' => 'rtArgsSection', + 'ENV' => 'rtEnvSection', + 'CREDITS' => 'rtCreditsSection', + 'CLEAN' => 'rtCleanSection', + 'XFAIL' => 'rtXfailSection', + ); + /** Return the message associated with an unimplemented test section + * + * @return text + */ + public function getMessage() + { + return rtText::get('sectionNotImplemented'); + } -class rtIsSectionImplemented implements rtTestPreCondition { - - private $sectionMap = array ( - 'TEST' => 'rtTestHeaderSection', - 'SKIPIF' => 'rtSkipIfSection', - 'FILE' => 'rtFileSection', - 'EXPECT' => 'rtExpectSection', - 'EXPECTF' => 'rtExpectFSection', - 'EXPECTREGEX' => 'rtExpectRegexSection', - 'INI' => 'rtIniSection', - 'ARGS' => 'rtArgsSection', - 'ENV' => 'rtEnvSection', - 'CREDITS' => 'rtCreditsSection', - 'CLEAN' => 'rtCleanSection', - 'XFAIL' => 'rtXfailSection', - ); - - - /** Return the message associated with an unimplemented test section - * - * @return text - */ - public function getMessage() { - return rtText::get('sectionNotImplemented'); - } - - - /** - * Check that the section has been implemented - * - * @param array $testCaseContents - * @return boolean - */ - public function isMet(array $sectionHeaders) { - foreach($sectionHeaders as $section) { - if(!array_key_exists($section, $this->sectionMap)) { - return false; + /** + * Check that the section has been implemented + * + * @param array $testCaseContents + * @return boolean + */ + public function isMet(array $sectionHeaders) + { + foreach ($sectionHeaders as $section) { + if (!array_key_exists($section, $this->sectionMap)) { + return false; + } } + return true; } - return true; - } } -?> \ No newline at end of file +?> diff --git a/src/testcase/preconditions/rtIsValidSectionName.php b/src/testcase/preconditions/rtIsValidSectionName.php index 75fdd00..2a0ff47 100644 --- a/src/testcase/preconditions/rtIsValidSectionName.php +++ b/src/testcase/preconditions/rtIsValidSectionName.php @@ -1,59 +1,61 @@ <?php +/** + * + */ +class rtIsValidSectionName implements rtTestPreCondition +{ + private $validSectionNames = array( + 'TEST', + 'SKIPIF', + 'FILE', + 'FILEEOF', + 'FILE_EXTERNAL', + 'EXPECT', + 'EXPECTF', + 'EXPECTREGEX', + 'INI', + 'ARGS', + 'ENV', + 'XFAIL', + 'STDIN', + 'CREDITS', + 'CLEAN', + 'POST', + 'GZIP_POST', + 'DEFLATE_POST', + 'POST_RAW', + 'GET', + 'COOKIE', + 'REDIRECTTEST', + 'HEADERS', + 'EXPECTHEADERS', + '===DONE===', + ); + /** + * Return the message associated with a duplicate test section + * + * @return text + */ + public function getMessage() + { + return rtText::get('invalidTestSection'); + } -class rtIsValidSectionName implements rtTestPreCondition { - - - private $validSectionNames = array ( - 'TEST', - 'SKIPIF', - 'FILE', - 'FILEEOF', - 'FILE_EXTERNAL', - 'EXPECT', - 'EXPECTF', - 'EXPECTREGEX', - 'INI', - 'ARGS', - 'ENV', - 'XFAIL', - 'STDIN', - 'CREDITS', - 'CLEAN', - 'POST', - 'GZIP_POST', - 'DEFLATE_POST', - 'POST_RAW', - 'GET', - 'COOKIE', - 'REDIRECTTEST', - 'HEADERS', - 'EXPECTHEADERS', - '===DONE===', - ); - - /** Return the message associated with a duplicate test section - * - * @return text - */ - public function getMessage() { - return rtText::get('invalidTestSection'); - } - - - /** - * Check that the section name is valid - * - * @param array $testCaseContents - * @return boolean - */ - public function isMet(array $sectionHeadings) { - foreach ($sectionHeadings as $section) { - if(!in_array($section, $this->validSectionNames)) { - return false; - } - return true; + /** + * Check that the section name is valid + * + * @param array $testCaseContents + * @return boolean + */ + public function isMet(array $sectionHeadings) + { + foreach ($sectionHeadings as $section) { + if (!in_array($section, $this->validSectionNames)) { + return false; + } + return true; + } } - } } - ?> \ No newline at end of file +?> diff --git a/src/testcase/rtPhpRunner.php b/src/testcase/rtPhpRunner.php index 0d208b5..31575db 100644 --- a/src/testcase/rtPhpRunner.php +++ b/src/testcase/rtPhpRunner.php @@ -1,89 +1,84 @@ <?php - - - /** * Execution of PHP code. * */ -class rtPhpRunner { - - private $phpCommand; - private $environmentVariables; - private $currentWorkingDirectory; - private $stdin; - private $timeOut; - - - public function __construct($phpCommand, $environmentVariables, $currentWorkingDirectory, $stdin = null, $timeOut = 60) { - $this->phpCommand = $phpCommand; - $this->environmentVariables = $environmentVariables; - $this->currentWorkingDirectory = $currentWorkingDirectory; - $this->timeOut = $timeOut; - $this->stdin = $stdin; - } - - - /** - * Runs the PHP code. - * - * @return string - the output from the code - */ - public function runphp() - { - $data = ''; - - $proc = proc_open($this->phpCommand, array( - 0 => array('pipe', 'r'), - 1 => array('pipe', 'w'), - 2 => array('pipe', 'w') - ), $pipes, $this->currentWorkingDirectory, $this->environmentVariables, array('suppress_errors' => true, 'binary_pipes' => true)); - - if (!$proc) { - throw new rtPhpRunnerException('Failed to open process to run PHP code in rtPhpRunner'); +class rtPhpRunner +{ + private $phpCommand; + private $environmentVariables; + private $currentWorkingDirectory; + private $stdin; + private $timeOut; + + public function __construct($phpCommand, $environmentVariables, $currentWorkingDirectory, $stdin = null, $timeOut = 60) + { + $this->phpCommand = $phpCommand; + $this->environmentVariables = $environmentVariables; + $this->currentWorkingDirectory = $currentWorkingDirectory; + $this->timeOut = $timeOut; + $this->stdin = $stdin; } - if (!is_null($this->stdin)) { - fwrite($pipes[0], (binary) $this->stdin); - } - fclose($pipes[0]); - - while (true) { - /* hide errors from interrupted syscalls */ - $r = $pipes; - $w = null; - $e = null; - - $n = @stream_select($r, $w, $e, $this->timeOut); + /** + * Runs the PHP code. + * + * @return string - the output from the code + */ + public function runphp() + { + $data = ''; + + $proc = proc_open( + $this->phpCommand, + array(0 => array('pipe', 'r'), 1 => array('pipe', 'w'), 2 => array('pipe', 'w')), + $pipes, + $this->currentWorkingDirectory, + $this->environmentVariables, + array('suppress_errors' => true, 'binary_pipes' => true) + ); + + if (!$proc) { + throw new rtPhpRunnerException('Failed to open process to run PHP code in rtPhpRunner'); + } - if ($n === false) { - - throw new rtPhpRunnerException('Stream select failure in rtPhpRunner'); + if (!is_null($this->stdin)) { + fwrite($pipes[0], (binary) $this->stdin); + } - } else if ($n === 0) { - - proc_terminate($proc); - throw new rtPhpRunnerException ('The process running test code has timed out in rtPhpRunner'); + fclose($pipes[0]); + + while (true) { + /* hide errors from interrupted syscalls */ + $r = $pipes; + $w = null; + $e = null; + + $n = @stream_select($r, $w, $e, $this->timeOut); + + if ($n === false) { + throw new rtPhpRunnerException('Stream select failure in rtPhpRunner'); + } else if ($n === 0) { + proc_terminate($proc); + throw new rtPhpRunnerException ('The process running test code has timed out in rtPhpRunner'); + } else if ($n > 0) { + $line = fread($pipes[1], 8192); + if (strlen($line) == 0) { + /* EOF */ + break; + } + $data .= (binary) $line; + } + } - } else if ($n > 0) { - $line = fread($pipes[1], 8192); - if (strlen($line) == 0) { - /* EOF */ - break; + /* check the process status. Note that this will always be FALSE on windows */ + $stat = proc_get_status($proc); + if ($stat['signaled']) { + throw new rtPhpRunnerException('The process was terminated by uncaught signal number in rtPhpRunners'); } - $data .= (binary) $line; - } - } - /* check the process status. Note that this will always be FALSE on windows */ - $stat = proc_get_status($proc); - if ($stat['signaled']) { - throw new rtPhpRunnerException('The process was terminated by uncaught signal number in rtPhpRunners'); + $code = proc_close($proc); + return $data; } - - $code = proc_close($proc); - return $data; - } } - ?> diff --git a/src/testcase/rtPhpTest.php b/src/testcase/rtPhpTest.php index d0d2762..3ddba9f 100644 --- a/src/testcase/rtPhpTest.php +++ b/src/testcase/rtPhpTest.php @@ -1,164 +1,167 @@ <?php - - -class rtPhpTest { - - private $testName; - public $testConfiguration; - private $contents; - private $status; - private $output; - private $sections; - private $fileSection; - private $expectSection; - private $sectionHeadings; - - - public function __construct(array $contents, $testName, $sectionHeadings, $runConfiguration) { - $this->contents = $contents; - $this->testName = $testName; - $this->sectionHeadings = $sectionHeadings; - $this->parse(); - $this->init($runConfiguration); - } - - public function parse() { - - for ($i=0; $i<count($this->contents); $i++) { - //Create an array of section objects - if($this->isSectionKey($this->contents[$i])) { - $sectionKey = $this->contents[$i]; - - $tempArray = array(); - for($j=$i+1; $j<count($this->contents); $j++) { - - if ($this->isSectionKey($this->contents[$j])) { - $testSection = rtSection::getInstance($sectionKey, $tempArray); - $this->sections[$sectionKey] = $testSection; - break; - } - $tempArray[] = $this->contents[$j]; - } - } +/** + * + */ +class rtPhpTest +{ + public $testConfiguration; + + private $testName; + private $contents; + private $status; + private $output; + private $sections; + private $fileSection; + private $expectSection; + private $sectionHeadings; + + public function __construct(array $contents, $testName, $sectionHeadings, $runConfiguration) + { + $this->contents = $contents; + $this->testName = $testName; + $this->sectionHeadings = $sectionHeadings; + $this->parse(); + $this->init($runConfiguration); } - $testSection = rtSection::getInstance($sectionKey, $tempArray); - $this->sections[$sectionKey] = $testSection; - - //Identify the file and expect section types - $this->fileSection = $this->setFileSection(); - $this->expectSection = $this->setExpectSection(); + public function parse() + { + for ($i=0; $i<count($this->contents); $i++) { + //Create an array of section objects + if ($this->isSectionKey($this->contents[$i])) { + $sectionKey = $this->contents[$i]; + + $tempArray = array(); + for ($j=$i+1; $j<count($this->contents); $j++) { + + if ($this->isSectionKey($this->contents[$j])) { + $testSection = rtSection::getInstance($sectionKey, $tempArray); + $this->sections[$sectionKey] = $testSection; + break; + } + $tempArray[] = $this->contents[$j]; + } + } + } - } + $testSection = rtSection::getInstance($sectionKey, $tempArray); + $this->sections[$sectionKey] = $testSection; + //Identify the file and expect section types + $this->fileSection = $this->setFileSection(); + $this->expectSection = $this->setExpectSection(); + } - public function init(rtRuntestsConfiguration $runConfiguration) { - $this->testConfiguration = new rtTestConfiguration($runConfiguration, $this->sections); - } + public function init(rtRuntestsConfiguration $runConfiguration) + { + $this->testConfiguration = new rtTestConfiguration($runConfiguration, $this->sections); + } + //run + public function executeTest(rtRuntestsConfiguration $runConfiguration) + { + $this->status = array(); - //run - public function executeTest(rtRuntestsConfiguration $runConfiguration) { + if (array_key_exists('SKIPIF', $this->sections)) { + $this->status = $this->sections['SKIPIF']->run($this, $runConfiguration); + } - $this->status = array(); + 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(); + - if(array_key_exists('SKIPIF', $this->sections)) { - $this->status = $this->sections['SKIPIF']->run($this, $runConfiguration); + if (array_key_exists('CLEAN', $this->sections)) { + $cleanStatus = $this->sections['CLEAN']->run($this, $runConfiguration); + $this->status = array_merge($this->status, $cleanStatus); + } + } } - 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(); - + public function compareOutput() + { + $result = $this->expectSection->compare($this->output); - if(array_key_exists('CLEAN', $this->sections)) { - $cleanStatus = $this->sections['CLEAN']->run($this, $runConfiguration); - $this->status = array_merge($this->status, $cleanStatus); - } + if ($result) { + $this->status['pass'] = ''; + } else { + $this->status['fail'] = ''; + } + } + private function isSectionKey($line) + { + if (in_array($line, $this->sectionHeadings)) { + return true; + } + return false; } - } - public function compareOutput() { + private function setFileSection() + { + if (array_key_exists('FILE', $this->sections)) { + return $this->sections['FILE']; + } - $result = $this->expectSection->compare($this->output); + if (array_key_exists('FILEEOF', $this->sections)) { + return $this->sections['FILEEOF']; + } - if($result) { - $this->status['pass'] = ''; - } else { - $this->status['fail'] = ''; + if (array_key_exists('FILE_EXTERNAL', $this->sections)) { + return $this->sections['FILE_EXTERNAL']; + } } - } - private function isSectionKey($line) { - if(in_array($line, $this->sectionHeadings)) { - return true; - } - return false; - } + private function setExpectSection() + { + if (array_key_exists('EXPECT', $this->sections)) { + return $this->sections['EXPECT']; + } + if (array_key_exists('EXPECTF', $this->sections)) { + return $this->sections['EXPECTF']; + } - private function setFileSection() { - if(array_key_exists('FILE', $this->sections)) { - return $this->sections['FILE']; + if (array_key_exists('EXPECTREGEX', $this->sections)) { + return $this->sections['EXPECTREGEX']; + } } - if(array_key_exists('FILEEOF', $this->sections)) { - return $this->sections['FILEEOF']; + public function getName() + { + return $this->testName; } - if(array_key_exists('FILE_EXTERNAL', $this->sections)) { - return $this->sections['FILE_EXTERNAL']; + public function getOutput() + { + return $this->output; } - } - private function setExpectSection() { - if(array_key_exists('EXPECT', $this->sections)) { - return $this->sections['EXPECT']; + public function hasSection($sectionKey) + { + return array_key_exists($sectionKey, $this->sections); } - if(array_key_exists('EXPECTF', $this->sections)) { - return $this->sections['EXPECTF']; + public function getSection($sectionKey) + { + return $this->sections[$sectionKey]; } - if(array_key_exists('EXPECTREGEX', $this->sections)) { - return $this->sections['EXPECTREGEX']; + public function getStatus() + { + return $this->status; } - } - - - - public function getName() { - return $this->testName; - } - - public function getOutput() { - return $this->output; - } - - public function hasSection($sectionKey) { - return array_key_exists($sectionKey, $this->sections); - } - - public function getSection($sectionKey) { - return $this->sections[$sectionKey]; - } - - public function getStatus() { - return $this->status; - } - - public function getFileSection() { - return $this->fileSection; - } - - public function getExpectSection() { - return $this->expectSection; - } - + public function getFileSection() + { + return $this->fileSection; + } + public function getExpectSection() + { + return $this->expectSection; + } } ?> diff --git a/src/testcase/rtPhpTestFile.php b/src/testcase/rtPhpTestFile.php index e293669..c7da798 100644 --- a/src/testcase/rtPhpTestFile.php +++ b/src/testcase/rtPhpTestFile.php @@ -1,88 +1,89 @@ <?php - /** * Class to deal with all file system operations for a test case * */ -class rtPhpTestFile { - - private $fileName; - private $testName; - private $testContents; - private $testExitMessage; - private $sectionHeadings = array(); - - - private $carriageReturn = "\r"; - private $newLine = "\n"; - - - private $preConditions = array ( - 'rtHasMandatorySections', - 'rtHasNoDuplicateSections', - 'rtIsValidSectionName', - 'rtIsSectionImplemented' - ); - - - /** - * Reads the contents of the test file and creates an array of the contents. - * - * @param string $testFile (file name) - */ - public function doRead($testFile) { +class rtPhpTestFile +{ + private $fileName; + private $testName; + private $testContents; + private $testExitMessage; + private $sectionHeadings = array(); + + private $carriageReturn = "\r"; + private $newLine = "\n"; + + private $preConditions = array ( + 'rtHasMandatorySections', + 'rtHasNoDuplicateSections', + 'rtIsValidSectionName', + 'rtIsSectionImplemented' + ); + + /** + * Reads the contents of the test file and creates an array of the contents. + * + * @param string $testFile (file name) + */ + public function doRead($testFile) + { $this->testFileName = realpath($testFile); $this->testName= dirname($this->testFileName).DIRECTORY_SEPARATOR.basename($this->testFileName, ".phpt"); $this->testContents = file($this->testFileName); - } - - public function normaliseLineEndings() { - - for($i=0; $i<count($this->testContents); $i++) { - //This is not nice but there are a huge number of tests with random spacs at the end of the section header - if(preg_match("/--([A-Z]+(_[A-Z]+|))--/", $this->testContents[$i], $matches)) { - $this->sectionHeadings[] = $matches[1]; - $this->testContents[$i] = $matches[1]; - } else { - $this->testContents[$i] = rtrim($this->testContents[$i], $this->carriageReturn.$this->newLine); - } + } + + public function normaliseLineEndings() + { + for ($i=0; $i<count($this->testContents); $i++) { + //This is not nice but there are a huge number of tests with random spacs at the end of the section header + if (preg_match("/--([A-Z]+(_[A-Z]+|))--/", $this->testContents[$i], $matches)) { + $this->sectionHeadings[] = $matches[1]; + $this->testContents[$i] = $matches[1]; + } else { + $this->testContents[$i] = rtrim($this->testContents[$i], $this->carriageReturn.$this->newLine); + } } - } - - public function arePreConditionsMet() { - foreach($this->preConditions as $preCondition) { - $condition = new $preCondition; - if(!$condition->isMet($this->sectionHeadings)) { - $this->testExitMessage = $condition->getMessage(); - return false; - } + } + + public function arePreConditionsMet() + { + foreach ($this->preConditions as $preCondition) { + $condition = new $preCondition; + if (!$condition->isMet($this->sectionHeadings)) { + $this->testExitMessage = $condition->getMessage(); + return false; + } } return true; - } + } - public function getContents() { + public function getContents() + { return $this->testContents; - } - - public function getSectionHeadings() { + } + + public function getSectionHeadings() + { return $this->sectionHeadings; - } + } - public function getTestName() { + public function getTestName() + { return $this->testName; - } + } - public function getTestFileName() { + public function getTestFileName() + { return $this->testFileName; - } + } - public function getExitMessage() { + public function getExitMessage() + { return $this->testExitMessage; - } - - + } } -?> \ No newline at end of file +?> diff --git a/src/testcase/rtTestConfiguration.php b/src/testcase/rtTestConfiguration.php index 76e7414..5c3ea35 100644 --- a/src/testcase/rtTestConfiguration.php +++ b/src/testcase/rtTestConfiguration.php @@ -4,57 +4,64 @@ * 1. RuntestsConfiguration * 2. Sections which modify the Runtests configuration */ +class rtTestConfiguration +{ + private $environmentVariables; + private $phpCommandLineArguments; + private $testCommandLineArguments; -class rtTestConfiguration { - - private $environmentVariables; - private $phpCommandLineArguments; - private $testCommandLineArguments; - - public function __construct(rtRuntestsConfiguration $runConfiguration, $sections) { - $this->init($runConfiguration, $sections); - } - - private function init(rtRuntestsConfiguration $runConfiguration, $sections) { - $this->setEnvironmentVariables($runConfiguration, $sections); - $this->setPhpCommandLineArguments($runConfiguration, $sections); - $this->setTestCommandLineArguments($sections); - } - - private function setEnvironmentVariables(rtRuntestsConfiguration $runConfiguration, $sections) { - $this->environmentVariables = $runConfiguration->getEnvironmentVariables(); - if(array_key_exists('ENV', $sections)) { - $this->environmentVariables = array_merge($this->environmentVariables, $sections['ENV']->getTestEnvironmentVariables()); - } - } - - private function setPhpCommandLineArguments(rtRuntestsConfiguration $runConfiguration, $sections) { - $this->phpCommandLineArguments = $runConfiguration->getSetting('PhpCommandLineArguments'); - if(array_key_exists('INI', $sections)) { - $additionalArguments = $sections['INI']->getCommandLineArguments(); - $args = new rtIniAsCommandLineArgs(); - $this->phpCommandLineArguments = $args->settingsToArguments($additionalArguments, $this->phpCommandLineArguments); - } - } - - private function setTestCommandLineArguments($sections) { - $this->testCommandLineArguments = ''; - if(array_key_exists('ARGS', $sections)) { - $this->testCommandLineArguments = $sections['ARGS']->getTestCommandLineArguments(); - } - } - - public function getEnvironmentVariables() { - return $this->environmentVariables; - } - - public function getPhpCommandLineArguments() { - return $this->phpCommandLineArguments; - } - - public function getTestCommandLineArguments() { - return $this->testCommandLineArguments; - } - + public function __construct(rtRuntestsConfiguration $runConfiguration, $sections) + { + $this->init($runConfiguration, $sections); + } + + private function init(rtRuntestsConfiguration $runConfiguration, $sections) + { + $this->setEnvironmentVariables($runConfiguration, $sections); + $this->setPhpCommandLineArguments($runConfiguration, $sections); + $this->setTestCommandLineArguments($sections); + } + + private function setEnvironmentVariables(rtRuntestsConfiguration $runConfiguration, $sections) + { + $this->environmentVariables = $runConfiguration->getEnvironmentVariables(); + if (array_key_exists('ENV', $sections)) { + $this->environmentVariables = array_merge($this->environmentVariables, $sections['ENV']->getTestEnvironmentVariables()); + } + } + + private function setPhpCommandLineArguments(rtRuntestsConfiguration $runConfiguration, $sections) + { + $this->phpCommandLineArguments = $runConfiguration->getSetting('PhpCommandLineArguments'); + if (array_key_exists('INI', $sections)) { + $additionalArguments = $sections['INI']->getCommandLineArguments(); + $args = new rtIniAsCommandLineArgs(); + $this->phpCommandLineArguments = $args->settingsToArguments($additionalArguments, $this->phpCommandLineArguments); + } + } + + private function setTestCommandLineArguments($sections) + { + $this->testCommandLineArguments = ''; + + if (array_key_exists('ARGS', $sections)) { + $this->testCommandLineArguments = $sections['ARGS']->getTestCommandLineArguments(); + } + } + + public function getEnvironmentVariables() + { + return $this->environmentVariables; + } + + public function getPhpCommandLineArguments() + { + return $this->phpCommandLineArguments; + } + + public function getTestCommandLineArguments() + { + return $this->testCommandLineArguments; + } } -?> \ No newline at end of file +?> diff --git a/src/testcase/rtTestDifference.php b/src/testcase/rtTestDifference.php index 60d3bbd..975fb4b 100644 --- a/src/testcase/rtTestDifference.php +++ b/src/testcase/rtTestDifference.php @@ -1,190 +1,188 @@ <?php - /** * Calculates the difference between the expected and actual output * */ -class rtTestDifference { - - private $difference; - private $expectedOutput; - private $output; - private $expectedRegularExpression; - - public function __construct(rtOutputSection $expectedOutput, $output) { - $this->expectedOutput = $expectedOutput->getContents(); - $this->expectedRegularExpression = explode(b"\n",$expectedOutput->getPattern()); - $this->output = explode(b"\n", $output); - - $this->generateDiff(); - } - - public function generateDiff() { - $this->difference = $this->generateArrayDiff($this->expectedRegularExpression, $this->output, true, $this->expectedOutput); - } - - - /** - * Return the difference - * - * @return array - */ - public function getDifference() { - return $this->difference; - } - - - /** - * Unmodified from the original run-tests.php - * - * @param array $ar1 - * @param array $ar2 - * @param boolean $is_reg - * @param array $w - * @return array - */ - public function generateArrayDiff($ar1, $ar2, $is_reg, $w) { - - $idx1 = 0; $ofs1 = 0; $cnt1 = @count($ar1); - $idx2 = 0; $ofs2 = 0; $cnt2 = @count($ar2); - $diff = array(); - $old1 = array(); - $old2 = array(); - - while ($idx1 < $cnt1 && $idx2 < $cnt2) { - - if ($this->compLine($ar1[$idx1], $ar2[$idx2], $is_reg)) { - $idx1++; - $idx2++; - continue; - } else { - - $c1 = @$this->countArrayDiff($ar1, $ar2, $is_reg, $w, $idx1+1, $idx2, $cnt1, $cnt2, 10); - $c2 = @$this->countArrayDiff($ar1, $ar2, $is_reg, $w, $idx1, $idx2+1, $cnt1, $cnt2, 10); - - if ($c1 > $c2) { - $old1[$idx1] = (binary) sprintf("%03d- ", $idx1+1) . $w[$idx1++]; - $last = 1; - } else if ($c2 > 0) { - $old2[$idx2] = (binary) sprintf("%03d+ ", $idx2+1) . $ar2[$idx2++]; - $last = 2; - } else { - $old1[$idx1] = (binary) sprintf("%03d- ", $idx1+1) . $w[$idx1++]; - $old2[$idx2] = (binary) sprintf("%03d+ ", $idx2+1) . $ar2[$idx2++]; - } - } - } - - reset($old1); $k1 = key($old1); $l1 = -2; - reset($old2); $k2 = key($old2); $l2 = -2; - - while ($k1 !== null || $k2 !== null) { - - if ($k1 == $l1 + 1 || $k2 === null) { - $l1 = $k1; - $diff[] = current($old1); - $k1 = next($old1) ? key($old1) : null; - } else if ($k2 == $l2 + 1 || $k1 === null) { - $l2 = $k2; - $diff[] = current($old2); - $k2 = next($old2) ? key($old2) : null; - } else if ($k1 < $k2) { - $l1 = $k1; - $diff[] = current($old1); - $k1 = next($old1) ? key($old1) : null; - } else { - $l2 = $k2; - $diff[] = current($old2); - $k2 = next($old2) ? key($old2) : null; - } - } - - while ($idx1 < $cnt1) { - $diff[] = (binary) sprintf("%03d- ", $idx1 + 1) . $w[$idx1++]; +class rtTestDifference +{ + private $difference; + private $expectedOutput; + private $output; + private $expectedRegularExpression; + + public function __construct(rtOutputSection $expectedOutput, $output) + { + $this->expectedOutput = $expectedOutput->getContents(); + $this->expectedRegularExpression = explode(b"\n", $expectedOutput->getPattern()); + $this->output = explode(b"\n", $output); + + $this->generateDiff(); } - while ($idx2 < $cnt2) { - $diff[] = (binary) sprintf("%03d+ ", $idx2 + 1) . $ar2[$idx2++]; + public function generateDiff() + { + $this->difference = $this->generateArrayDiff($this->expectedRegularExpression, $this->output, true, $this->expectedOutput); } - return $diff; - } - - - /** - * Unmodified from the original version of runt-tests.php - * - * @param array $ar1 - * @param array $ar2 - * @param boolean $is_reg - * @param array $w - * @param int $idx1 - * @param int $idx2 - * @param int $cnt1 - * @param int $cnt2 - * @param int $steps - * @return unknown - */ - public function countArrayDiff($ar1, $ar2, $is_reg, $w, $idx1, $idx2, $cnt1, $cnt2, $steps) { - - $equal = 0; - - while ($idx1 < $cnt1 && $idx2 < $cnt2 && $this->compLine($ar1[$idx1], $ar2[$idx2], $is_reg)) { - $idx1++; - $idx2++; - $equal++; - $steps--; + /** + * Return the difference + * + * @return array + */ + public function getDifference() + { + return $this->difference; } - if (--$steps > 0) { - $eq1 = 0; - $st = $steps / 2; - for ($ofs1 = $idx1 + 1; $ofs1 < $cnt1 && $st-- > 0; $ofs1++) { - $eq = @$this->countArrayDiff($ar1, $ar2, $is_reg, $w, $ofs1, $idx2, $cnt1, $cnt2, $st); + /** + * Unmodified from the original run-tests.php + * + * @param array $ar1 + * @param array $ar2 + * @param boolean $is_reg + * @param array $w + * @return array + */ + public function generateArrayDiff($ar1, $ar2, $is_reg, $w) + { + $idx1 = 0; $ofs1 = 0; $cnt1 = @count($ar1); + $idx2 = 0; $ofs2 = 0; $cnt2 = @count($ar2); + $diff = array(); + $old1 = array(); + $old2 = array(); + + while ($idx1 < $cnt1 && $idx2 < $cnt2) { + + if ($this->compLine($ar1[$idx1], $ar2[$idx2], $is_reg)) { + $idx1++; + $idx2++; + continue; + } else { + + $c1 = @$this->countArrayDiff($ar1, $ar2, $is_reg, $w, $idx1+1, $idx2, $cnt1, $cnt2, 10); + $c2 = @$this->countArrayDiff($ar1, $ar2, $is_reg, $w, $idx1, $idx2+1, $cnt1, $cnt2, 10); + + if ($c1 > $c2) { + $old1[$idx1] = (binary) sprintf("%03d- ", $idx1+1) . $w[$idx1++]; + $last = 1; + } else if ($c2 > 0) { + $old2[$idx2] = (binary) sprintf("%03d+ ", $idx2+1) . $ar2[$idx2++]; + $last = 2; + } else { + $old1[$idx1] = (binary) sprintf("%03d- ", $idx1+1) . $w[$idx1++]; + $old2[$idx2] = (binary) sprintf("%03d+ ", $idx2+1) . $ar2[$idx2++]; + } + } + } - if ($eq > $eq1) { - $eq1 = $eq; + reset($old1); $k1 = key($old1); $l1 = -2; + reset($old2); $k2 = key($old2); $l2 = -2; + + while ($k1 !== null || $k2 !== null) { + + if ($k1 == $l1 + 1 || $k2 === null) { + $l1 = $k1; + $diff[] = current($old1); + $k1 = next($old1) ? key($old1) : null; + } else if ($k2 == $l2 + 1 || $k1 === null) { + $l2 = $k2; + $diff[] = current($old2); + $k2 = next($old2) ? key($old2) : null; + } else if ($k1 < $k2) { + $l1 = $k1; + $diff[] = current($old1); + $k1 = next($old1) ? key($old1) : null; + } else { + $l2 = $k2; + $diff[] = current($old2); + $k2 = next($old2) ? key($old2) : null; + } } - } - $eq2 = 0; - $st = $steps; + while ($idx1 < $cnt1) { + $diff[] = (binary) sprintf("%03d- ", $idx1 + 1) . $w[$idx1++]; + } - for ($ofs2 = $idx2 + 1; $ofs2 < $cnt2 && $st-- > 0; $ofs2++) { - $eq = @$this->countArrayDiff($ar1, $ar2, $is_reg, $w, $idx1, $ofs2, $cnt1, $cnt2, $st); - if ($eq > $eq2) { - $eq2 = $eq; + while ($idx2 < $cnt2) { + $diff[] = (binary) sprintf("%03d+ ", $idx2 + 1) . $ar2[$idx2++]; } - } - if ($eq1 > $eq2) { - $equal += $eq1; - } else if ($eq2 > 0) { - $equal += $eq2; - } + return $diff; } - return $equal; - } - + /** + * Unmodified from the original version of runt-tests.php + * + * @param array $ar1 + * @param array $ar2 + * @param boolean $is_reg + * @param array $w + * @param int $idx1 + * @param int $idx2 + * @param int $cnt1 + * @param int $cnt2 + * @param int $steps + * @return unknown + */ + public function countArrayDiff($ar1, $ar2, $is_reg, $w, $idx1, $idx2, $cnt1, $cnt2, $steps) + { + $equal = 0; + + while ($idx1 < $cnt1 && $idx2 < $cnt2 && $this->compLine($ar1[$idx1], $ar2[$idx2], $is_reg)) { + $idx1++; + $idx2++; + $equal++; + $steps--; + } - /** - * Copied unmodified from run-tests.php - * - * @param string $l1 - * @param string $l2 - * @param boolean $is_reg - * @return boolean - */ - public function compLine($l1, $l2, $is_reg) { + if (--$steps > 0) { + $eq1 = 0; + $st = $steps / 2; + + for ($ofs1 = $idx1 + 1; $ofs1 < $cnt1 && $st-- > 0; $ofs1++) { + $eq = @$this->countArrayDiff($ar1, $ar2, $is_reg, $w, $ofs1, $idx2, $cnt1, $cnt2, $st); + + if ($eq > $eq1) { + $eq1 = $eq; + } + } + + $eq2 = 0; + $st = $steps; + + for ($ofs2 = $idx2 + 1; $ofs2 < $cnt2 && $st-- > 0; $ofs2++) { + $eq = @$this->countArrayDiff($ar1, $ar2, $is_reg, $w, $idx1, $ofs2, $cnt1, $cnt2, $st); + if ($eq > $eq2) { + $eq2 = $eq; + } + } + + if ($eq1 > $eq2) { + $equal += $eq1; + } else if ($eq2 > 0) { + $equal += $eq2; + } + } - if ($is_reg) { - return preg_match((binary) "/^$l1$/s", (binary) $l2); - } else { - return !strcmp((binary) $l1, (binary) $l2); + return $equal; } - } + /** + * Copied unmodified from run-tests.php + * + * @param string $l1 + * @param string $l2 + * @param boolean $is_reg + * @return boolean + */ + public function compLine($l1, $l2, $is_reg) + { + if ($is_reg) { + return preg_match((binary) "/^$l1$/s", (binary) $l2); + } else { + return !strcmp((binary) $l1, (binary) $l2); + } + } } -?> \ No newline at end of file +?> diff --git a/src/testcase/rtTestOutputWriter.php b/src/testcase/rtTestOutputWriter.php index eed4761..62149c7 100644 --- a/src/testcase/rtTestOutputWriter.php +++ b/src/testcase/rtTestOutputWriter.php @@ -1,45 +1,39 @@ <?php - /** * Class for writing the output from a test * */ - -abstract class rtTestOutputWriter { - - - protected $testOutput; - protected $testExitStatus; - protected $testExitMessage; - - - - public static function getInstance (array $testResults, $outputType) { +abstract class rtTestOutputWriter +{ + protected $testOutput; + protected $testExitStatus; + protected $testExitMessage; - if($outputType == 'list') { - return new rtTestOutputWriterList($testResults); - } + public static function getInstance (array $testResults, $outputType) + { + if ($outputType == 'list') { + return new rtTestOutputWriterList($testResults); + } + + if ($outputType == 'xml') { + return new rtTestOutputWriterXML($testresults); + } + } - if($outputType == 'xml') { - return new rtTestOutputWriterXML($testresults); - } + abstract function init(array $testResults); - } - - abstract function init(array $testResults); - - /** - * Write the output to standard out - * - */ - abstract function write(); - - - /** - * - */ - public function getOutput() { - return $this->testOutput; - } + /** + * Write the output to standard out + * + */ + abstract function write(); + + /** + * + */ + public function getOutput() + { + return $this->testOutput; + } } ?> diff --git a/src/testcase/rtTestPreCondition.php b/src/testcase/rtTestPreCondition.php index f0901b5..a2822b3 100644 --- a/src/testcase/rtTestPreCondition.php +++ b/src/testcase/rtTestPreCondition.php @@ -1,11 +1,10 @@ <?php +interface rtTestPreCondition +{ + public function isMet(array $testContents); -interface rtTestPreCondition { - - public function isMet(array $testContents); - - public function getMessage(); + public function getMessage(); } ?> diff --git a/src/testcase/rtTestResults.php b/src/testcase/rtTestResults.php index 1f10e47..2785080 100644 --- a/src/testcase/rtTestResults.php +++ b/src/testcase/rtTestResults.php @@ -1,172 +1,159 @@ <?php - /** * Class to store test results. - * Ensures that files are either deleted or saved depending on the test results - * Maintains an array of files names that have been saved - * Maintains (adds to) the tests case status to give a final status array - * Request calculation of difference between expected/actual output if the test has failed. + * + * Ensures that files are either deleted or saved depending on the test results + * Maintains an array of files names that have been saved + * Maintains (adds to) the tests case status to give a final status array + * Request calculation of difference between expected/actual output if the test has failed. * */ - -class rtTestResults { - - private $status = array(); - private $testName = ''; - private $savedResultsFiles = array(); - private $title = ''; - - public function __construct(rtPhpTest $testCase = null, $borkErrorString = null, $borkedFile = null) { - $this->init($testCase,$borkErrorString, $borkedFile); - } - - public function init(rtPhpTest $testCase = null, $borkErrorString = null, $borkedFile = null) { - if($testCase != null) { - $this->title = implode('',$testCase->getSection('TEST')->getContents()); - $this->status = $testCase->getStatus(); - $this->testName = $testCase->getName(); - } else { - $this->status['bork'] = $borkErrorString; - $this->testName = $borkedFile; - } - } - - public function processResults(rtPhpTest $testCase, rtRuntestsConfiguration $runConfiguration) { - - if (array_key_exists('pass', $this->status)) { - $this->onPass($testCase, $runConfiguration); - } - - elseif (array_key_exists('fail', $this->status)) { - $this->onFail($testCase); - } - - elseif (array_key_exists('skip', $this->status)) { - $this->onSkip($testCase, $runConfiguration); - } - - elseif (array_key_exists('bork', $this->status)) { - //what to do here? - } - else { - echo "no status? something wrong here\n"; - } - - - } - - - /** - * Actions is a test passes - */ - private function onPass(rtPhpTest $testCase, rtRuntestsConfiguration $runConfiguration) { - - if(!$runConfiguration->hasCommandLineOption('keep-all') && !$runConfiguration->hasCommandLineOption('keep-php')) { - $testCase->getFileSection()->deleteFile(); - } else { - $this->savedFileNames['php'] = $this->testName. ".php"; - } - - if($runConfiguration->hasCommandLineOption('keep-all') || $runConfiguration->hasCommandLineOption('keep-out')){ - $outputFileName = $this->testName.".out"; - file_put_contents($outputFileName, $testCase->getOutput()); - $this->savedFileNames['out'] = $outputFileName; - } - - if($runConfiguration->hasCommandLineOption('keep-all') || $runConfiguration->hasCommandLineOption('keep-exp')){ - $expectedFileName = $this->testName.".exp"; - file_put_contents($expectedFileName, implode(b"\n", $testCase->getExpectSection()->getContents())); - $this->savedFileNames['exp'] = $expectedFileName; - } - - if($testCase->hasSection('XFAIL')) { - $this->status['warn'] = 'Test passeses but has an XFAIL section'; - } - - if($testCase->hasSection('CLEAN')) { - if(!$runConfiguration->hasCommandLineOption('keep-all') && !$runConfiguration->hasCommandLineOption('keep-clean')) { - $testCase->getSection('CLEAN')->deleteFile(); - } else { - $this->savedFileNames['clean'] = $this->testName. ".clean"; - } - } - - if($testCase->hasSection('SKIPIF')) { - $testCase->getSection('SKIPIF')->deleteFile(); - - } - } - - private function onFail(rtPhpTest $testCase) { - - $testDifference = new rtTestDifference($testCase->getExpectSection(), $testCase->getOutput()); - $difference = implode(b"\n",$testDifference->getDifference()); - - $differenceFileName = $this->testName.".diff"; - $outputFileName = $this->testName.".out"; - $expectedFileName = $this->testName.".exp"; - - file_put_contents($differenceFileName, $difference); - file_put_contents($outputFileName, $testCase->getOutput()); - file_put_contents($expectedFileName, implode(b"\n", $testCase->getExpectSection()->getContents())); - - $this->savedFileNames['out'] = $outputFileName; - $this->savedFileNames['exp'] = $expectedFileName; - $this->savedFileNames['diff'] = $differenceFileName; - - if($testCase->hasSection('XFAIL')) { - $this->status['xfail'] = $testCase->getSection('XFAIL')->getReason(); - - } - - //Note: if there are clean and skipif files they will not be deleted if the test fails - if($testCase->hasSection('CLEAN')) { - $this->savedFileNames['clean'] = $this->testName. 'clean.php'; - } - - if($testCase->hasSection('SKIPIF')) { - $this->savedFileNames['skipif'] = $this->testName. 'skipif.php'; - } - - } - - private function onSkip(rtPhpTest $testCase, rtRuntestsConfiguration $runConfiguration) { - - if($runConfiguration->hasCommandLineOption('keep-all') || $runConfiguration->hasCommandLineOption('keep-skip')) { - $this->savedFileNames['skipif'] = $this->testName. 'skipif.php'; - } else { - - $skipSection = $testCase->getSection('SKIPIF'); - $skipSection->deleteFile(); +class rtTestResults +{ + private $status = array(); + private $testName = ''; + private $savedResultsFiles = array(); + private $title = ''; + + public function __construct(rtPhpTest $testCase = null, $borkErrorString = null, $borkedFile = null) + { + $this->init($testCase,$borkErrorString, $borkedFile); + } + + public function init(rtPhpTest $testCase = null, $borkErrorString = null, $borkedFile = null) + { + if ($testCase != null) { + $this->title = implode('',$testCase->getSection('TEST')->getContents()); + $this->status = $testCase->getStatus(); + $this->testName = $testCase->getName(); + } else { + $this->status['bork'] = $borkErrorString; + $this->testName = $borkedFile; + } + } + + public function processResults(rtPhpTest $testCase, rtRuntestsConfiguration $runConfiguration) + { + + if (array_key_exists('pass', $this->status)) { + $this->onPass($testCase, $runConfiguration); + } elseif (array_key_exists('fail', $this->status)) { + $this->onFail($testCase); + } elseif (array_key_exists('skip', $this->status)) { + $this->onSkip($testCase, $runConfiguration); + } elseif (array_key_exists('bork', $this->status)) { + //what to do here? + } else { + echo "no status? something wrong here\n"; + } + } + + /** + * Actions is a test passes + */ + private function onPass(rtPhpTest $testCase, rtRuntestsConfiguration $runConfiguration) + { + if (!$runConfiguration->hasCommandLineOption('keep-all') && !$runConfiguration->hasCommandLineOption('keep-php')) { + $testCase->getFileSection()->deleteFile(); + } else { + $this->savedFileNames['php'] = $this->testName. ".php"; + } + + if ($runConfiguration->hasCommandLineOption('keep-all') || $runConfiguration->hasCommandLineOption('keep-out')) { + $outputFileName = $this->testName.".out"; + file_put_contents($outputFileName, $testCase->getOutput()); + $this->savedFileNames['out'] = $outputFileName; + } + + if ($runConfiguration->hasCommandLineOption('keep-all') || $runConfiguration->hasCommandLineOption('keep-exp')) { + $expectedFileName = $this->testName.".exp"; + file_put_contents($expectedFileName, implode(b"\n", $testCase->getExpectSection()->getContents())); + $this->savedFileNames['exp'] = $expectedFileName; + } + + if ($testCase->hasSection('XFAIL')) { + $this->status['warn'] = 'Test passeses but has an XFAIL section'; + } + + if ($testCase->hasSection('CLEAN')) { + if (!$runConfiguration->hasCommandLineOption('keep-all') && !$runConfiguration->hasCommandLineOption('keep-clean')) { + $testCase->getSection('CLEAN')->deleteFile(); + } else { + $this->savedFileNames['clean'] = $this->testName. ".clean"; + } + } + + if ($testCase->hasSection('SKIPIF')) { + $testCase->getSection('SKIPIF')->deleteFile(); + } + } + + private function onFail(rtPhpTest $testCase) + { + $testDifference = new rtTestDifference($testCase->getExpectSection(), $testCase->getOutput()); + $difference = implode(b"\n",$testDifference->getDifference()); + + $differenceFileName = $this->testName.".diff"; + $outputFileName = $this->testName.".out"; + $expectedFileName = $this->testName.".exp"; + + file_put_contents($differenceFileName, $difference); + file_put_contents($outputFileName, $testCase->getOutput()); + file_put_contents($expectedFileName, implode(b"\n", $testCase->getExpectSection()->getContents())); + + $this->savedFileNames['out'] = $outputFileName; + $this->savedFileNames['exp'] = $expectedFileName; + $this->savedFileNames['diff'] = $differenceFileName; + + if ($testCase->hasSection('XFAIL')) { + $this->status['xfail'] = $testCase->getSection('XFAIL')->getReason(); + } + + //Note: if there are clean and skipif files they will not be deleted if the test fails + if ($testCase->hasSection('CLEAN')) { + $this->savedFileNames['clean'] = $this->testName. 'clean.php'; + } + + if ($testCase->hasSection('SKIPIF')) { + $this->savedFileNames['skipif'] = $this->testName. 'skipif.php'; + } + } + + private function onSkip(rtPhpTest $testCase, rtRuntestsConfiguration $runConfiguration) + { + if ($runConfiguration->hasCommandLineOption('keep-all') || $runConfiguration->hasCommandLineOption('keep-skip')) { + $this->savedFileNames['skipif'] = $this->testName. 'skipif.php'; + } else { + $skipSection = $testCase->getSection('SKIPIF'); + $skipSection->deleteFile(); + } + + //It may seem odd to check for an XFAIL if we are skipping the test, on the other hand I found + //a few windows tests with blank XFAIL sections and wanted to know about those. + + if ($testCase->hasSection('XFAIL')) { + $this->status['xfail'] = $testCase->getSection('XFAIL')->getReason(); + } + } + + public function getStatus() + { + return $this->status; + } + + public function getSavedFileNames() + { + return $this->savedFileNames; + } + + public function getName() + { + return $this->testName; + } + + public function getTitle() + { + return $this->title; } - - //It may seem odd to check for an XFAIL if we are skipping the test, on the other hand I found - //a few windows tests with blank XFAIL sections and wanted to know about those. - - if($testCase->hasSection('XFAIL')) { - $this->status['xfail'] = $testCase->getSection('XFAIL')->getReason(); - } - - } - - - public function getStatus() { - return $this->status; - } - - public function getSavedFileNames() { - return $this->savedFileNames; - } - - public function getName() { - return $this->testName; - } - - public function getTitle() { - return $this->title; - } - - - } -?> \ No newline at end of file +?> diff --git a/src/testcase/sections/configurationsections/rtArgsSection.php b/src/testcase/sections/configurationsections/rtArgsSection.php index 8409e47..47ae97b 100644 --- a/src/testcase/sections/configurationsections/rtArgsSection.php +++ b/src/testcase/sections/configurationsections/rtArgsSection.php @@ -1,21 +1,24 @@ <?php -class rtArgsSection extends rtConfigurationSection { - - private $testCommandLineArguments; - - - protected function init() { - $this->testCommandLineArguments = '-- ' . $this->sectionContents[0]; - } - - /** - * Return additional arguments to be added to the PHP Test command line - * - * @return string - */ - public function getTestCommandLineArguments() { - return $this->testCommandLineArguments; - } - +/** + * + */ +class rtArgsSection extends rtConfigurationSection +{ + private $testCommandLineArguments; + + protected function init() + { + $this->testCommandLineArguments = '-- ' . $this->sectionContents[0]; + } + + /** + * Return additional arguments to be added to the PHP Test command line + * + * @return string + */ + public function getTestCommandLineArguments() + { + return $this->testCommandLineArguments; + } } -?> \ No newline at end of file +?> diff --git a/src/testcase/sections/configurationsections/rtEnvSection.php b/src/testcase/sections/configurationsections/rtEnvSection.php index 8758819..602893b 100644 --- a/src/testcase/sections/configurationsections/rtEnvSection.php +++ b/src/testcase/sections/configurationsections/rtEnvSection.php @@ -1,23 +1,27 @@ <?php -class rtEnvSection extends rtConfigurationSection { +/** + * + */ +class rtEnvSection extends rtConfigurationSection +{ + private $testEnvironmentVariables = array(); - private $testEnvironmentVariables = array(); - - - protected function init() { - foreach($this->sectionContents as $line) { - $tempArray = explode('=', $line); - $this->testEnvironmentVariables[trim($tempArray[0])] = trim($tempArray[1]); + protected function init() + { + foreach ($this->sectionContents as $line) { + $tempArray = explode('=', $line); + $this->testEnvironmentVariables[trim($tempArray[0])] = trim($tempArray[1]); + } } - } - /** - * Additional environment variables required by the test - * - * @return array - */ - public function getTestEnvironmentVariables() { - return $this->testEnvironmentVariables; - } + /** + * Additional environment variables required by the test + * + * @return array + */ + public function getTestEnvironmentVariables() + { + return $this->testEnvironmentVariables; + } } -?> \ No newline at end of file +?> diff --git a/src/testcase/sections/configurationsections/rtIniSection.php b/src/testcase/sections/configurationsections/rtIniSection.php index 932ac74..85fe279 100644 --- a/src/testcase/sections/configurationsections/rtIniSection.php +++ b/src/testcase/sections/configurationsections/rtIniSection.php @@ -1,24 +1,26 @@ <?php +/** + * + */ +class rtIniSection extends rtConfigurationSection +{ + private $commandLineArguments = array(); -class rtIniSection extends rtConfigurationSection { - - private $commandLineArguments = array(); - - - public function init() { - foreach ($this->sectionContents as $line) { - $this->commandLineArguments[] = addslashes($line); + public function init() + { + foreach ($this->sectionContents as $line) { + $this->commandLineArguments[] = addslashes($line); + } + } + + /** + * Returns any additional PHP commandline arguments + * + * @return array + */ + public function getCommandLineArguments() + { + return $this->commandLineArguments; } - } - - /** - * Returns any additional PHP commandline arguments - * - * @return array - */ - public function getCommandLineArguments() { - return $this->commandLineArguments; - } - } -?> \ No newline at end of file +?> diff --git a/src/testcase/sections/executablesections/rtCleanSection.php b/src/testcase/sections/executablesections/rtCleanSection.php index d7627b7..d4a8eff 100644 --- a/src/testcase/sections/executablesections/rtCleanSection.php +++ b/src/testcase/sections/executablesections/rtCleanSection.php @@ -1,44 +1,41 @@ <?php - /** * Class representing the clean test section */ -class rtCleanSection extends rtExecutableSection { - - - public function setExecutableFileName($testName) { - $this->fileName = $testName.".clean.php"; - } - - public function run(rtPhpTest $testCase, rtRuntestsConfiguration $runConfiguration) { - - $this->status = array(); - - $this->setExecutableFileName($testCase->getName()); - $this->writeExecutableFile(); - - $phpCommand = $runConfiguration->getSetting('PhpExecutable'); - $phpCommand .= ' '.$runConfiguration->getSetting('PhpCommandLineArguments'); - $phpCommand .= ' -f '.$this->fileName; - - $PhpRunner = new rtPhpRunner($phpCommand, - $runConfiguration->getEnvironmentVariables(), - $runConfiguration->getSetting('WorkingDirectory') - ); - +class rtCleanSection extends rtExecutableSection +{ + public function setExecutableFileName($testName) + { + $this->fileName = $testName.".clean.php"; + } - try { - $this->output = $PhpRunner->runphp(); - //if the CLEAN section has worked the result should be a blank line - if(trim($this->output) != "") { - $this->status['warn'] = 'Execution of clean section failed: '.trim($this->output); - } - } catch (rtPhpRunnerException $e) { - $this->status['warn'] = 'Failed to execute clean section'; + public function run(rtPhpTest $testCase, rtRuntestsConfiguration $runConfiguration) + { + $this->status = array(); + + $this->setExecutableFileName($testCase->getName()); + $this->writeExecutableFile(); + + $phpCommand = $runConfiguration->getSetting('PhpExecutable'); + $phpCommand .= ' '.$runConfiguration->getSetting('PhpCommandLineArguments'); + $phpCommand .= ' -f '.$this->fileName; + + $PhpRunner = new rtPhpRunner($phpCommand, + $runConfiguration->getEnvironmentVariables(), + $runConfiguration->getSetting('WorkingDirectory') + ); + + try { + $this->output = $PhpRunner->runphp(); + //if the CLEAN section has worked the result should be a blank line + if (trim($this->output) != "") { + $this->status['warn'] = 'Execution of clean section failed: '.trim($this->output); + } + } catch (rtPhpRunnerException $e) { + $this->status['warn'] = 'Failed to execute clean section'; + } + + return $this->status; } - - return $this->status; - } } - -?> \ No newline at end of file +?> diff --git a/src/testcase/sections/executablesections/rtFileSection.php b/src/testcase/sections/executablesections/rtFileSection.php index f9dc95c..4120d60 100644 --- a/src/testcase/sections/executablesections/rtFileSection.php +++ b/src/testcase/sections/executablesections/rtFileSection.php @@ -1,41 +1,38 @@ <?php - /** * Class for the --FILE-- section */ -class rtFileSection extends rtExecutableSection { - - - public function setExecutableFileName($testName) { - $this->fileName = $testName.".php"; - } +class rtFileSection extends rtExecutableSection +{ + public function setExecutableFileName($testName) + { + $this->fileName = $testName.".php"; + } - public function run(rtPhpTest $testCase, rtRuntestsConfiguration $runConfiguration) { - - $this->status = array(); + public function run(rtPhpTest $testCase, rtRuntestsConfiguration $runConfiguration) + { + $this->status = array(); - $this->setExecutableFileName($testCase->getName()); - $this->writeExecutableFile(); + $this->setExecutableFileName($testCase->getName()); + $this->writeExecutableFile(); - $phpCommand = $runConfiguration->getSetting('PhpExecutable'); - $phpCommand .= ' '.$testCase->testConfiguration->getPhpCommandLineArguments(); - $phpCommand .= ' -f '.$this->fileName; - $phpCommand .= ' '.$testCase->testConfiguration->getTestCommandLineArguments(); - - $PhpRunner = new rtPhpRunner($phpCommand, - $testCase->testConfiguration->getEnvironmentVariables(), - $runConfiguration->getSetting('WorkingDirectory') - ); - - try { - $this->output = $PhpRunner->runphp(); - } catch (rtPhpRunnerException $e) { - $this->status['fail'] = $e->getMessage(); + $phpCommand = $runConfiguration->getSetting('PhpExecutable'); + $phpCommand .= ' '.$testCase->testConfiguration->getPhpCommandLineArguments(); + $phpCommand .= ' -f '.$this->fileName; + $phpCommand .= ' '.$testCase->testConfiguration->getTestCommandLineArguments(); + + $PhpRunner = new rtPhpRunner($phpCommand, + $testCase->testConfiguration->getEnvironmentVariables(), + $runConfiguration->getSetting('WorkingDirectory') + ); + + try { + $this->output = $PhpRunner->runphp(); + } catch (rtPhpRunnerException $e) { + $this->status['fail'] = $e->getMessage(); + } + + return $this->status; } - - return $this->status; - - } - } -?> \ No newline at end of file +?> diff --git a/src/testcase/sections/executablesections/rtSkipIfSection.php b/src/testcase/sections/executablesections/rtSkipIfSection.php index 146ec63..e706e96 100644 --- a/src/testcase/sections/executablesections/rtSkipIfSection.php +++ b/src/testcase/sections/executablesections/rtSkipIfSection.php @@ -1,60 +1,53 @@ <?php - /** * Class representing the SkipIf test section */ -class rtSkipIfSection extends rtExecutableSection { - - - public function setExecutableFileName($testName) { - $this->fileName = $testName.".skipif.php"; - } - - - public function run(rtPhpTest $testCase, rtRuntestsConfiguration $runConfiguration) { - - $this->status = array(); - - $this->setExecutableFileName($testCase->getName()); - $this->writeExecutableFile(); - - $phpCommand = $runConfiguration->getSetting('PhpExecutable'); - $phpCommand .= ' '.$runConfiguration->getSetting('PhpCommandLineArguments'); - $phpCommand .= ' -f '.$this->fileName; - - $PhpRunner = new rtPhpRunner($phpCommand, - $runConfiguration->getEnvironmentVariables(), - $runConfiguration->getSetting('WorkingDirectory') - ); - - try { - $this->output = $PhpRunner->runphp(); - - if (!strncasecmp('skip', ltrim($this->output), 4)) { - if(preg_match('/^\s*skip\s*(.+)\s*/i', $this->output, $matches)) { - $this->status['skip'] = $matches[1]; - } - else { - $this->status['skip'] = ''; - } - } +class rtSkipIfSection extends rtExecutableSection +{ + public function setExecutableFileName($testName) + { + $this->fileName = $testName.".skipif.php"; + } - if (!strncasecmp('warn', ltrim($this->output), 4)) { - if(preg_match('/^\s*warn\s*(.+)\s*/i', $this->output, $matches)) { - $this->status['warn'] = $matches[1]; + public function run(rtPhpTest $testCase, rtRuntestsConfiguration $runConfiguration) + { + $this->status = array(); + + $this->setExecutableFileName($testCase->getName()); + $this->writeExecutableFile(); + + $phpCommand = $runConfiguration->getSetting('PhpExecutable'); + $phpCommand .= ' '.$runConfiguration->getSetting('PhpCommandLineArguments'); + $phpCommand .= ' -f '.$this->fileName; + + $PhpRunner = new rtPhpRunner($phpCommand, + $runConfiguration->getEnvironmentVariables(), + $runConfiguration->getSetting('WorkingDirectory') + ); + + try { + $this->output = $PhpRunner->runphp(); + + if (!strncasecmp('skip', ltrim($this->output), 4)) { + if (preg_match('/^\s*skip\s*(.+)\s*/i', $this->output, $matches)) { + $this->status['skip'] = $matches[1]; + } else { + $this->status['skip'] = ''; + } + } + + if (!strncasecmp('warn', ltrim($this->output), 4)) { + if (preg_match('/^\s*warn\s*(.+)\s*/i', $this->output, $matches)) { + $this->status['warn'] = $matches[1]; + } else { + $this->status['warn'] = ''; + } + } + } catch (rtPhpRunnerException $e) { + $this->status['bork'] = 'Failed to execute skipif section'; } - else { - $this->status['warn'] = ''; - } - } - - } catch (rtPhpRunnerException $e) { - $this->status['bork'] = 'Failed to execute skipif section'; + + return $this->status; } - - return $this->status; - } - - } -?> \ No newline at end of file +?> diff --git a/src/testcase/sections/informationsections/rtCreditsSection.php b/src/testcase/sections/informationsections/rtCreditsSection.php index 15d6197..e86336b 100644 --- a/src/testcase/sections/informationsections/rtCreditsSection.php +++ b/src/testcase/sections/informationsections/rtCreditsSection.php @@ -1,11 +1,9 @@ <?php - - /** * Class for --CREDITS-- section * */ -class rtCreditsSection extends rtInformationSection { - +class rtCreditsSection extends rtInformationSection +{ } -?> \ No newline at end of file +?> diff --git a/src/testcase/sections/informationsections/rtTestHeaderSection.php b/src/testcase/sections/informationsections/rtTestHeaderSection.php index ba0290c..9da8d69 100644 --- a/src/testcase/sections/informationsections/rtTestHeaderSection.php +++ b/src/testcase/sections/informationsections/rtTestHeaderSection.php @@ -1,19 +1,20 @@ <?php - /** * Class for the --TEST-- section */ -class rtTestHeaderSection extends rtInformationSection { - - protected $testHeader; - - protected function init() { - //Only a single line heading is allowed. Ingore any more lines. - $this->testHeader = $this->sectionContents[0]; - } - - public function getHeader() { - return $this->testHeader; - } +class rtTestHeaderSection extends rtInformationSection +{ + protected $testHeader; + + protected function init() + { + //Only a single line heading is allowed. Ingore any more lines. + $this->testHeader = $this->sectionContents[0]; + } + + public function getHeader() + { + return $this->testHeader; + } } -?> \ No newline at end of file +?> diff --git a/src/testcase/sections/informationsections/rtXfailSection.php b/src/testcase/sections/informationsections/rtXfailSection.php index d60cdc7..5c196f0 100644 --- a/src/testcase/sections/informationsections/rtXfailSection.php +++ b/src/testcase/sections/informationsections/rtXfailSection.php @@ -1,25 +1,25 @@ <?php - - /** * Class for the --XFAIL-- section * */ -class rtXfailSection extends rtInformationSection { +class rtXfailSection extends rtInformationSection +{ + protected $failReason; - protected $failReason; - - protected function init() { - //Only a single line reason is allowed. Ingore any more lines. - if(isset($this->sectionContents[0])){ - $this->failReason = $this->sectionContents[0]; - } else { - $this->failReason = "This test is apparently expected to fail but the author did not say why"; + protected function init() + { + //Only a single line reason is allowed. Ingore any more lines. + if (isset($this->sectionContents[0])) { + $this->failReason = $this->sectionContents[0]; + } else { + $this->failReason = "This test is apparently expected to fail but the author did not say why"; + } } - } - public function getReason() { - return $this->failReason; - } + public function getReason() + { + return $this->failReason; + } } -?> \ No newline at end of file +?> diff --git a/src/testcase/sections/outputsections/rtExpectFSection.php b/src/testcase/sections/outputsections/rtExpectFSection.php index 693c947..40de4df 100644 --- a/src/testcase/sections/outputsections/rtExpectFSection.php +++ b/src/testcase/sections/outputsections/rtExpectFSection.php @@ -1,96 +1,97 @@ <?php - - /** * Class representing expected and actual output from a test */ -class rtExpectFSection extends rtOutputSection { - - protected function init() { - parent::createPattern(); - $this->createPattern(); - } - - /** - * Create the pattern used to match against actual output - * - */ - protected function createPattern() { - $this->expectedPattern = preg_quote($this->expectedPattern, '/'); - $this->expectedPattern = $this->expectfUnicodeSubstitutions ($this->expectedPattern); - $this->expectedPattern = $this->expectfRegexSubstitutions($this->expectedPattern); - } - - - /* - * Replaces string with unicode and vice versa. Allows same tests for PHP5 and PHP6 - * @param string - * @return string - */ - private function expectfUnicodeSubstitutions($string) { - $string = str_replace( - array('%unicode_string_optional%'), - version_compare(PHP_VERSION, '6.0.0-dev') == -1 ? 'string' : 'Unicode string', $string ); +class rtExpectFSection extends rtOutputSection +{ + protected function init() + { + parent::createPattern(); + $this->createPattern(); + } + + /** + * Create the pattern used to match against actual output + * + */ + protected function createPattern() + { + $this->expectedPattern = preg_quote($this->expectedPattern, '/'); + $this->expectedPattern = $this->expectfUnicodeSubstitutions ($this->expectedPattern); + $this->expectedPattern = $this->expectfRegexSubstitutions($this->expectedPattern); + } - $string = str_replace( - array('%unicode\|string%', '%string\|unicode%'), - version_compare(PHP_VERSION, '6.0.0-dev') == -1 ? 'string' : 'unicode', - $string - ); + /* + * Replaces string with unicode and vice versa. Allows same tests for PHP5 and PHP6 + * @param string + * @return string + */ + private function expectfUnicodeSubstitutions($string) + { + $string = str_replace( + array('%unicode_string_optional%'), + version_compare(PHP_VERSION, '6.0.0-dev') == -1 ? 'string' : 'Unicode string', $string + ); + + $string = str_replace( + array('%unicode\|string%', '%string\|unicode%'), + version_compare(PHP_VERSION, '6.0.0-dev') == -1 ? 'string' : 'unicode', + $string + ); + + $string = str_replace( + array('%u\|b%', '%b\|u%'), + version_compare(PHP_VERSION, '6.0.0-dev') == -1 ? '' : 'u', + $string + ); + + return $string; + } - $string = str_replace( - array('%u\|b%', '%b\|u%'), - version_compare(PHP_VERSION, '6.0.0-dev') == -1 ? '' : 'u', - $string - ); - return $string; - } + /* + * Substitute the %strings used in EXPECTF sections with a regular expression + * @param string + * @return string + */ + private function expectfRegexSubstitutions($string) + { + $string = str_replace('%e', '\\' . DIRECTORY_SEPARATOR, $string); + $string = str_replace('%s', '[^\r\n]+', $string); + $string = str_replace('%S', '[^\r\n]*', $string); + $string = str_replace('%a', '.+', $string); + $string = str_replace('%A', '.*', $string); + $string = str_replace('%w', '\s*', $string); + $string = str_replace('%i', '[+-]?\d+', $string); + $string = str_replace('%d', '\d+', $string); + $string = str_replace('%x', '[0-9a-fA-F]+', $string); + $string = str_replace('%f', '[+-]?\.?\d+\.?\d*(?:[Ee][+-]?\d+)?', $string); + $string = str_replace('%c', '.', $string); - - /* - * Substitute the %strings used in EXPECTF sections with a regular expression - * @param string - * @return string - */ - private function expectfRegexSubstitutions($string) { + return $string; + } - $string = str_replace('%e', '\\' . DIRECTORY_SEPARATOR, $string); - $string = str_replace('%s', '[^\r\n]+', $string); - $string = str_replace('%S', '[^\r\n]*', $string); - $string = str_replace('%a', '.+', $string); - $string = str_replace('%A', '.*', $string); - $string = str_replace('%w', '\s*', $string); - $string = str_replace('%i', '[+-]?\d+', $string); - $string = str_replace('%d', '\d+', $string); - $string = str_replace('%x', '[0-9a-fA-F]+', $string); - $string = str_replace('%f', '[+-]?\.?\d+\.?\d*(?:[Ee][+-]?\d+)?', $string); - $string = str_replace('%c', '.', $string); - return $string; - } - - - - /** - * Compare the test output with the expected pattern - * - * @param string $testOutput - * @return boolean - */ - public function compare($testOutput) { - $testOutput = trim(preg_replace("/$this->carriageReturnLineFeed/", $this->lineFeed, $testOutput)); - - /*For debugging: - - file_put_contents(sys_get_temp_dir().'/zrtexp',$this->expectedPattern ); - file_put_contents(sys_get_temp_dir().'/zrtout', $testOutput ); + /** + * Compare the test output with the expected pattern + * + * @param string $testOutput + * @return boolean + */ + public function compare($testOutput) + { + $testOutput = trim(preg_replace("/$this->carriageReturnLineFeed/", $this->lineFeed, $testOutput)); + + /*For debugging: + + file_put_contents(sys_get_temp_dir().'/zrtexp',$this->expectedPattern ); + file_put_contents(sys_get_temp_dir().'/zrtout', $testOutput ); - */ - - if (preg_match((binary) "/^$this->expectedPattern\$/s", $testOutput)) { - return true; - } else { - return false; + */ + + if (preg_match((binary) "/^$this->expectedPattern\$/s", $testOutput)) { + return true; + } else { + return false; + } } - } } -?> \ No newline at end of file +?> diff --git a/src/testcase/sections/outputsections/rtExpectRegexSection.php b/src/testcase/sections/outputsections/rtExpectRegexSection.php index f18ef1f..0dca266 100644 --- a/src/testcase/sections/outputsections/rtExpectRegexSection.php +++ b/src/testcase/sections/outputsections/rtExpectRegexSection.php @@ -1,37 +1,36 @@ <?php - /** * Class representing expected output and actual output */ -class rtExpectRegexSection extends rtOutputSection { - - protected function init() { - parent::createPattern(); - } - - - /** - * Compare the test output with the expected pattern - * - * @param string $testOutput - * @return boolean - */ - public function compare($testOutput) { - - $testOutput = trim(preg_replace("/$this->carriageReturnLineFeed/", $this->lineFeed, $testOutput)); - - /*For debugging: +class rtExpectRegexSection extends rtOutputSection +{ + protected function init() + { + parent::createPattern(); + } - file_put_contents(sys_get_temp_dir().'/zrtexp',$this->expectedPattern ); - file_put_contents(sys_get_temp_dir().'/zrtout', $testOutput ); + /** + * Compare the test output with the expected pattern + * + * @param string $testOutput + * @return boolean + */ + public function compare($testOutput) + { + $testOutput = trim(preg_replace("/$this->carriageReturnLineFeed/", $this->lineFeed, $testOutput)); + + /*For debugging: + + file_put_contents(sys_get_temp_dir().'/zrtexp',$this->expectedPattern ); + file_put_contents(sys_get_temp_dir().'/zrtout', $testOutput ); - */ - - if (preg_match((binary) "/^$this->expectedPattern\$/s", $testOutput)) { - return true; - } else { - return false; + */ + + if (preg_match((binary) "/^$this->expectedPattern\$/s", $testOutput)) { + return true; + } else { + return false; + } } - } } -?> \ No newline at end of file +?> diff --git a/src/testcase/sections/outputsections/rtExpectSection.php b/src/testcase/sections/outputsections/rtExpectSection.php index df59033..e2d789f 100644 --- a/src/testcase/sections/outputsections/rtExpectSection.php +++ b/src/testcase/sections/outputsections/rtExpectSection.php @@ -1,29 +1,29 @@ <?php - /** * Class representing expected output and actual output */ -class rtExpectSection extends rtOutputSection { +class rtExpectSection extends rtOutputSection +{ + protected function init() + { + parent::createPattern(); + } - protected function init() { - parent::createPattern(); - } - + /** + * Compare the test output with the expected pattern + * + * @param string $testOutput + * @return boolean + */ + public function compare($testOutput) + { + $testOutput = trim(preg_replace("/$this->carriageReturnLineFeed/", $this->lineFeed, $testOutput)); - /** - * Compare the test output with the expected pattern - * - * @param string $testOutput - * @return boolean - */ - public function compare($testOutput) { - $testOutput = trim(preg_replace("/$this->carriageReturnLineFeed/", $this->lineFeed, $testOutput)); - if (strcmp($this->expectedPattern, $testOutput) == 0) { - return true; - } else { - return false; + if (strcmp($this->expectedPattern, $testOutput) == 0) { + return true; + } else { + return false; + } } - } - } -?> \ No newline at end of file +?> diff --git a/src/testcase/sections/rtConfigurationSection.php b/src/testcase/sections/rtConfigurationSection.php index 996833d..a1a34f2 100644 --- a/src/testcase/sections/rtConfigurationSection.php +++ b/src/testcase/sections/rtConfigurationSection.php @@ -1,8 +1,8 @@ <?php - - -abstract class rtConfigurationSection extends rtSection { - +/** + * + */ +abstract class rtConfigurationSection extends rtSection +{ } - -?> \ No newline at end of file +?> diff --git a/src/testcase/sections/rtExecutableSection.php b/src/testcase/sections/rtExecutableSection.php index cfed6c6..e145321 100644 --- a/src/testcase/sections/rtExecutableSection.php +++ b/src/testcase/sections/rtExecutableSection.php @@ -1,34 +1,38 @@ <?php - - -abstract class rtExecutableSection extends rtSection { - - protected $fileName; - protected $output; - protected $status; - - protected function init() { +/** + * + */ +abstract class rtExecutableSection extends rtSection +{ + protected $fileName; + protected $output; + protected $status; - } - - protected function writeExecutableFile() { - $contentsAsString = implode("\n", $this->sectionContents) ."\n"; - file_put_contents($this->fileName, (binary) $contentsAsString); - } - - public function getFileName() { - return $this->fileName; - } - - public function deleteFile() { - @unlink($this->fileName); - } - - public function getOutput() { - return $this->output; - } - - - abstract function run(rtPhpTest $testcase, rtRuntestsConfiguration $runConfiguration); + protected function init() + { + } + + protected function writeExecutableFile() + { + $contentsAsString = implode("\n", $this->sectionContents) ."\n"; + file_put_contents($this->fileName, (binary) $contentsAsString); + } + + public function getFileName() + { + return $this->fileName; + } + + public function deleteFile() + { + @unlink($this->fileName); + } + + public function getOutput() + { + return $this->output; + } + + abstract function run(rtPhpTest $testcase, rtRuntestsConfiguration $runConfiguration); } ?> diff --git a/src/testcase/sections/rtInformationSection.php b/src/testcase/sections/rtInformationSection.php index 9f1dac9..eeaf93a 100644 --- a/src/testcase/sections/rtInformationSection.php +++ b/src/testcase/sections/rtInformationSection.php @@ -1,13 +1,12 @@ <?php - /** * Class for all information sections * */ -class rtInformationSection extends rtSection { - - protected function init() { - - } +class rtInformationSection extends rtSection +{ + protected function init() + { + } } -?> \ No newline at end of file +?> diff --git a/src/testcase/sections/rtOutputSection.php b/src/testcase/sections/rtOutputSection.php index bbce322..a204f0b 100644 --- a/src/testcase/sections/rtOutputSection.php +++ b/src/testcase/sections/rtOutputSection.php @@ -1,34 +1,35 @@ <?php - /** * parent class for all expected output sections * */ +abstract class rtOutputSection extends rtSection +{ + protected $expectedPattern; + + protected function init() + { + $this->createPattern(); + } + + /** + * Create the pattern used to match against actual output + * + */ + protected function createPattern() + { + $this->expectedPattern = implode($this->lineFeed, $this->sectionContents); + $this->expectedPattern = str_replace($this->carriageReturnLineFeed, $this->lineFeed, $this->expectedPattern); -abstract class rtOutputSection extends rtSection { - - protected $expectedPattern; - - protected function init() { - $this->createPattern(); - } - - /** - * Create the pattern used to match against actual output - * - */ - protected function createPattern() { - $this->expectedPattern = implode ($this->lineFeed, $this->sectionContents ); - $this->expectedPattern = str_replace($this->carriageReturnLineFeed, $this->lineFeed, $this->expectedPattern); - - //remove any blank lines from the start and end - $this->expectedPattern = trim($this->expectedPattern); - } + //remove any blank lines from the start and end + $this->expectedPattern = trim($this->expectedPattern); + } - public function getPattern() { - return $this->expectedPattern; - } + public function getPattern() + { + return $this->expectedPattern; + } - abstract function compare($testOutput); + abstract function compare($testOutput); } ?> diff --git a/src/testcase/sections/rtSection.php b/src/testcase/sections/rtSection.php index 58378ba..cf2de24 100644 --- a/src/testcase/sections/rtSection.php +++ b/src/testcase/sections/rtSection.php @@ -1,58 +1,57 @@ <?php - /** * Parent class for all test case sections * */ -abstract class rtSection { - - private static $sectionMap = array ( - 'TEST' => 'rtTestHeaderSection', - 'SKIPIF' => 'rtSkipIfSection', - 'FILE' => 'rtFileSection', - 'EXPECT' => 'rtExpectSection', - 'EXPECTF' => 'rtExpectFSection', - 'EXPECTREGEX' => 'rtExpectRegexSection', - 'INI' => 'rtIniSection', - 'ARGS' => 'rtArgsSection', - 'ENV' => 'rtEnvSection', - 'CREDITS' => 'rtCreditsSection', - 'CLEAN' => 'rtCleanSection', - 'XFAIL' => 'rtXfailSection', - ); - - protected $sectionName; - protected $sectionContents; - - protected $carriageReturnLineFeed = "\r\n"; - protected $lineFeed = "\n"; - - - public function __construct($sectionName, $contents) - { - $this->sectionName = $sectionName; - $this->sectionContents = $contents; - $this->init(); - } - - abstract protected function init(); - - public static function getInstance($sectionName, $contents) { - - if (!isset(self::$sectionMap[$sectionName])) { - throw new RuntimeException('Unknown section type ' . $sectionName); +abstract class rtSection +{ + private static $sectionMap = array ( + 'TEST' => 'rtTestHeaderSection', + 'SKIPIF' => 'rtSkipIfSection', + 'FILE' => 'rtFileSection', + 'EXPECT' => 'rtExpectSection', + 'EXPECTF' => 'rtExpectFSection', + 'EXPECTREGEX' => 'rtExpectRegexSection', + 'INI' => 'rtIniSection', + 'ARGS' => 'rtArgsSection', + 'ENV' => 'rtEnvSection', + 'CREDITS' => 'rtCreditsSection', + 'CLEAN' => 'rtCleanSection', + 'XFAIL' => 'rtXfailSection', + ); + + protected $sectionName; + protected $sectionContents; + + protected $carriageReturnLineFeed = "\r\n"; + protected $lineFeed = "\n"; + + public function __construct($sectionName, $contents) + { + $this->sectionName = $sectionName; + $this->sectionContents = $contents; + $this->init(); } - return new rtSection::$sectionMap[$sectionName]($sectionName, $contents); - } + abstract protected function init(); - public function getName() { - return $this->sectionName; - } + public static function getInstance($sectionName, $contents) + { + if (!isset(self::$sectionMap[$sectionName])) { + throw new RuntimeException('Unknown section type ' . $sectionName); + } - public function getContents() { - return $this->sectionContents; - } + return new rtSection::$sectionMap[$sectionName]($sectionName, $contents); + } + public function getName() + { + return $this->sectionName; + } + + public function getContents() + { + return $this->sectionContents; + } } ?> diff --git a/src/testgroup/rtPhpTestGroup.php b/src/testgroup/rtPhpTestGroup.php index fb6fd4a..ad2a542 100644 --- a/src/testgroup/rtPhpTestGroup.php +++ b/src/testgroup/rtPhpTestGroup.php @@ -1,68 +1,62 @@ <?php - - /** * Runs a 'group of tests'. A 'group' is all or the tests in a single directory. * */ -class rtPhpTestGroup { - - - private $testDirectory; - private $testCases; - private $results; - - - public function __construct(rtRuntestsConfiguration $runConfiguration, $directory) { - $this->testDirectory = $directory; - $this->init($runConfiguration); - } - - - public function init(rtRuntestsConfiguration $runConfiguration) { - - $this->testFiles = rtUtil::getTestList($this->testDirectory); - - foreach($this->testFiles as $testName) { - - if(!file_exists($testName)) { - echo $testName . " "; - echo rtText::get('invalidTestFileName'); - exit(); - } - - //Create a new test file object; - $testFile = new rtPhpTestFile(); - $testFile->doRead($testName); - $testFile->normaliseLineEndings(); - - if($testFile->arePreconditionsMet() ) { - //Create a new test case - $this->testCases[] = new rtPhpTest($testFile->getContents(), $testFile->getTestName(), $testFile->getSectionHeadings(), $runConfiguration); - } else { - $this->results[] = new rtTestResults(null, $testFile->getExitMessage(), $testFile->getTestName()); - } +class rtPhpTestGroup +{ + private $testDirectory; + private $testCases; + private $results; + + public function __construct(rtRuntestsConfiguration $runConfiguration, $directory) + { + $this->testDirectory = $directory; + $this->init($runConfiguration); } - } - public function runGroup(rtRuntestsConfiguration $runConfiguration) { - - foreach ($this->testCases as $testCase) { - - $testCase->executeTest($runConfiguration); - - $testResult = new rtTestResults($testCase); - $testResult->processResults($testCase, $runConfiguration); - $this->results[] = $testResult; + public function init(rtRuntestsConfiguration $runConfiguration) + { + $this->testFiles = rtUtil::getTestList($this->testDirectory); + + foreach ($this->testFiles as $testName) { + + if (!file_exists($testName)) { + echo $testName . " "; + echo rtText::get('invalidTestFileName'); + exit(); + } + + // Create a new test file object; + $testFile = new rtPhpTestFile(); + $testFile->doRead($testName); + $testFile->normaliseLineEndings(); + + if ($testFile->arePreconditionsMet() ) { + // Create a new test case + $this->testCases[] = new rtPhpTest($testFile->getContents(), $testFile->getTestName(), $testFile->getSectionHeadings(), $runConfiguration); + } else { + $this->results[] = new rtTestResults(null, $testFile->getExitMessage(), $testFile->getTestName()); + } + } } - } - - public function writeGroup() { - $testOutputWriter = rtTestOutputWriter::getInstance($this->results, 'list'); - $testOutputWriter->write($this->testDirectory); + public function runGroup(rtRuntestsConfiguration $runConfiguration) + { + foreach ($this->testCases as $testCase) { - } + $testCase->executeTest($runConfiguration); + + $testResult = new rtTestResults($testCase); + $testResult->processResults($testCase, $runConfiguration); + $this->results[] = $testResult; + } + } + public function writeGroup() + { + $testOutputWriter = rtTestOutputWriter::getInstance($this->results, 'list'); + $testOutputWriter->write($this->testDirectory); + } } ?> diff --git a/src/testrun/rtPhpTestRun.php b/src/testrun/rtPhpTestRun.php index f75a0be..a0122e2 100644 --- a/src/testrun/rtPhpTestRun.php +++ b/src/testrun/rtPhpTestRun.php @@ -1,100 +1,98 @@ -<?php - +i<?php /** * Main class for a test run * */ -class rtPhpTestRun { - - private $commandLineArguments; - - public function __construct($argv) { - $this->commandLineArguments = $argv; - } - - public function run() { - //Set SSH variables - - //Configure the test environment - - $runConfiguration = rtRuntestsConfiguration::getInstance($this->commandLineArguments); - $runConfiguration->configure(); +class rtPhpTestRun +{ + private $commandLineArguments; + public function __construct($argv) + { + $this->commandLineArguments = $argv; + } - if($runConfiguration->getSetting('TestDirectories') != null) { - foreach($runConfiguration->getSetting('TestDirectories') as $testDirectory) { - - //make list of subdirectories which contain tests, includes the top level directory - $subDirectories = rtUtil::getDirectoryList($testDirectory); - - //Run tests in each subdirectory in sequence - foreach ($subDirectories as $subDirectory) { - $testGroup = new rtPhpTestGroup($runConfiguration, $subDirectory); - $testGroup->runGroup($runConfiguration); - $testGroup->writeGroup(); - } - } - - //*have a directory or list of directories to test. - /* if (single directory) { - * if(contains sub-directories with .phpt files) { - * if (parallel) { - * initate parallel run - * } else { - * initaite sequential run - * } - * } else { - * initiate sequential run - * } - * } else { //multiple directories - * if (parallel) { - * initiate parallel (runs the list of dirs in parallel - * } else { - * run each directory in sequence - * } - * } - * - */ - } else { - if($runConfiguration->getSetting('TestFiles') == null) { - echo rtText::get('invalidTestFileName'); - exit(); - } else { - foreach($runConfiguration->getSetting('TestFiles') as $testName) { - - if(!file_exists($testName)) { - echo $testName . " "; - echo rtText::get('invalidTestFileName'); - exit(); - } - - //Read the test file - $testFile =new rtPhpTestFile(); - $testFile->doRead($testName); - $testFile->normaliseLineEndings($testName); - if($testFile->arePreconditionsMet()) { - - $testCase = new rtPhpTest($testFile->getContents(), $testFile->getTestName(), $testFile->getSectionHeadings(), $runConfiguration); - - //Setup and set the local environment for the test case - $testCase->executeTest($runConfiguration); - - - $results = new rtTestResults($testCase); - $results->processResults($testCase, $runConfiguration); - - - - } else { - $results = new rtTestResults(null, $testFile->getExitMessage(), $testFile->getTestName()); - } - $testOutputWriter = rtTestOutputWriter::getInstance(array($results), 'list'); - $testOutputWriter->write(); - - + public function run() + { + //Set SSH variables + + //Configure the test environment + $runConfiguration = rtRuntestsConfiguration::getInstance($this->commandLineArguments); + $runConfiguration->configure(); + + if ($runConfiguration->getSetting('TestDirectories') != null) { + + foreach ($runConfiguration->getSetting('TestDirectories') as $testDirectory) { + + //make list of subdirectories which contain tests, includes the top level directory + $subDirectories = rtUtil::getDirectoryList($testDirectory); + + //Run tests in each subdirectory in sequence + foreach ($subDirectories as $subDirectory) { + $testGroup = new rtPhpTestGroup($runConfiguration, $subDirectory); + $testGroup->runGroup($runConfiguration); + $testGroup->writeGroup(); + } + } + + //*have a directory or list of directories to test. + /* if (single directory) { + * if(contains sub-directories with .phpt files) { + * if (parallel) { + * initate parallel run + * } else { + * initaite sequential run + * } + * } else { + * initiate sequential run + * } + * } else { //multiple directories + * if (parallel) { + * initiate parallel (runs the list of dirs in parallel + * } else { + * run each directory in sequence + * } + * } + * + */ + } else { + + if ($runConfiguration->getSetting('TestFiles') == null) { + echo rtText::get('invalidTestFileName'); + exit(); + } else { + foreach ($runConfiguration->getSetting('TestFiles') as $testName) { + + if (!file_exists($testName)) { + echo $testName . " "; + echo rtText::get('invalidTestFileName'); + exit(); + } + + //Read the test file + $testFile = new rtPhpTestFile(); + $testFile->doRead($testName); + $testFile->normaliseLineEndings($testName); + + if ($testFile->arePreconditionsMet()) { + + $testCase = new rtPhpTest($testFile->getContents(), $testFile->getTestName(), $testFile->getSectionHeadings(), $runConfiguration); + + //Setup and set the local environment for the test case + $testCase->executeTest($runConfiguration); + + $results = new rtTestResults($testCase); + $results->processResults($testCase, $runConfiguration); + + } else { + $results = new rtTestResults(null, $testFile->getExitMessage(), $testFile->getTestName()); + } + + $testOutputWriter = rtTestOutputWriter::getInstance(array($results), 'list'); + $testOutputWriter->write(); + } + } } - } } - } } -?> \ No newline at end of file +?>