com phpruntests: phpruntests: added a precondition-check to ensure using php 5.3 or higher and an appropriate testcase.:
src/configuration/preconditions/rtIfParallelHasPcntl.php src/configuration/preconditions/rtIsExecutableSet.php
src/configuration/preconditions/rtIsPcreLoaded.php src/configuration/preconditions/rtIsPhpVersionCorrect.php
src/configuration/preconditions/rtIsProcOpenAvailable.php src/configuration/preconditions/rtIsSafeModeDisable

From: Date: Wed, 06 May 2009 20:45:42 +0000
Subject: com phpruntests: phpruntests: added a precondition-check to ensure using php 5.3 or higher and an appropriate testcase.:
src/configuration/preconditions/rtIfParallelHasPcntl.php src/configuration/preconditions/rtIsExecutableSet.php
src/configuration/preconditions/rtIsPcreLoaded.php src/configuration/preconditions/rtIsPhpVersionCorrect.php
src/configuration/preconditions/rtIsProcOpenAvailable.php src/configuration/preconditions/rtIsSafeModeDisable
Groups: php.qa 
Request: Send a blank email to php-qa+get-66489@lists.php.net to get a copy of this message
Commit: db086690e2a776fd9c15803eb9cda1fb2bd12b45 Author: Georg Gradwohl <g2@php.net> Wed, 6 May 2009 20:45:42 +0000 Parents: 01bac8c1021ebdd9c551f4cb0a306ad32c2cc7d2 Branches: master Link: http://git.php.net/?p=phpruntests.git;a=commitdiff;h=db086690e2a776fd9c15803eb9cda1fb2bd12b45 Log: phpruntests: added a precondition-check to ensure using php 5.3 or higher and an appropriate testcase. Changed paths: M src/configuration/preconditions/rtIfParallelHasPcntl.php M src/configuration/preconditions/rtIsExecutableSet.php M src/configuration/preconditions/rtIsPcreLoaded.php A src/configuration/preconditions/rtIsPhpVersionCorrect.php M src/configuration/preconditions/rtIsProcOpenAvailable.php M src/configuration/preconditions/rtIsSafeModeDisabled.php M src/configuration/preconditions/rtIsTestFileSpecified.php M src/configuration/rtPreConditionList.php M src/configuration/rtRuntestsConfiguration.php M src/rtClassMap.php M src/testClassMap.php A src/texts/invalidPhpVersion.txt A tests/configuration/preconditions/rtVersionCheckTest.php

