com phpruntests: Refactored rtRuntestsConfiguration and adjusted the unit tests.: src/configuration/rtRuntestsConfiguration.php
src/configuration/rtSetting.php src/configuration/settings/rtPhpCgiExecutableSetting.php src/configuration/settings/rtPhpExecutableSetting.php
tests/configuration/settings/rtCurrentDirectorySettingTest.php tests/configuration/settings/rtLogFormatSettingTest.php
tests/configuration/settings/rtPhpCgiExecutableSettingTest.p
| From: | David Soria Parra | Date: | Tue, 12 May 2009 09:15:19 +0000 |
| Subject: | com phpruntests: Refactored rtRuntestsConfiguration and adjusted the unit tests.: src/configuration/rtRuntestsConfiguration.php src/configuration/rtSetting.php src/configuration/settings/rtPhpCgiExecutableSetting.php src/configuration/settings/rtPhpExecutableSetting.php tests/configuration/settings/rtCurrentDirectorySettingTest.php tests/configuration/settings/rtLogFormatSettingTest.php tests/configuration/settings/rtPhpCgiExecutableSettingTest.p |
||
| Groups: | php.qa | ||
| Request: | Send a blank email to php-qa+get-66484@lists.php.net to get a copy of this message | ||
Commit: 137a354f8e27c9031bf057594f7796c1a5f27c76
Author: Stefan Priebsch <spriebsch@php.net> Tue, 12 May 2009 09:15:19 +0000
Parents: 1c3f1ee6a38ae842d49443886d90de0a61309755
Branches: master
Link: http://git.php.net/?p=phpruntests.git;a=commitdiff;h=137a354f8e27c9031bf057594f7796c1a5f27c76
Log:
Refactored rtRuntestsConfiguration and adjusted the unit tests.
Changed paths:
M src/configuration/rtRuntestsConfiguration.php
M src/configuration/rtSetting.php
M src/configuration/settings/rtPhpCgiExecutableSetting.php
M src/configuration/settings/rtPhpExecutableSetting.php
M tests/configuration/settings/rtCurrentDirectorySettingTest.php
M tests/configuration/settings/rtLogFormatSettingTest.php
M tests/configuration/settings/rtPhpCgiExecutableSettingTest.php
M tests/configuration/settings/rtPhpCommandLineArgSettingTest.php
M tests/configuration/settings/rtPhpExecutableSettingTest.php
M tests/configuration/settings/rtTestDirectorySettingTest.php
M tests/configuration/settings/rtWorkingDirectorySettingTest.php
diff --git a/src/configuration/rtRuntestsConfiguration.php b/src/configuration/rtRuntestsConfiguration.php index 05d68e6..af5906d 100644 --- a/src/configuration/rtRuntestsConfiguration.php +++ b/src/configuration/rtRuntestsConfiguration.php @@ -31,19 +31,18 @@ abstract class rtRuntestsConfiguration protected $commandLineArgs; private $settings; - private $setters; private $environmentVariables; private $commandLine; private $settingNames = array ( - 'CurrentDirectory' => 'rtCurrentDirectorySetting', - 'WorkingDirectory' => 'rtWorkingDirectorySetting', - 'LogFormat' => 'rtLogFormatSetting', - 'PhpExecutable' => 'rtPhpExecutableSetting', - 'PhpCgiExecutable' => 'rtPhpCgiExecutableSetting', - 'TestFiles' => 'rtTestFileSetting', - 'TestDirectories' => 'rtTestDirectorySetting', - 'PhpCommandLineArguments' => 'rtPhpCommandLineArgSetting', + 'rtCurrentDirectorySetting', + 'rtWorkingDirectorySetting', + 'rtLogFormatSetting', + 'rtPhpExecutableSetting', + 'rtPhpCgiExecutableSetting', + 'rtTestFileSetting', + 'rtTestDirectorySetting', + 'rtPhpCommandLineArgSetting', ); protected function init() @@ -57,7 +56,9 @@ abstract class rtRuntestsConfiguration $this->environmentVariables->getUserSuppliedVariables(); } - + /** + * @todo spriebsch: is configure() the right name for this method, it checks preconditions? + */ public function configure() { //extend test command line using TEST_PHP_ARGS @@ -65,10 +66,9 @@ abstract class rtRuntestsConfiguration $options->parseAdditionalOptions($this->commandLine, $this->environmentVariables); //set configuration - foreach ($this->settingNames as $name => $setting) { - $this->setters[$name] = new $setting($this); - $methodName = 'set' . $name; - $this->$methodName(); + foreach ($this->settingNames as $className) { + $object = new $className($this); + $this->settings[$className] = $object->get(); } //check configuration preconditions @@ -76,10 +76,7 @@ abstract class rtRuntestsConfiguration // $preConditionList->check($this->commandLine, $this->environmentVariables); - $preConditionList->check($this); - - - + $preConditionList->check($this); } /** @@ -97,85 +94,6 @@ abstract class rtRuntestsConfiguration } /** - * Sets the directory that run-tests was started from - * - */ - private function setCurrentDirectory() - { - $this->settings['CurrentDirectory']= $this->setters['CurrentDirectory']->get(); - } - - /** - * Sets the directory that run-tests is run from - * - */ - private function setWorkingDirectory() - { - $this->settings['WorkingDirectory']= $this->setters['WorkingDirectory']->get(); - } - - /** - * Sets the PHP executable being used to run teh tests - * - */ - private function setPhpExecutable() - { - $this->settings['PhpExecutable']= $this->setters['PhpExecutable']->get(); - } - - /** - * Sets the PHP GGI executable being used to run the tests - * - */ - private function setPhpCgiExecutable() - { - //If the CGI executable hasn't been set using an environmental variable or 'auto', try and derive it from - //the name of the cli executable. - //TODO This is *ix specific, need a WIN specific class PhpCgiExecutable setting class - if($this->setters['PhpCgiExecutable']->get() == null) { - $this->setters['PhpCgiExecutable']->setFromPhpCli($this->settings['PhpExecutable']); - } - $this->settings['PhpCgiExecutable']= $this->setters['PhpCgiExecutable']->get(); - } - - /** - * Sets the log format - * - */ - private function setLogFormat() - { - $this->settings['LogFormat']= $this->setters['LogFormat']->get(); - } - - /** - * Sets the command line arguments for PHP - * - */ - private function setPhpCommandLineArguments() - { - $this->settings['PhpCommandLineArguments']= $this->setters['PhpCommandLineArguments']->get(); - } - - /** - * Sets the names of directories to be tested - * - */ - private function setTestDirectories() - { - $this->settings['TestDirectories'] = $this->setters['TestDirectories']->get(); - } - - /** - * Sets the names of files to be tested - * - * @param array $testFiles - */ - private function setTestFiles() - { - $this->settings['TestFiles'] = $this->setters['TestFiles']->get(); - } - - /** * Returns the value of a setting * * @param string $settingName diff --git a/src/configuration/rtSetting.php b/src/configuration/rtSetting.php index 30d10d2..6fb7c8b 100644 --- a/src/configuration/rtSetting.php +++ b/src/configuration/rtSetting.php @@ -1,7 +1,11 @@ <?php /** - * Classes that set things in the test configuration + * Classes that set things in the test configuration. + * Settings may instantiate other settings to retrieve values they need. + * This leads to some settings being instantiated multiple times, and + * being redundantly calculated, but makes settings independent from the order + * in which they are processed in rtRuntestsConfiguration. * */ abstract class rtSetting diff --git a/src/configuration/settings/rtPhpCgiExecutableSetting.php b/src/configuration/settings/rtPhpCgiExecutableSetting.php index 639a265..02665d1 100644 --- a/src/configuration/settings/rtPhpCgiExecutableSetting.php +++ b/src/configuration/settings/rtPhpCgiExecutableSetting.php @@ -10,29 +10,31 @@ class rtPhpCgiExecutableSetting extends rtSetting private $phpCgiExecutable; + private $configuration; + /** * Sets the PHP CGI executable. Note the dependency on having a working directory setting * */ public function init(rtRuntestsConfiguration $configuration) { - + $this->configuration = $configuration; if ($configuration->hasEnvironmentVariable('TEST_PHP_CGI_EXECUTABLE')) { if ($configuration->getEnvironmentVariable('TEST_PHP_CGI_EXECUTABLE') == 'auto') { - $this->phpCgiExecutable = $configuration->getSetting('WorkingDirectory') . self::SAPI_CGI; + + $rtWorkingDirectorySetting = new rtWorkingDirectorySetting($configuration); + $this->phpCgiExecutable = $rtWorkingDirectorySetting->get() . self::SAPI_CGI; } else { $this->phpCgiExecutable = $configuration->getEnvironmentVariable('TEST_PHP_CGI_EXECUTABLE'); } - } else { - $this->phpCgiExecutable = null; } } /** - * + * @todo spriebsch: does this method need to be public, is it only called from get()? */ - public function setFromPhpCli($phpCli) + public function guessFromPhpCli($phpCli) { if(substr(dirname($phpCli),-3) == 'cli') { $pathLength = strlen(dirname($phpCli)) - 3; @@ -40,15 +42,23 @@ class rtPhpCgiExecutableSetting extends rtSetting $this->phpCgiExecutable = $sapiDir."cgi/php-cgi"; } } - - + /** - * Supply the setting to the configuration on request + * Returns path to PHP CGI executable. + * If not set, we guess based on the path to the PHP CLI executable. * + * @return string */ public function get() { + if (is_null($this->phpCgiExecutable)) { + + // We ask rtPhpExecutableSetting for the path to the PHP executable. + $rtPhpExecutableSetting = new rtPhpExecutableSetting($this->configuration); + $this->guessFromPhpCli($rtPhpExecutableSetting->get()); + } + return $this->phpCgiExecutable; } -} +} ?> diff --git a/src/configuration/settings/rtPhpExecutableSetting.php b/src/configuration/settings/rtPhpExecutableSetting.php index 5c6329e..ec32ef6 100644 --- a/src/configuration/settings/rtPhpExecutableSetting.php +++ b/src/configuration/settings/rtPhpExecutableSetting.php @@ -16,11 +16,12 @@ class rtPhpExecutableSetting extends rtSetting */ public function init(rtRuntestsConfiguration $configuration) { - if ($configuration->hasEnvironmentVariable('TEST_PHP_EXECUTABLE')) { - if ($configuration->getEnvironmentVariable('TEST_PHP_EXECUTABLE') == 'auto') { - $this->phpExecutable = $configuration->getSetting('WorkingDirectory').self::SAPI_CLI; + if ($configuration->getEnvironmentVariable('TEST_PHP_EXECUTABLE') == 'auto') { + + $rtWorkingDirectorySetting = new rtWorkingDirectorySetting($configuration); + $this->phpExecutable = $rtWorkingDirectorySetting->get() . self::SAPI_CLI; } else { $this->phpExecutable = $configuration->getEnvironmentVariable('TEST_PHP_EXECUTABLE'); } @@ -40,5 +41,4 @@ class rtPhpExecutableSetting extends rtSetting return $this->phpExecutable; } } - ?> diff --git a/tests/configuration/settings/rtCurrentDirectorySettingTest.php b/tests/configuration/settings/rtCurrentDirectorySettingTest.php index 22ac996..d2f91ea 100644 --- a/tests/configuration/settings/rtCurrentDirectorySettingTest.php +++ b/tests/configuration/settings/rtCurrentDirectorySettingTest.php @@ -8,9 +8,9 @@ class rtCurrentDirectorySettingTest extends PHPUnit_Framework_TestCase public function testSetting() { $configuration = rtRuntestsConfiguration::getInstance(array('run-tests.php', '-p', 'a-php-exe', 'test.phpt')); - $dirsetting = new rtCurrentDirectorySetting($configuration); + $setting = new rtCurrentDirectorySetting($configuration); - $this->assertEquals(realpath(getcwd()), $dirsetting->get()); + $this->assertEquals(realpath(getcwd()), $setting->get()); } } ?> diff --git a/tests/configuration/settings/rtLogFormatSettingTest.php b/tests/configuration/settings/rtLogFormatSettingTest.php index e2db2e9..50793e9 100644 --- a/tests/configuration/settings/rtLogFormatSettingTest.php +++ b/tests/configuration/settings/rtLogFormatSettingTest.php @@ -9,16 +9,16 @@ class rtLogFormatSettingTest extends PHPUnit_Framework_TestCase $configuration = rtRuntestsConfiguration::getInstance(array('run-tests.php', '-p', 'a-php-exe', 'test.phpt')); $configuration->setEnvironmentVariable('TEST_PHP_LOG_FORMAT', 'some-log-format'); - $logsetting = new rtLogFormatSetting($configuration); + $setting = new rtLogFormatSetting($configuration); - $this->assertEquals('SOME-LOG-FORMAT', $logsetting->get()); + $this->assertEquals('SOME-LOG-FORMAT', $setting->get()); } public function testSetLEOD() { $configuration = rtRuntestsConfiguration::getInstance(array('run-tests.php', '-p', 'a-php-exe', 'test.phpt')); - $logsetting = new rtLogFormatSetting($configuration); + $setting = new rtLogFormatSetting($configuration); - $this->assertEquals('LEOD', $logsetting->get()); + $this->assertEquals('LEOD', $setting->get()); } } ?> diff --git a/tests/configuration/settings/rtPhpCgiExecutableSettingTest.php b/tests/configuration/settings/rtPhpCgiExecutableSettingTest.php index 4483d03..2c1ae79 100644 --- a/tests/configuration/settings/rtPhpCgiExecutableSettingTest.php +++ b/tests/configuration/settings/rtPhpCgiExecutableSettingTest.php @@ -8,27 +8,31 @@ class rtPhpCgiExecutableSettingTest extends PHPUnit_Framework_TestCase public function testSetPhpCgiExecutableEV() { $configuration = rtRuntestsConfiguration::getInstance(array('run-tests.php', 'test.phpt')); $configuration->setEnvironmentVariable('TEST_PHP_CGI_EXECUTABLE', 'a-php-executable'); - $cgisetting = new rtPhpCgiExecutableSetting($configuration); - $this->assertEquals('a-php-executable', $cgisetting->get()); + $setting = new rtPhpCgiExecutableSetting($configuration); + + $this->assertEquals('a-php-executable', $setting->get()); } public function testSetPhpCgiExecutableEVAuto() { - $configuration = rtRuntestsConfiguration::getInstance(array('run-tests.php','-p', 'a-php-exe', 'test.phpt')); + $configuration = rtRuntestsConfiguration::getInstance(array('run-tests.php', '-p', 'a-php-exe', 'test.phpt')); $configuration->setEnvironmentVariable('TEST_PHP_CGI_EXECUTABLE', 'auto'); - $configuration->configure(); - $this->assertEquals(realpath(getcwd()).'/sapi/cgi/php', $configuration->getSetting('PhpCgiExecutable')); + $setting = new rtPhpCgiExecutableSetting($configuration); + + $this->assertEquals(realpath(getcwd()).'/sapi/cgi/php-cgi', $setting->get('PhpCgiExecutable')); } public function testSetPhpCgiExecutableNotSet() { $configuration = rtRuntestsConfiguration::getInstance(array('run-tests.php', 'test.phpt')); - $cgisetting = new rtPhpCgiExecutableSetting($configuration); - $this->assertEquals(null, $cgisetting->get()); + $setting = new rtPhpCgiExecutableSetting($configuration); + + $this->assertEquals(null, $setting->get()); } public function testSetFromCliExecutableName() { - $config = rtRuntestsConfiguration::getInstance(array('run-tests.php', '-p', '/a/sapi/cli/a-php-exe', 'test.phpt')); - $config->configure(); - $this->assertEquals('/a/sapi/cgi/php', $config->getSetting('PhpCgiExecutable')); + $configuration = rtRuntestsConfiguration::getInstance(array('run-tests.php', '-p', '/a/sapi/cli/a-php-exe', 'test.phpt')); + $setting = new rtPhpCgiExecutableSetting($configuration); + + $this->assertEquals('/a/sapi/cgi/php-cgi', $setting->get()); } } ?> diff --git a/tests/configuration/settings/rtPhpCommandLineArgSettingTest.php b/tests/configuration/settings/rtPhpCommandLineArgSettingTest.php index 6f54aa1..6d37e33 100644 --- a/tests/configuration/settings/rtPhpCommandLineArgSettingTest.php +++ b/tests/configuration/settings/rtPhpCommandLineArgSettingTest.php @@ -9,8 +9,8 @@ class rtCommandLineArgSettingTest extends PHPUnit_Framework_TestCase { $configuration = rtRuntestsConfiguration::getInstance(array('run-tests.php', '-p', 'a-php-executable')); - $clArgsetting = new rtPhpCommandLineArgSetting($configuration); - $last49 = addslashes(substr($clArgsetting->get(), -49)); + $setting = new rtPhpCommandLineArgSetting($configuration); + $last49 = addslashes(substr($setting->get(), -49)); $this->assertEquals('-d \"unicode.from_error_mode=U_INVALID_SUBSTITUTE\"', $last49); } diff --git a/tests/configuration/settings/rtPhpExecutableSettingTest.php b/tests/configuration/settings/rtPhpExecutableSettingTest.php index 58a831a..27a6007 100644 --- a/tests/configuration/settings/rtPhpExecutableSettingTest.php +++ b/tests/configuration/settings/rtPhpExecutableSettingTest.php @@ -5,41 +5,40 @@ require_once dirname(__FILE__) . '../../../../src/rtAutoload.php'; class rtPhpExecutableSettingTest extends PHPUnit_Framework_TestCase { - public function testSetPhpExecutable() + public function testSetPhpExecutableFromCommandLineOption() { $configuration = rtRuntestsConfiguration::getInstance(array('run-tests.php', '-p', 'a-php-executable')); + $setting = new rtPhpExecutableSetting($configuration); - $clisetting = new rtPhpExecutableSetting($configuration); - - $this->assertEquals('a-php-executable', $clisetting->get()); + $this->assertEquals('a-php-executable', $setting->get()); } - public function testSetPhpExecutableEV() + public function testSetPhpExecutableFromEnvironmentVariable() { $configuration = rtRuntestsConfiguration::getInstance(array('run-tests.php')); $configuration->setEnvironmentVariable('TEST_PHP_EXECUTABLE', 'a-php-executable'); + $setting = new rtPhpExecutableSetting($configuration); - $clisetting = new rtPhpExecutableSetting($configuration); - - $this->assertEquals('a-php-executable', $clisetting->get()); + $this->assertEquals('a-php-executable', $setting->get()); } - public function testSetPhpExecutableEvAuto() + public function testSetPhpExecutableAutomaticallyFromEnvironmentVariable() { $configuration = rtRuntestsConfiguration::getInstance(array('run-tests.php', 'test.phpt')); $configuration->setEnvironmentVariable('TEST_PHP_EXECUTABLE', 'auto'); $configuration->setEnvironmentVariable('TEST_PHP_SRCDIR', '/some/directory'); - $configuration->configure(); - $this->assertEquals('/some/directory/sapi/cli/php', $configuration->getSetting('PhpExecutable')); + $setting = new rtPhpExecutableSetting($configuration); + + $this->assertEquals('/some/directory/sapi/cli/php', $setting->get('PhpExecutable')); } - public function testSetPhpExecutableCwdAuto() + public function testSetPhpExecutableAutomaticallyFromEnvironmentVariableAndWorkingDirectory() { $configuration = rtRuntestsConfiguration::getInstance(array('run-tests.php', 'test.phpt')); $configuration->setEnvironmentVariable('TEST_PHP_EXECUTABLE', 'auto'); - $configuration->configure(); + $setting = new rtPhpExecutableSetting($configuration); - $this->assertEquals(realpath(getcwd()).'/sapi/cli/php', $configuration->getSetting('PhpExecutable')); + $this->assertEquals(realpath(getcwd()).'/sapi/cli/php', $setting->get('PhpExecutable')); } } ?> diff --git a/tests/configuration/settings/rtTestDirectorySettingTest.php b/tests/configuration/settings/rtTestDirectorySettingTest.php index c8bb64d..1fe9852 100644 --- a/tests/configuration/settings/rtTestDirectorySettingTest.php +++ b/tests/configuration/settings/rtTestDirectorySettingTest.php @@ -17,12 +17,9 @@ class rtTestDirectorySettingsTest extends PHPUnit_Framework_TestCase public function testSet() { $configuration = rtRuntestsConfiguration::getInstance(array('run-tests.php', '-p', 'a-php-exe', $this->d1, $this->d2)); - $testdirsetting = new rtTestDirectorySetting($configuration); + $setting = new rtTestDirectorySetting($configuration); - $dirlist = $testdirsetting->get(); - - $this->assertEquals($dirlist[0], $this->d1); - $this->assertEquals($dirlist[1], $this->d2); + $this->assertEquals($setting->get(), array($this->d1, $this->d2)); } } ?> diff --git a/tests/configuration/settings/rtWorkingDirectorySettingTest.php b/tests/configuration/settings/rtWorkingDirectorySettingTest.php index 8731431..cfa874d 100644 --- a/tests/configuration/settings/rtWorkingDirectorySettingTest.php +++ b/tests/configuration/settings/rtWorkingDirectorySettingTest.php @@ -8,18 +8,18 @@ class rtWorkingDirectorySettingTest extends PHPUnit_Framework_TestCase public function testSet() { $configuration = rtRuntestsConfiguration::getInstance(array('run-tests.php', '-p', 'a-php-exe', 'test.phpt')); - $dirsetting = new rtWorkingDirectorySetting($configuration); + $setting = new rtWorkingDirectorySetting($configuration); - $this->assertEquals(getcwd(), $dirsetting->get()); + $this->assertEquals(getcwd(), $setting->get()); } public function testSetFromEnv() { $configuration = rtRuntestsConfiguration::getInstance(array('run-tests.php', '-p', 'a-php-exe', 'test.phpt')); $configuration->setEnvironmentVariable('TEST_PHP_SRCDIR', 'the-source-dir'); - $dirsetting = new rtWorkingDirectorySetting($configuration); + $setting = new rtWorkingDirectorySetting($configuration); - $this->assertEquals('the-source-dir', $dirsetting->get()); + $this->assertEquals('the-source-dir', $setting->get()); } } ?>
diff --git a/src/configuration/rtRuntestsConfiguration.php b/src/configuration/rtRuntestsConfiguration.php index 05d68e6..af5906d 100644 --- a/src/configuration/rtRuntestsConfiguration.php +++ b/src/configuration/rtRuntestsConfiguration.php @@ -31,19 +31,18 @@ abstract class rtRuntestsConfiguration protected $commandLineArgs; private $settings; - private $setters; private $environmentVariables; private $commandLine; private $settingNames = array ( - 'CurrentDirectory' => 'rtCurrentDirectorySetting', - 'WorkingDirectory' => 'rtWorkingDirectorySetting', - 'LogFormat' => 'rtLogFormatSetting', - 'PhpExecutable' => 'rtPhpExecutableSetting', - 'PhpCgiExecutable' => 'rtPhpCgiExecutableSetting', - 'TestFiles' => 'rtTestFileSetting', - 'TestDirectories' => 'rtTestDirectorySetting', - 'PhpCommandLineArguments' => 'rtPhpCommandLineArgSetting', + 'rtCurrentDirectorySetting', + 'rtWorkingDirectorySetting', + 'rtLogFormatSetting', + 'rtPhpExecutableSetting', + 'rtPhpCgiExecutableSetting', + 'rtTestFileSetting', + 'rtTestDirectorySetting', + 'rtPhpCommandLineArgSetting', ); protected function init() @@ -57,7 +56,9 @@ abstract class rtRuntestsConfiguration $this->environmentVariables->getUserSuppliedVariables(); } - + /** + * @todo spriebsch: is configure() the right name for this method, it checks preconditions? + */ public function configure() { //extend test command line using TEST_PHP_ARGS @@ -65,10 +66,9 @@ abstract class rtRuntestsConfiguration $options->parseAdditionalOptions($this->commandLine, $this->environmentVariables); //set configuration - foreach ($this->settingNames as $name => $setting) { - $this->setters[$name] = new $setting($this); - $methodName = 'set' . $name; - $this->$methodName(); + foreach ($this->settingNames as $className) { + $object = new $className($this); + $this->settings[$className] = $object->get(); } //check configuration preconditions @@ -76,10 +76,7 @@ abstract class rtRuntestsConfiguration // $preConditionList->check($this->commandLine, $this->environmentVariables); - $preConditionList->check($this); - - - + $preConditionList->check($this); } /** @@ -97,85 +94,6 @@ abstract class rtRuntestsConfiguration } /** - * Sets the directory that run-tests was started from - * - */ - private function setCurrentDirectory() - { - $this->settings['CurrentDirectory']= $this->setters['CurrentDirectory']->get(); - } - - /** - * Sets the directory that run-tests is run from - * - */ - private function setWorkingDirectory() - { - $this->settings['WorkingDirectory']= $this->setters['WorkingDirectory']->get(); - } - - /** - * Sets the PHP executable being used to run teh tests - * - */ - private function setPhpExecutable() - { - $this->settings['PhpExecutable']= $this->setters['PhpExecutable']->get(); - } - - /** - * Sets the PHP GGI executable being used to run the tests - * - */ - private function setPhpCgiExecutable() - { - //If the CGI executable hasn't been set using an environmental variable or 'auto', try and derive it from - //the name of the cli executable. - //TODO This is *ix specific, need a WIN specific class PhpCgiExecutable setting class - if($this->setters['PhpCgiExecutable']->get() == null) { - $this->setters['PhpCgiExecutable']->setFromPhpCli($this->settings['PhpExecutable']); - } - $this->settings['PhpCgiExecutable']= $this->setters['PhpCgiExecutable']->get(); - } - - /** - * Sets the log format - * - */ - private function setLogFormat() - { - $this->settings['LogFormat']= $this->setters['LogFormat']->get(); - } - - /** - * Sets the command line arguments for PHP - * - */ - private function setPhpCommandLineArguments() - { - $this->settings['PhpCommandLineArguments']= $this->setters['PhpCommandLineArguments']->get(); - } - - /** - * Sets the names of directories to be tested - * - */ - private function setTestDirectories() - { - $this->settings['TestDirectories'] = $this->setters['TestDirectories']->get(); - } - - /** - * Sets the names of files to be tested - * - * @param array $testFiles - */ - private function setTestFiles() - { - $this->settings['TestFiles'] = $this->setters['TestFiles']->get(); - } - - /** * Returns the value of a setting * * @param string $settingName diff --git a/src/configuration/rtSetting.php b/src/configuration/rtSetting.php index 30d10d2..6fb7c8b 100644 --- a/src/configuration/rtSetting.php +++ b/src/configuration/rtSetting.php @@ -1,7 +1,11 @@ <?php /** - * Classes that set things in the test configuration + * Classes that set things in the test configuration. + * Settings may instantiate other settings to retrieve values they need. + * This leads to some settings being instantiated multiple times, and + * being redundantly calculated, but makes settings independent from the order + * in which they are processed in rtRuntestsConfiguration. * */ abstract class rtSetting diff --git a/src/configuration/settings/rtPhpCgiExecutableSetting.php b/src/configuration/settings/rtPhpCgiExecutableSetting.php index 639a265..02665d1 100644 --- a/src/configuration/settings/rtPhpCgiExecutableSetting.php +++ b/src/configuration/settings/rtPhpCgiExecutableSetting.php @@ -10,29 +10,31 @@ class rtPhpCgiExecutableSetting extends rtSetting private $phpCgiExecutable; + private $configuration; + /** * Sets the PHP CGI executable. Note the dependency on having a working directory setting * */ public function init(rtRuntestsConfiguration $configuration) { - + $this->configuration = $configuration; if ($configuration->hasEnvironmentVariable('TEST_PHP_CGI_EXECUTABLE')) { if ($configuration->getEnvironmentVariable('TEST_PHP_CGI_EXECUTABLE') == 'auto') { - $this->phpCgiExecutable = $configuration->getSetting('WorkingDirectory') . self::SAPI_CGI; + + $rtWorkingDirectorySetting = new rtWorkingDirectorySetting($configuration); + $this->phpCgiExecutable = $rtWorkingDirectorySetting->get() . self::SAPI_CGI; } else { $this->phpCgiExecutable = $configuration->getEnvironmentVariable('TEST_PHP_CGI_EXECUTABLE'); } - } else { - $this->phpCgiExecutable = null; } } /** - * + * @todo spriebsch: does this method need to be public, is it only called from get()? */ - public function setFromPhpCli($phpCli) + public function guessFromPhpCli($phpCli) { if(substr(dirname($phpCli),-3) == 'cli') { $pathLength = strlen(dirname($phpCli)) - 3; @@ -40,15 +42,23 @@ class rtPhpCgiExecutableSetting extends rtSetting $this->phpCgiExecutable = $sapiDir."cgi/php-cgi"; } } - - + /** - * Supply the setting to the configuration on request + * Returns path to PHP CGI executable. + * If not set, we guess based on the path to the PHP CLI executable. * + * @return string */ public function get() { + if (is_null($this->phpCgiExecutable)) { + + // We ask rtPhpExecutableSetting for the path to the PHP executable. + $rtPhpExecutableSetting = new rtPhpExecutableSetting($this->configuration); + $this->guessFromPhpCli($rtPhpExecutableSetting->get()); + } + return $this->phpCgiExecutable; } -} +} ?> diff --git a/src/configuration/settings/rtPhpExecutableSetting.php b/src/configuration/settings/rtPhpExecutableSetting.php index 5c6329e..ec32ef6 100644 --- a/src/configuration/settings/rtPhpExecutableSetting.php +++ b/src/configuration/settings/rtPhpExecutableSetting.php @@ -16,11 +16,12 @@ class rtPhpExecutableSetting extends rtSetting */ public function init(rtRuntestsConfiguration $configuration) { - if ($configuration->hasEnvironmentVariable('TEST_PHP_EXECUTABLE')) { - if ($configuration->getEnvironmentVariable('TEST_PHP_EXECUTABLE') == 'auto') { - $this->phpExecutable = $configuration->getSetting('WorkingDirectory').self::SAPI_CLI; + if ($configuration->getEnvironmentVariable('TEST_PHP_EXECUTABLE') == 'auto') { + + $rtWorkingDirectorySetting = new rtWorkingDirectorySetting($configuration); + $this->phpExecutable = $rtWorkingDirectorySetting->get() . self::SAPI_CLI; } else { $this->phpExecutable = $configuration->getEnvironmentVariable('TEST_PHP_EXECUTABLE'); } @@ -40,5 +41,4 @@ class rtPhpExecutableSetting extends rtSetting return $this->phpExecutable; } } - ?> diff --git a/tests/configuration/settings/rtCurrentDirectorySettingTest.php b/tests/configuration/settings/rtCurrentDirectorySettingTest.php index 22ac996..d2f91ea 100644 --- a/tests/configuration/settings/rtCurrentDirectorySettingTest.php +++ b/tests/configuration/settings/rtCurrentDirectorySettingTest.php @@ -8,9 +8,9 @@ class rtCurrentDirectorySettingTest extends PHPUnit_Framework_TestCase public function testSetting() { $configuration = rtRuntestsConfiguration::getInstance(array('run-tests.php', '-p', 'a-php-exe', 'test.phpt')); - $dirsetting = new rtCurrentDirectorySetting($configuration); + $setting = new rtCurrentDirectorySetting($configuration); - $this->assertEquals(realpath(getcwd()), $dirsetting->get()); + $this->assertEquals(realpath(getcwd()), $setting->get()); } } ?> diff --git a/tests/configuration/settings/rtLogFormatSettingTest.php b/tests/configuration/settings/rtLogFormatSettingTest.php index e2db2e9..50793e9 100644 --- a/tests/configuration/settings/rtLogFormatSettingTest.php +++ b/tests/configuration/settings/rtLogFormatSettingTest.php @@ -9,16 +9,16 @@ class rtLogFormatSettingTest extends PHPUnit_Framework_TestCase $configuration = rtRuntestsConfiguration::getInstance(array('run-tests.php', '-p', 'a-php-exe', 'test.phpt')); $configuration->setEnvironmentVariable('TEST_PHP_LOG_FORMAT', 'some-log-format'); - $logsetting = new rtLogFormatSetting($configuration); + $setting = new rtLogFormatSetting($configuration); - $this->assertEquals('SOME-LOG-FORMAT', $logsetting->get()); + $this->assertEquals('SOME-LOG-FORMAT', $setting->get()); } public function testSetLEOD() { $configuration = rtRuntestsConfiguration::getInstance(array('run-tests.php', '-p', 'a-php-exe', 'test.phpt')); - $logsetting = new rtLogFormatSetting($configuration); + $setting = new rtLogFormatSetting($configuration); - $this->assertEquals('LEOD', $logsetting->get()); + $this->assertEquals('LEOD', $setting->get()); } } ?> diff --git a/tests/configuration/settings/rtPhpCgiExecutableSettingTest.php b/tests/configuration/settings/rtPhpCgiExecutableSettingTest.php index 4483d03..2c1ae79 100644 --- a/tests/configuration/settings/rtPhpCgiExecutableSettingTest.php +++ b/tests/configuration/settings/rtPhpCgiExecutableSettingTest.php @@ -8,27 +8,31 @@ class rtPhpCgiExecutableSettingTest extends PHPUnit_Framework_TestCase public function testSetPhpCgiExecutableEV() { $configuration = rtRuntestsConfiguration::getInstance(array('run-tests.php', 'test.phpt')); $configuration->setEnvironmentVariable('TEST_PHP_CGI_EXECUTABLE', 'a-php-executable'); - $cgisetting = new rtPhpCgiExecutableSetting($configuration); - $this->assertEquals('a-php-executable', $cgisetting->get()); + $setting = new rtPhpCgiExecutableSetting($configuration); + + $this->assertEquals('a-php-executable', $setting->get()); } public function testSetPhpCgiExecutableEVAuto() { - $configuration = rtRuntestsConfiguration::getInstance(array('run-tests.php','-p', 'a-php-exe', 'test.phpt')); + $configuration = rtRuntestsConfiguration::getInstance(array('run-tests.php', '-p', 'a-php-exe', 'test.phpt')); $configuration->setEnvironmentVariable('TEST_PHP_CGI_EXECUTABLE', 'auto'); - $configuration->configure(); - $this->assertEquals(realpath(getcwd()).'/sapi/cgi/php', $configuration->getSetting('PhpCgiExecutable')); + $setting = new rtPhpCgiExecutableSetting($configuration); + + $this->assertEquals(realpath(getcwd()).'/sapi/cgi/php-cgi', $setting->get('PhpCgiExecutable')); } public function testSetPhpCgiExecutableNotSet() { $configuration = rtRuntestsConfiguration::getInstance(array('run-tests.php', 'test.phpt')); - $cgisetting = new rtPhpCgiExecutableSetting($configuration); - $this->assertEquals(null, $cgisetting->get()); + $setting = new rtPhpCgiExecutableSetting($configuration); + + $this->assertEquals(null, $setting->get()); } public function testSetFromCliExecutableName() { - $config = rtRuntestsConfiguration::getInstance(array('run-tests.php', '-p', '/a/sapi/cli/a-php-exe', 'test.phpt')); - $config->configure(); - $this->assertEquals('/a/sapi/cgi/php', $config->getSetting('PhpCgiExecutable')); + $configuration = rtRuntestsConfiguration::getInstance(array('run-tests.php', '-p', '/a/sapi/cli/a-php-exe', 'test.phpt')); + $setting = new rtPhpCgiExecutableSetting($configuration); + + $this->assertEquals('/a/sapi/cgi/php-cgi', $setting->get()); } } ?> diff --git a/tests/configuration/settings/rtPhpCommandLineArgSettingTest.php b/tests/configuration/settings/rtPhpCommandLineArgSettingTest.php index 6f54aa1..6d37e33 100644 --- a/tests/configuration/settings/rtPhpCommandLineArgSettingTest.php +++ b/tests/configuration/settings/rtPhpCommandLineArgSettingTest.php @@ -9,8 +9,8 @@ class rtCommandLineArgSettingTest extends PHPUnit_Framework_TestCase { $configuration = rtRuntestsConfiguration::getInstance(array('run-tests.php', '-p', 'a-php-executable')); - $clArgsetting = new rtPhpCommandLineArgSetting($configuration); - $last49 = addslashes(substr($clArgsetting->get(), -49)); + $setting = new rtPhpCommandLineArgSetting($configuration); + $last49 = addslashes(substr($setting->get(), -49)); $this->assertEquals('-d \"unicode.from_error_mode=U_INVALID_SUBSTITUTE\"', $last49); } diff --git a/tests/configuration/settings/rtPhpExecutableSettingTest.php b/tests/configuration/settings/rtPhpExecutableSettingTest.php index 58a831a..27a6007 100644 --- a/tests/configuration/settings/rtPhpExecutableSettingTest.php +++ b/tests/configuration/settings/rtPhpExecutableSettingTest.php @@ -5,41 +5,40 @@ require_once dirname(__FILE__) . '../../../../src/rtAutoload.php'; class rtPhpExecutableSettingTest extends PHPUnit_Framework_TestCase { - public function testSetPhpExecutable() + public function testSetPhpExecutableFromCommandLineOption() { $configuration = rtRuntestsConfiguration::getInstance(array('run-tests.php', '-p', 'a-php-executable')); + $setting = new rtPhpExecutableSetting($configuration); - $clisetting = new rtPhpExecutableSetting($configuration); - - $this->assertEquals('a-php-executable', $clisetting->get()); + $this->assertEquals('a-php-executable', $setting->get()); } - public function testSetPhpExecutableEV() + public function testSetPhpExecutableFromEnvironmentVariable() { $configuration = rtRuntestsConfiguration::getInstance(array('run-tests.php')); $configuration->setEnvironmentVariable('TEST_PHP_EXECUTABLE', 'a-php-executable'); + $setting = new rtPhpExecutableSetting($configuration); - $clisetting = new rtPhpExecutableSetting($configuration); - - $this->assertEquals('a-php-executable', $clisetting->get()); + $this->assertEquals('a-php-executable', $setting->get()); } - public function testSetPhpExecutableEvAuto() + public function testSetPhpExecutableAutomaticallyFromEnvironmentVariable() { $configuration = rtRuntestsConfiguration::getInstance(array('run-tests.php', 'test.phpt')); $configuration->setEnvironmentVariable('TEST_PHP_EXECUTABLE', 'auto'); $configuration->setEnvironmentVariable('TEST_PHP_SRCDIR', '/some/directory'); - $configuration->configure(); - $this->assertEquals('/some/directory/sapi/cli/php', $configuration->getSetting('PhpExecutable')); + $setting = new rtPhpExecutableSetting($configuration); + + $this->assertEquals('/some/directory/sapi/cli/php', $setting->get('PhpExecutable')); } - public function testSetPhpExecutableCwdAuto() + public function testSetPhpExecutableAutomaticallyFromEnvironmentVariableAndWorkingDirectory() { $configuration = rtRuntestsConfiguration::getInstance(array('run-tests.php', 'test.phpt')); $configuration->setEnvironmentVariable('TEST_PHP_EXECUTABLE', 'auto'); - $configuration->configure(); + $setting = new rtPhpExecutableSetting($configuration); - $this->assertEquals(realpath(getcwd()).'/sapi/cli/php', $configuration->getSetting('PhpExecutable')); + $this->assertEquals(realpath(getcwd()).'/sapi/cli/php', $setting->get('PhpExecutable')); } } ?> diff --git a/tests/configuration/settings/rtTestDirectorySettingTest.php b/tests/configuration/settings/rtTestDirectorySettingTest.php index c8bb64d..1fe9852 100644 --- a/tests/configuration/settings/rtTestDirectorySettingTest.php +++ b/tests/configuration/settings/rtTestDirectorySettingTest.php @@ -17,12 +17,9 @@ class rtTestDirectorySettingsTest extends PHPUnit_Framework_TestCase public function testSet() { $configuration = rtRuntestsConfiguration::getInstance(array('run-tests.php', '-p', 'a-php-exe', $this->d1, $this->d2)); - $testdirsetting = new rtTestDirectorySetting($configuration); + $setting = new rtTestDirectorySetting($configuration); - $dirlist = $testdirsetting->get(); - - $this->assertEquals($dirlist[0], $this->d1); - $this->assertEquals($dirlist[1], $this->d2); + $this->assertEquals($setting->get(), array($this->d1, $this->d2)); } } ?> diff --git a/tests/configuration/settings/rtWorkingDirectorySettingTest.php b/tests/configuration/settings/rtWorkingDirectorySettingTest.php index 8731431..cfa874d 100644 --- a/tests/configuration/settings/rtWorkingDirectorySettingTest.php +++ b/tests/configuration/settings/rtWorkingDirectorySettingTest.php @@ -8,18 +8,18 @@ class rtWorkingDirectorySettingTest extends PHPUnit_Framework_TestCase public function testSet() { $configuration = rtRuntestsConfiguration::getInstance(array('run-tests.php', '-p', 'a-php-exe', 'test.phpt')); - $dirsetting = new rtWorkingDirectorySetting($configuration); + $setting = new rtWorkingDirectorySetting($configuration); - $this->assertEquals(getcwd(), $dirsetting->get()); + $this->assertEquals(getcwd(), $setting->get()); } public function testSetFromEnv() { $configuration = rtRuntestsConfiguration::getInstance(array('run-tests.php', '-p', 'a-php-exe', 'test.phpt')); $configuration->setEnvironmentVariable('TEST_PHP_SRCDIR', 'the-source-dir'); - $dirsetting = new rtWorkingDirectorySetting($configuration); + $setting = new rtWorkingDirectorySetting($configuration); - $this->assertEquals('the-source-dir', $dirsetting->get()); + $this->assertEquals('the-source-dir', $setting->get()); } } ?>