com phpruntests: committing stable code on the way tio redir impl: src/run-tests.php src/taskScheduler/rtTaskScheduler.php
src/taskScheduler/rtTaskSchedulerFile.php src/taskScheduler/rtTaskTestGroup.php src/testcase/rtPhpTest.php src/testgroup/rtGroupConfiguration.php
src/testgroup/rtPhpTestGroup.php src/testrun/rtPhpTestRun.php tests/rtPhpTestGroupTest.php
| From: | Zoe Slattery | Date: | Tue, 14 Aug 2012 18:44:57 +0000 |
| Subject: | com phpruntests: committing stable code on the way tio redir impl: src/run-tests.php src/taskScheduler/rtTaskScheduler.php src/taskScheduler/rtTaskSchedulerFile.php src/taskScheduler/rtTaskTestGroup.php src/testcase/rtPhpTest.php src/testgroup/rtGroupConfiguration.php src/testgroup/rtPhpTestGroup.php src/testrun/rtPhpTestRun.php tests/rtPhpTestGroupTest.php |
||
| Groups: | php.qa | ||
| Request: | Send a blank email to php-qa+get-66739@lists.php.net to get a copy of this message | ||
Commit: ca7438d6799e51f60e8c56ec93c5a39562f11f71
Author: zoe slattery <zoe@php.net> Tue, 14 Aug 2012 19:44:57 +0100
Parents: d212f75880adaeb7e08e1b3cb1f58f8fd616e248
Branches: master
Link: http://git.php.net/?p=phpruntests.git;a=commitdiff;h=ca7438d6799e51f60e8c56ec93c5a39562f11f71
Log:
committing stable code on the way tio redir impl
Changed paths:
M src/run-tests.php
M src/taskScheduler/rtTaskScheduler.php
M src/taskScheduler/rtTaskSchedulerFile.php
M src/taskScheduler/rtTaskTestGroup.php
M src/testcase/rtPhpTest.php
M src/testgroup/rtGroupConfiguration.php
M src/testgroup/rtPhpTestGroup.php
M src/testrun/rtPhpTestRun.php
M tests/rtPhpTestGroupTest.php
diff --git a/src/run-tests.php b/src/run-tests.php index a71ba30..3d11d00 100644 --- a/src/run-tests.php +++ b/src/run-tests.php @@ -3,6 +3,7 @@ * Main php file for run-tests.php */ + error_reporting(E_ALL); /** diff --git a/src/taskScheduler/rtTaskScheduler.php b/src/taskScheduler/rtTaskScheduler.php index 5b50fd9..56bc3a8 100644 --- a/src/taskScheduler/rtTaskScheduler.php +++ b/src/taskScheduler/rtTaskScheduler.php @@ -131,6 +131,7 @@ class rtTaskScheduler $task = $this->taskList[$i]; $task->run(); $results = $task->getResult(); + rtTestOutputWriter::flushResult($results, $this->reportStatus); $this->resultList[] = $results; } diff --git a/src/taskScheduler/rtTaskSchedulerFile.php b/src/taskScheduler/rtTaskSchedulerFile.php index 7f98828..326c615 100644 --- a/src/taskScheduler/rtTaskSchedulerFile.php +++ b/src/taskScheduler/rtTaskSchedulerFile.php @@ -220,7 +220,8 @@ class rtTaskSchedulerFile extends rtTaskScheduler print "ERROR unserialize - cid $cid\n"; continue; } - + + $task->run(); $e = microtime(true); diff --git a/src/taskScheduler/rtTaskTestGroup.php b/src/taskScheduler/rtTaskTestGroup.php index 6f9c665..f1c225e 100644 --- a/src/taskScheduler/rtTaskTestGroup.php +++ b/src/taskScheduler/rtTaskTestGroup.php @@ -32,7 +32,7 @@ class rtTaskTestGroup extends rtTask implements rtTaskInterface public function run() { $testGroup = new rtPhpTestGroup($this->runConfiguration, $this->subDirectory); - $testGroup->runGroup($this->runConfiguration); + $testGroup->run(); $this->result = $testGroup->getResults(); return true; } diff --git a/src/testcase/rtPhpTest.php b/src/testcase/rtPhpTest.php index ce2141a..4e572e0 100644 --- a/src/testcase/rtPhpTest.php +++ b/src/testcase/rtPhpTest.php @@ -106,7 +106,7 @@ class rtPhpTest $this->testStatus = $this->sections['SKIPIF']->run($this, $runConfiguration); $this->testStatus->setExecutedPhpCommand($this->sections['SKIPIF']->getPhpCommand()); } - + //TODO: D'oh - what is this meant to be? if (!$this->testStatus->getValue('skip') && !$this->testStatus->getValue('skip')) { $this->testStatus = $this->fileSection->run($this, $runConfiguration); $this->testStatus->setExecutedPhpCommand($this->fileSection->getPhpCommand()); diff --git a/src/testgroup/rtGroupConfiguration.php b/src/testgroup/rtGroupConfiguration.php index b3d9bbc..00548e4 100644 --- a/src/testgroup/rtGroupConfiguration.php +++ b/src/testgroup/rtGroupConfiguration.php @@ -1 +1,31 @@ <?php +/** + * rtGroupConfiguration + * + * Defines environment for a group of test. Could be either setting group + * environment variables (as in redirected tests) of setting parameters + * to stop the group being run in parallel + * + * @category Testing + * @package RUNTESTS + * @author Zoe Slattery <zoe@php.net> + * @author Stefan Priebsch <spriebsch@php.net> + * @copyright 2009 The PHP Group + * @license http://www.php.net/license/3_01.txt PHP License 3.01 + * + */ +class rtGroupConfiguration +{ + protected $testDirectory; + + + public function __construct(rtRuntestsConfiguration $runConfiguration, $directory) + { + $this->testDirectory = $directory; + } + + public function parseRedirect(rtPHPTest $redirectedTest) { + var_dump($redirectedTest->getSection('REDIRECTTEST')); + } +} + diff --git a/src/testgroup/rtPhpTestGroup.php b/src/testgroup/rtPhpTestGroup.php index 735d2df..b052284 100644 --- a/src/testgroup/rtPhpTestGroup.php +++ b/src/testgroup/rtPhpTestGroup.php @@ -12,19 +12,21 @@ * @license http://www.php.net/license/3_01.txt PHP License 3.01 * */ -class rtPhpTestGroup +class rtPhpTestGroup extends rtTask implements rtTaskInterface { protected $testDirectory; protected $testCases; - protected $results; + protected $result = null; + protected $runConfiguration; public function __construct(rtRuntestsConfiguration $runConfiguration, $directory) { + $this->runConfiguration = $runConfiguration; $this->testDirectory = $directory; - $this->init($runConfiguration); + $this->init(); } - public function init(rtRuntestsConfiguration $runConfiguration) + public function init() { $this->testFiles = rtUtil::getTestList($this->testDirectory); @@ -47,13 +49,13 @@ class rtPhpTestGroup $testStatus = new rtTestStatus($testFile->getTestName()); if ($testFile->arePreconditionsMet() ) { // Create a new test case - $this->testCases[] = new rtPhpTest($testFile->getContents(), $testFile->getTestName(), $testFile->getSectionHeadings(), $runConfiguration, $testStatus); + $this->testCases[] = new rtPhpTest($testFile->getContents(), $testFile->getTestName(), $testFile->getSectionHeadings(), $this->runConfiguration, $testStatus); } elseif (in_array("REDIRECTTEST",$testFile->getSectionHeadings())){ //Redirect handler, save the test case for processing after the main groups have finished. //Check to make sure that it shouldn't be skipped, if skipped don't save it - $redirectedTest= new rtPhpTest($testFile->getContents(), $testFile->getTestName(), $testFile->getSectionHeadings(), $runConfiguration, $testStatus); + $redirectedTest= new rtPhpTest($testFile->getContents(), $testFile->getTestName(), $testFile->getSectionHeadings(), $this->runConfiguration, $testStatus); if($redirectedTest->hasSection('SKIPIF')) { - $redirectedTest->runSkipif($runConfiguration); + $redirectedTest->runSkipif($this->runConfiguration); if($redirectedTest->getStatus()->getValue('skip')) { $testStatus->setTrue('skip'); $testStatus->setMessage('skip', $testFile->getExitMessage()); @@ -61,47 +63,48 @@ class rtPhpTestGroup $testStatus->setTrue('redirected'); $testStatus->setMessage('redirected', $testFile->getExitMessage()); } - $this->results[] = new rtTestResults($redirectedTest, $testStatus); + $this->result[] = new rtTestResults($redirectedTest, $testStatus); } }else { $testStatus->setTrue('bork'); $testStatus->setMessage('bork', $testFile->getExitMessage()); - $this->results[] = new rtTestResults(null, $testStatus); + $this->result[] = new rtTestResults(null, $testStatus); } } } - public function runGroup(rtRuntestsConfiguration $runConfiguration) + public function run() { + if (count($this->testCases) == 0) { return; } + foreach ($this->testCases as $testCase) { - $testCase->executeTest($runConfiguration); + $testCase->executeTest($this->runConfiguration); $testResult = new rtTestResults($testCase); - $testResult->processResults($testCase, $runConfiguration); - $this->results[] = $testResult; + $testResult->processResults($testCase, $this->runConfiguration); + $this->result[] = $testResult; } } public function writeGroup($outType, $cid=null) { - $testOutputWriter = rtTestOutputWriter::getInstance($this->results, $outType); + $testOutputWriter = rtTestOutputWriter::getInstance($this->result, $outType); $testOutputWriter->write($this->testDirectory, $cid); } - public function getResults() - { - return $this->results; - } - public function getTestCases() { return $this->testCases; } + + public function getResults() { + return $this->result; + } } ?> diff --git a/src/testrun/rtPhpTestRun.php b/src/testrun/rtPhpTestRun.php index b3ed91f..cacac1b 100644 --- a/src/testrun/rtPhpTestRun.php +++ b/src/testrun/rtPhpTestRun.php @@ -56,12 +56,16 @@ class rtPhpTestRun $php = $this->runConfiguration->getSetting('PhpExecutable'); $this->runConfiguration->setEnvironmentVariable('TEST_PHP_EXECUTABLE', $php); - + // Main decision point. Either we start this with a directory (or set of directories, in which case tests are + // run as a group (and in parallel if required) or...... + // if ($this->runConfiguration->getSetting('TestDirectories') != null) { $this->run_group($this->runConfiguration->getSetting('TestDirectories')); } else { + //.. the input is a test file, or list of files and are just run as single tests + // and not in parallel if ($this->runConfiguration->getSetting('TestFiles') == null) { echo rtText::get('invalidTestFileName'); @@ -74,11 +78,13 @@ class rtPhpTestRun if(count($this->redirectedTestCases) > 0) { foreach($this->redirectedTestCases as $testCase){ echo $testCase->getName() . "\n"; + + } + //For each test case - construct a new group //Call run_group() again with an array of groups // - // Need to run the skipif section first (Could this be done earlier?) // The redirect section has PHP code in it but no tags. // It is code the needs to be run as part of run-tests, not as a 'runnable' section - // eek it's eval(). Is there any better way to do this? It's setting a 'group @@ -123,9 +129,12 @@ class rtPhpTestRun // create the task-list $taskList = array(); + + foreach ($subDirectories as $subDirectory) { $taskList[] = new rtTaskTestGroup($this->runConfiguration, $subDirectory); } + // run the task-scheduler $scheduler = rtTaskScheduler::getInstance(); @@ -146,6 +155,7 @@ class rtPhpTestRun } } } + // create output $type = null; @@ -183,10 +193,7 @@ class rtPhpTestRun $testFile = new rtPhpTestFile(); $testFile->doRead($testName); $testFile->normaliseLineEndings(); - - // var_dump($testFile->getSectionHeadings()); - // var_dump($testFile->getContents()); - + $testStatus = new rtTestStatus($testFile->getTestName()); @@ -204,6 +211,7 @@ class rtPhpTestRun //Redirect handler //Build a list of redirected test cases + //TODO: need to run the skipif section here.. $this->redirectedTestCases[] = new rtPhpTest($testFile->getContents(), $testFile->getTestName(), $testFile->getSectionHeadings(), $this->runConfiguration, $testStatus); $testStatus->setTrue('redirected'); diff --git a/tests/rtPhpTestGroupTest.php b/tests/rtPhpTestGroupTest.php index 1a3ff74..5557b74 100644 --- a/tests/rtPhpTestGroupTest.php +++ b/tests/rtPhpTestGroupTest.php @@ -16,11 +16,11 @@ class rtPHpTestGroupTest extends PHPUnit_Framework_TestCase $config->configure(); $phpTestGroup = new rtPhpTestGroup($config, $directory); - + $validTestCaseCount = count($phpTestGroup->getTestCases()); $phptFileCount = count(glob($directory . "/*.phpt")); - $inValidTestCaseCount = count($phpTestGroup->getResults()); + $inValidTestCaseCount = count($phpTestGroup->getResult()); //PhpTestGroup should divide the test cases into valid tests (TestCases), //or invalid ones. An invalid test is either one which 'borks' (that is, the @@ -39,10 +39,11 @@ class rtPHpTestGroupTest extends PHPUnit_Framework_TestCase $config->configure(); $phpTestGroup = new rtPhpTestGroup($config, $directory); + - $inValidTests = $phpTestGroup->getResults(); + $inValidTests = $phpTestGroup->getResult(); foreach($inValidTests as $testResult) { if($testResult->getStatus() == 'redirected') {
diff --git a/src/run-tests.php b/src/run-tests.php index a71ba30..3d11d00 100644 --- a/src/run-tests.php +++ b/src/run-tests.php @@ -3,6 +3,7 @@ * Main php file for run-tests.php */ + error_reporting(E_ALL); /** diff --git a/src/taskScheduler/rtTaskScheduler.php b/src/taskScheduler/rtTaskScheduler.php index 5b50fd9..56bc3a8 100644 --- a/src/taskScheduler/rtTaskScheduler.php +++ b/src/taskScheduler/rtTaskScheduler.php @@ -131,6 +131,7 @@ class rtTaskScheduler $task = $this->taskList[$i]; $task->run(); $results = $task->getResult(); + rtTestOutputWriter::flushResult($results, $this->reportStatus); $this->resultList[] = $results; } diff --git a/src/taskScheduler/rtTaskSchedulerFile.php b/src/taskScheduler/rtTaskSchedulerFile.php index 7f98828..326c615 100644 --- a/src/taskScheduler/rtTaskSchedulerFile.php +++ b/src/taskScheduler/rtTaskSchedulerFile.php @@ -220,7 +220,8 @@ class rtTaskSchedulerFile extends rtTaskScheduler print "ERROR unserialize - cid $cid\n"; continue; } - + + $task->run(); $e = microtime(true); diff --git a/src/taskScheduler/rtTaskTestGroup.php b/src/taskScheduler/rtTaskTestGroup.php index 6f9c665..f1c225e 100644 --- a/src/taskScheduler/rtTaskTestGroup.php +++ b/src/taskScheduler/rtTaskTestGroup.php @@ -32,7 +32,7 @@ class rtTaskTestGroup extends rtTask implements rtTaskInterface public function run() { $testGroup = new rtPhpTestGroup($this->runConfiguration, $this->subDirectory); - $testGroup->runGroup($this->runConfiguration); + $testGroup->run(); $this->result = $testGroup->getResults(); return true; } diff --git a/src/testcase/rtPhpTest.php b/src/testcase/rtPhpTest.php index ce2141a..4e572e0 100644 --- a/src/testcase/rtPhpTest.php +++ b/src/testcase/rtPhpTest.php @@ -106,7 +106,7 @@ class rtPhpTest $this->testStatus = $this->sections['SKIPIF']->run($this, $runConfiguration); $this->testStatus->setExecutedPhpCommand($this->sections['SKIPIF']->getPhpCommand()); } - + //TODO: D'oh - what is this meant to be? if (!$this->testStatus->getValue('skip') && !$this->testStatus->getValue('skip')) { $this->testStatus = $this->fileSection->run($this, $runConfiguration); $this->testStatus->setExecutedPhpCommand($this->fileSection->getPhpCommand()); diff --git a/src/testgroup/rtGroupConfiguration.php b/src/testgroup/rtGroupConfiguration.php index b3d9bbc..00548e4 100644 --- a/src/testgroup/rtGroupConfiguration.php +++ b/src/testgroup/rtGroupConfiguration.php @@ -1 +1,31 @@ <?php +/** + * rtGroupConfiguration + * + * Defines environment for a group of test. Could be either setting group + * environment variables (as in redirected tests) of setting parameters + * to stop the group being run in parallel + * + * @category Testing + * @package RUNTESTS + * @author Zoe Slattery <zoe@php.net> + * @author Stefan Priebsch <spriebsch@php.net> + * @copyright 2009 The PHP Group + * @license http://www.php.net/license/3_01.txt PHP License 3.01 + * + */ +class rtGroupConfiguration +{ + protected $testDirectory; + + + public function __construct(rtRuntestsConfiguration $runConfiguration, $directory) + { + $this->testDirectory = $directory; + } + + public function parseRedirect(rtPHPTest $redirectedTest) { + var_dump($redirectedTest->getSection('REDIRECTTEST')); + } +} + diff --git a/src/testgroup/rtPhpTestGroup.php b/src/testgroup/rtPhpTestGroup.php index 735d2df..b052284 100644 --- a/src/testgroup/rtPhpTestGroup.php +++ b/src/testgroup/rtPhpTestGroup.php @@ -12,19 +12,21 @@ * @license http://www.php.net/license/3_01.txt PHP License 3.01 * */ -class rtPhpTestGroup +class rtPhpTestGroup extends rtTask implements rtTaskInterface { protected $testDirectory; protected $testCases; - protected $results; + protected $result = null; + protected $runConfiguration; public function __construct(rtRuntestsConfiguration $runConfiguration, $directory) { + $this->runConfiguration = $runConfiguration; $this->testDirectory = $directory; - $this->init($runConfiguration); + $this->init(); } - public function init(rtRuntestsConfiguration $runConfiguration) + public function init() { $this->testFiles = rtUtil::getTestList($this->testDirectory); @@ -47,13 +49,13 @@ class rtPhpTestGroup $testStatus = new rtTestStatus($testFile->getTestName()); if ($testFile->arePreconditionsMet() ) { // Create a new test case - $this->testCases[] = new rtPhpTest($testFile->getContents(), $testFile->getTestName(), $testFile->getSectionHeadings(), $runConfiguration, $testStatus); + $this->testCases[] = new rtPhpTest($testFile->getContents(), $testFile->getTestName(), $testFile->getSectionHeadings(), $this->runConfiguration, $testStatus); } elseif (in_array("REDIRECTTEST",$testFile->getSectionHeadings())){ //Redirect handler, save the test case for processing after the main groups have finished. //Check to make sure that it shouldn't be skipped, if skipped don't save it - $redirectedTest= new rtPhpTest($testFile->getContents(), $testFile->getTestName(), $testFile->getSectionHeadings(), $runConfiguration, $testStatus); + $redirectedTest= new rtPhpTest($testFile->getContents(), $testFile->getTestName(), $testFile->getSectionHeadings(), $this->runConfiguration, $testStatus); if($redirectedTest->hasSection('SKIPIF')) { - $redirectedTest->runSkipif($runConfiguration); + $redirectedTest->runSkipif($this->runConfiguration); if($redirectedTest->getStatus()->getValue('skip')) { $testStatus->setTrue('skip'); $testStatus->setMessage('skip', $testFile->getExitMessage()); @@ -61,47 +63,48 @@ class rtPhpTestGroup $testStatus->setTrue('redirected'); $testStatus->setMessage('redirected', $testFile->getExitMessage()); } - $this->results[] = new rtTestResults($redirectedTest, $testStatus); + $this->result[] = new rtTestResults($redirectedTest, $testStatus); } }else { $testStatus->setTrue('bork'); $testStatus->setMessage('bork', $testFile->getExitMessage()); - $this->results[] = new rtTestResults(null, $testStatus); + $this->result[] = new rtTestResults(null, $testStatus); } } } - public function runGroup(rtRuntestsConfiguration $runConfiguration) + public function run() { + if (count($this->testCases) == 0) { return; } + foreach ($this->testCases as $testCase) { - $testCase->executeTest($runConfiguration); + $testCase->executeTest($this->runConfiguration); $testResult = new rtTestResults($testCase); - $testResult->processResults($testCase, $runConfiguration); - $this->results[] = $testResult; + $testResult->processResults($testCase, $this->runConfiguration); + $this->result[] = $testResult; } } public function writeGroup($outType, $cid=null) { - $testOutputWriter = rtTestOutputWriter::getInstance($this->results, $outType); + $testOutputWriter = rtTestOutputWriter::getInstance($this->result, $outType); $testOutputWriter->write($this->testDirectory, $cid); } - public function getResults() - { - return $this->results; - } - public function getTestCases() { return $this->testCases; } + + public function getResults() { + return $this->result; + } } ?> diff --git a/src/testrun/rtPhpTestRun.php b/src/testrun/rtPhpTestRun.php index b3ed91f..cacac1b 100644 --- a/src/testrun/rtPhpTestRun.php +++ b/src/testrun/rtPhpTestRun.php @@ -56,12 +56,16 @@ class rtPhpTestRun $php = $this->runConfiguration->getSetting('PhpExecutable'); $this->runConfiguration->setEnvironmentVariable('TEST_PHP_EXECUTABLE', $php); - + // Main decision point. Either we start this with a directory (or set of directories, in which case tests are + // run as a group (and in parallel if required) or...... + // if ($this->runConfiguration->getSetting('TestDirectories') != null) { $this->run_group($this->runConfiguration->getSetting('TestDirectories')); } else { + //.. the input is a test file, or list of files and are just run as single tests + // and not in parallel if ($this->runConfiguration->getSetting('TestFiles') == null) { echo rtText::get('invalidTestFileName'); @@ -74,11 +78,13 @@ class rtPhpTestRun if(count($this->redirectedTestCases) > 0) { foreach($this->redirectedTestCases as $testCase){ echo $testCase->getName() . "\n"; + + } + //For each test case - construct a new group //Call run_group() again with an array of groups // - // Need to run the skipif section first (Could this be done earlier?) // The redirect section has PHP code in it but no tags. // It is code the needs to be run as part of run-tests, not as a 'runnable' section - // eek it's eval(). Is there any better way to do this? It's setting a 'group @@ -123,9 +129,12 @@ class rtPhpTestRun // create the task-list $taskList = array(); + + foreach ($subDirectories as $subDirectory) { $taskList[] = new rtTaskTestGroup($this->runConfiguration, $subDirectory); } + // run the task-scheduler $scheduler = rtTaskScheduler::getInstance(); @@ -146,6 +155,7 @@ class rtPhpTestRun } } } + // create output $type = null; @@ -183,10 +193,7 @@ class rtPhpTestRun $testFile = new rtPhpTestFile(); $testFile->doRead($testName); $testFile->normaliseLineEndings(); - - // var_dump($testFile->getSectionHeadings()); - // var_dump($testFile->getContents()); - + $testStatus = new rtTestStatus($testFile->getTestName()); @@ -204,6 +211,7 @@ class rtPhpTestRun //Redirect handler //Build a list of redirected test cases + //TODO: need to run the skipif section here.. $this->redirectedTestCases[] = new rtPhpTest($testFile->getContents(), $testFile->getTestName(), $testFile->getSectionHeadings(), $this->runConfiguration, $testStatus); $testStatus->setTrue('redirected'); diff --git a/tests/rtPhpTestGroupTest.php b/tests/rtPhpTestGroupTest.php index 1a3ff74..5557b74 100644 --- a/tests/rtPhpTestGroupTest.php +++ b/tests/rtPhpTestGroupTest.php @@ -16,11 +16,11 @@ class rtPHpTestGroupTest extends PHPUnit_Framework_TestCase $config->configure(); $phpTestGroup = new rtPhpTestGroup($config, $directory); - + $validTestCaseCount = count($phpTestGroup->getTestCases()); $phptFileCount = count(glob($directory . "/*.phpt")); - $inValidTestCaseCount = count($phpTestGroup->getResults()); + $inValidTestCaseCount = count($phpTestGroup->getResult()); //PhpTestGroup should divide the test cases into valid tests (TestCases), //or invalid ones. An invalid test is either one which 'borks' (that is, the @@ -39,10 +39,11 @@ class rtPHpTestGroupTest extends PHPUnit_Framework_TestCase $config->configure(); $phpTestGroup = new rtPhpTestGroup($config, $directory); + - $inValidTests = $phpTestGroup->getResults(); + $inValidTests = $phpTestGroup->getResult(); foreach($inValidTests as $testResult) { if($testResult->getStatus() == 'redirected') {