diff --git a/src/configuration/preconditions/rtIfParallelHasPcntl.php b/src/configuration/preconditions/rtIfParallelHasPcntl.php index b5a6887..245bbd7 100644 --- a/src/configuration/preconditions/rtIfParallelHasPcntl.php +++ b/src/configuration/preconditions/rtIfParallelHasPcntl.php @@ -19,8 +19,21 @@ class rtIfParallelHasPcntl extends rtPreCondition /** * Check that the PCNTL is loaded if parallel run is required * + * @param rtRuntestsConfiguration $config * @return boolean + * @access public */ + public function check(rtRuntestsConfiguration $config) + { + if ($config->hasCommandLineOption('z') || $config->hasEnvironmentVariable('TESTS_PHP_PARALLEL')) { + return extension_loaded('pcntl'); + } + + return true; + } + + + /* public function check(rtCommandLineOptions $commandLine = null, rtEnvironmentVariables $environmentVariables = null) { if ($commandLine->hasOption('z') || $environmentVariables->hasVariable('TESTS_PHP_PARALLEL')) { @@ -29,5 +42,6 @@ class rtIfParallelHasPcntl extends rtPreCondition return true; } + */ } ?> diff --git a/src/configuration/preconditions/rtIsExecutableSet.php b/src/configuration/preconditions/rtIsExecutableSet.php index 836ae94..ab1deef 100644 --- a/src/configuration/preconditions/rtIsExecutableSet.php +++ b/src/configuration/preconditions/rtIsExecutableSet.php @@ -15,14 +15,30 @@ class rtIsExecutableSet extends rtPreCondition { return rtText::get('missingPHPExecutable'); } - + + /** * Check that the PHP executable is a valid executable * - * @param rtCommandLine $commandLine - * @param rtEnvironmentVariables $environment + * @param rtRuntestsConfiguration $config * @return boolean + * @access public */ + public function check(rtRuntestsConfiguration $config) + { + if ($config->hasCommandLineOption('p')) { + return true; + } + + if ($config->hasEnvironmentVariable('TEST_PHP_EXECUTABLE')) { + return true; + } + + return false; + } + + + /* public function check(rtCommandLineOptions $commandLine = null, rtEnvironmentVariables $environmentVariables = null) { if ($commandLine->hasOption('p')) { @@ -34,6 +50,7 @@ class rtIsExecutableSet extends rtPreCondition } return false; - } + } + */ } ?> diff --git a/src/configuration/preconditions/rtIsPcreLoaded.php b/src/configuration/preconditions/rtIsPcreLoaded.php index 78acc7f..c9dac85 100644 --- a/src/configuration/preconditions/rtIsPcreLoaded.php +++ b/src/configuration/preconditions/rtIsPcreLoaded.php @@ -17,9 +17,18 @@ class rtIsPcreLoaded extends rtPreCondition /** * Check that the PCRE is loaded - * + * + * @param rtRuntestsConfiguration $config * @return boolean + * @access public */ + public function check(rtRuntestsConfiguration $config) + { + return extension_loaded('pcre'); + } + + + /* public function check(rtCommandLineOptions $commandLine = null, rtEnvironmentVariables $environmentVariables = null) { if (extension_loaded('pcre')) { @@ -28,5 +37,6 @@ class rtIsPcreLoaded extends rtPreCondition return false; } + */ } ?> diff --git a/src/configuration/preconditions/rtIsPhpVersionCorrect.php b/src/configuration/preconditions/rtIsPhpVersionCorrect.php new file mode 100644 index 0000000..2fae325 --- /dev/null +++ b/src/configuration/preconditions/rtIsPhpVersionCorrect.php @@ -0,0 +1,113 @@ +<?php +/** + * rtIsPhpVersionCorrect + * + * class for checking the required minimum-version (5.3) + * of the the running and executing php-executable + * + * @category Configuration + * @package RUNTESTS + * @author Zoe Slattery <zoe@php.net> + * @author Stefan Priebsch <spriebsch@php.net> + * @author Georg Gradwohl <g2@php.net> + * @copyright 2009 The PHP Group + * @license http://www.php.net/license/3_01.txt PHP License 3.01 + * @link http://qa.php.net/ + */ +class rtIsPhpVersionCorrect extends rtPreCondition +{ + /** + * the required major-version of the php-executeable + * + * @var int + */ + private $requiredMajorVersion = 5; + + /** + * the required minor-version of the php-executeable + * + * @var int + */ + private $requiredMinorVersion = 3; + + /** + * Return the message associated with an invalid php-version + * + * @return text + * @access public + */ + public function getMessage() + { + return rtText::get('invalidPhpVersion'); + } + + /** + * check that used php-version matches the precondition + * + * @param rtRuntestsConfiguration $config + * + * @return boolean + * @access public + */ + public function check(rtRuntestsConfiguration $config) + { + return ($this->checkRunVersion() && $this->checkExecVersion($config)); + } + + /** + * check that executing php-version matches the precondition + * + * @param rtRuntestsConfiguration $config + * + * @return boolean + * @access private + */ + private function checkExecVersion(rtRuntestsConfiguration $config) + { + $exec = escapeshellcmd($config->getSetting('PhpExecutable').' -v'); + + $pipe = popen($exec, "r"); + $output = fread($pipe, 1024); + pclose($pipe); + + return $this->parseVersionString($output); + } + + /** + * check that running php-version matches the precondition + * + * @return boolean + * @access private + */ + private function checkRunVersion() + { + return $this->parseVersionString('PHP '.phpversion()); + } + + /** + * parses the version-string and checks the required minimun-version + * + * @param string $versionStr output of "php -v" + * + * @return boolean + * @access public + */ + public function parseVersionString($versionStr) + { + $major = substr($versionStr, 4,1); + $minor = substr($versionStr, 6,1); + + if ($major > $this->requiredMajorVersion) { + return true; + + } elseif ($major == $this->requiredMajorVersion) { + + if ($minor >= $this->requiredMinorVersion) { + return true; + } + } + + return false; + } +} +?> diff --git a/src/configuration/preconditions/rtIsProcOpenAvailable.php b/src/configuration/preconditions/rtIsProcOpenAvailable.php index ce3556c..0c055ee 100644 --- a/src/configuration/preconditions/rtIsProcOpenAvailable.php +++ b/src/configuration/preconditions/rtIsProcOpenAvailable.php @@ -18,9 +18,18 @@ class rtIsProcOpenAvailable extends rtPreCondition /** * Check that proc_open() is available - * + * + * @param rtRuntestsConfiguration $config * @return boolean + * @access public */ + public function check(rtRuntestsConfiguration $config) + { + return function_exists('proc_open'); + } + + + /* public function check(rtCommandLineOptions $commandLine = null, rtEnvironmentVariables $environmentVariables = null) { if (function_exists('proc_open')) { @@ -29,5 +38,6 @@ class rtIsProcOpenAvailable extends rtPreCondition return false; } + */ } ?> diff --git a/src/configuration/preconditions/rtIsSafeModeDisabled.php b/src/configuration/preconditions/rtIsSafeModeDisabled.php index d12d6d0..2a9cc8d 100644 --- a/src/configuration/preconditions/rtIsSafeModeDisabled.php +++ b/src/configuration/preconditions/rtIsSafeModeDisabled.php @@ -19,8 +19,21 @@ class rtIsSafeModeDisabled extends rtPreCondition /** * Check to see if safe mode is enabled * + * @param rtRuntestsConfiguration $config * @return boolean + * @access public */ + public function check(rtRuntestsConfiguration $config) + { + if (!ini_get('safe_mode')) { + return true; + } + + return false; + } + + + /* public function check(rtCommandLineOptions $commandLine = null, rtEnvironmentVariables $environmentVariables = null) { if (!ini_get('safe_mode')) { @@ -29,5 +42,6 @@ class rtIsSafeModeDisabled extends rtPreCondition return false; } + */ } ?> diff --git a/src/configuration/preconditions/rtIsTestFileSpecified.php b/src/configuration/preconditions/rtIsTestFileSpecified.php index 4dfd1e8..f7c86d4 100644 --- a/src/configuration/preconditions/rtIsTestFileSpecified.php +++ b/src/configuration/preconditions/rtIsTestFileSpecified.php @@ -18,10 +18,33 @@ class rtIsTestFileSpecified extends rtPreCondition /** * Check that a test file or directory has been given * - * @param rtCommandLine $commandLine - * @param rtEnvironmentVariables $environmentVariables + * @param rtRuntestsConfiguration $config * @return boolean + * @access public */ + public function check(rtRuntestsConfiguration $config) + { + if ($config->hasCommandLineOption('l')) { + return true; + } + + if ($config->hasCommandLineOption('r')) { + return true; + } + + if ($config->getTestFilename() != null) { + return true; + } + + if ($config->hasEnvironmentVariable('TEST_PHP_USER')) { + return true; + } + + return false; + } + + + /* public function check(rtCommandLineOptions $commandLine = null, rtEnvironmentVariables $environmentVariables = null) { if ($commandLine->hasOption('l')) { @@ -41,6 +64,7 @@ class rtIsTestFileSpecified extends rtPreCondition } return false; - } + } + */ } ?> diff --git a/src/configuration/rtPreConditionList.php b/src/configuration/rtPreConditionList.php index 7e9bd7e..440ddfc 100644 --- a/src/configuration/rtPreConditionList.php +++ b/src/configuration/rtPreConditionList.php @@ -13,6 +13,7 @@ abstract class rtPreConditionList 'rtIsProcOpenAvailable', 'rtIsSafeModeDisabled', 'rtIsTestFileSpecified', + 'rtIsPhpVersionCorrect', ); /** @@ -37,11 +38,13 @@ abstract class rtPreConditionList * @param rtEnvironmentVariables $environmentVariables * @return boolean */ - public function check($commandLine, $environmentVariables) + public function check(rtRuntestsConfiguration $config) { foreach ($this->preConditions as $preCon) { $p = new $preCon; - if (!$p->check($commandLine, $environmentVariables)) { + + // if (!$p->check($commandLine, $environmentVariables)) { + if (!$p->check($config)) { die($p->getMessage()); } } diff --git a/src/configuration/rtRuntestsConfiguration.php b/src/configuration/rtRuntestsConfiguration.php index 9aee170..05d68e6 100644 --- a/src/configuration/rtRuntestsConfiguration.php +++ b/src/configuration/rtRuntestsConfiguration.php @@ -64,17 +64,22 @@ abstract class rtRuntestsConfiguration $options = new rtAddToCommandLine(); $options->parseAdditionalOptions($this->commandLine, $this->environmentVariables); - //check configuration preconditions - $preConditionList = rtPreConditionList::getInstance(); - $preConditionList->check($this->commandLine, $this->environmentVariables); - //set configuration foreach ($this->settingNames as $name => $setting) { $this->setters[$name] = new $setting($this); $methodName = 'set' . $name; $this->$methodName(); } - + + //check configuration preconditions + $preConditionList = rtPreConditionList::getInstance(); + + // $preConditionList->check($this->commandLine, $this->environmentVariables); + + $preConditionList->check($this); + + + } /** diff --git a/src/rtClassMap.php b/src/rtClassMap.php index f867978..999b042 100644 --- a/src/rtClassMap.php +++ b/src/rtClassMap.php @@ -10,6 +10,7 @@ 'rtIsProcOpenAvailable' => 'configuration/preconditions/rtIsProcOpenAvailable.php', 'rtIsSafeModeDisabled' => 'configuration/preconditions/rtIsSafeModeDisabled.php', 'rtIsTestFileSpecified' => 'configuration/preconditions/rtIsTestFileSpecified.php', + 'rtIsPhpVersionCorrect' => 'configuration/preconditions/rtIsPhpVersionCorrect.php', 'rtAddToCommandLine' => 'configuration/rtAddToCommandLine.php', 'rtCommandLineOptions' => 'configuration/rtCommandLineOptions.php', 'rtEnvironmentVariables' => 'configuration/rtEnvironmentVariables.php', diff --git a/src/testClassMap.php b/src/testClassMap.php index c689a8d..952f761 100644 --- a/src/testClassMap.php +++ b/src/testClassMap.php @@ -43,6 +43,7 @@ $rtClassMap = array( 'rtHasNoDuplicateSections' => 'testcase/preconditions/rtHasNoDuplicateSections.php', 'rtIsSectionImplemented' => 'testcase/preconditions/rtIsSectionImplemented.php', 'rtIsValidSectionName' => 'testcase/preconditions/rtIsValidSectionName.php', + 'rtVersionCheckTest' => 'configuration/preconditions/rtVersionCheckTest.php'. 'rtPhpRunner' => 'testcase/rtPhpRunner.php', 'rtPhpTest' => 'testcase/rtPhpTest.php', 'rtPhpTestFile' => 'testcase/rtPhpTestFile.php', @@ -73,4 +74,5 @@ $rtClassMap = array( 'rtDirectoryList' => 'testrun/rtDirectoryList.php', 'rtPhpTestRun' => 'testrun/rtPhpTestRun.php', 'rtPhptDirectoryFilterIterator' => 'testrun/rtPhptDirectoryFilterIterator.php', + ); diff --git a/src/texts/invalidPhpVersion.txt b/src/texts/invalidPhpVersion.txt new file mode 100644 index 0000000..87894e5 --- /dev/null +++ b/src/texts/invalidPhpVersion.txt @@ -0,0 +1,3 @@ +This version of run-tests requires PHP 5.3 or higher. +The PHP executable that you have supplied using either the command line option +-p or the environmental variable TEST_PHP_EXECUTABLE does not fulfill this requirement. diff --git a/tests/configuration/preconditions/rtVersionCheckTest.php b/tests/configuration/preconditions/rtVersionCheckTest.php new file mode 100644 index 0000000..f7203e2 --- /dev/null +++ b/tests/configuration/preconditions/rtVersionCheckTest.php @@ -0,0 +1,47 @@ +<?php + +require_once 'PHPUnit/Framework.php'; +require_once dirname(__FILE__) . '../../../../src/rtAutoload.php'; + +class rtVersionCheckTest extends PHPUnit_Framework_TestCase +{ + private $versionCheck = null; + + protected function setUp() + { + $this->versionCheck = new rtIsPhpVersionCorrect(); + } + + protected function tearDown() + { + $this->versionCheck = null; + } + + public function testCorrectVersion() + { + $str = "PHP 5.3.0RC1 (cli) (built: Apr 26 2009 02:49:56) + Copyright (c) 1997-2009 The PHP Group + Zend Engine v2.3.0, Copyright (c) 1998-2009 Zend Technologies"; + + $this->assertTrue($this->versionCheck->parseVersionString($str)); + $this->assertTrue($this->versionCheck->parseVersionString("PHP 6.2.0")); + } + + public function testIncorrectVersion() + { + $str = "PHP 5.2.9 (cli) (built: Apr 26 2009 03:15:54) + Copyright (c) 1997-2009 The PHP Group + Zend Engine v2.2.0, Copyright (c) 1998-2009 Zend Technologies"; + + $this->assertFalse($this->versionCheck->parseVersionString($str)); + $this->assertFalse($this->versionCheck->parseVersionString("PHP 4.4.9")); + } + + public function testInvalidString() + { + $this->assertFalse($this->versionCheck->parseVersionString("5.3.0")); + $this->assertFalse($this->versionCheck->parseVersionString("PHP 5.2 PHP 6.0")); + $this->assertFalse($this->versionCheck->parseVersionString("PHP 6")); + } +} +?>
« previous php.qa (#66489) next »