Commit:    34d4af0b381063823f25e19a73817540e3292daa
Author:    zoe slattery <z...@php.net>         Wed, 23 May 2012 12:01:09 +0100
Parents:   8ccb00b2bca6a04af566e45f386bd46edaa35962
Branches:  master

Link:       
http://git.php.net/?p=phpruntests.git;a=commitdiff;h=34d4af0b381063823f25e19a73817540e3292daa

Log:
More steps towards implementation of REDIRECT

Changed paths:
  M  src/rtClassMap.php
  M  src/taskScheduler/rtTaskScheduler.php
  M  src/testrun/rtPhpTestRun.php

diff --git a/src/rtClassMap.php b/src/rtClassMap.php
index 79eb583..ad56c93 100644
--- a/src/rtClassMap.php
+++ b/src/rtClassMap.php
@@ -99,6 +99,7 @@ $rtClassMap = array(
     'rtInformationSection'                     => 
'testcase/sections/rtInformationSection.php',
     'rtOutputSection'                          => 
'testcase/sections/rtOutputSection.php',
     'rtSection'                                => 
'testcase/sections/rtSection.php',
+    'rtGroupConfiguration'                     => 
'testgroup/rtGroupConfiguration.php',
     'rtPhpTestGroup'                           => 
'testgroup/rtPhpTestGroup.php',
     'rtPhpTestRun'                             => 'testrun/rtPhpTestRun.php',
 );
diff --git a/src/taskScheduler/rtTaskScheduler.php 
b/src/taskScheduler/rtTaskScheduler.php
index 99bcc96..b252882 100644
--- a/src/taskScheduler/rtTaskScheduler.php
+++ b/src/taskScheduler/rtTaskScheduler.php
@@ -133,7 +133,11 @@ class rtTaskScheduler
                        $results = $task->getResult();
                        rtTestOutputWriter::flushResult($results, 
$this->reportStatus);
                        $this->resultList[] = $results;
-                       $this->redirectedTestCases[] = 
$task->getRedirectedTestCases();
+                       if($task->getRedirectedTestCases() != null) {
+                               foreach($task->getRedirectedTestCases() as 
$testCase) {
+                                       $this->redirectedTestCases[] = 
$testCase;
+                               }
+                       }
                }
 
                return;
diff --git a/src/testrun/rtPhpTestRun.php b/src/testrun/rtPhpTestRun.php
index f780df5..2e86e19 100644
--- a/src/testrun/rtPhpTestRun.php
+++ b/src/testrun/rtPhpTestRun.php
@@ -15,173 +15,199 @@
  */
 class rtPhpTestRun
 {
-    protected $commandLineArguments;
-
-    public function __construct($argv)
-    {
-        $this->commandLineArguments = $argv;
-    }
-
-    public function run()
-    {
-        //Set SSH variables
-
-       // check the operation-system (win/unix)
-       $os = (substr(PHP_OS, 0, 3) == "WIN") ? 'Windows' : 'Unix';
-       
-        //Configure the test environment
-        $runConfiguration = 
rtRuntestsConfiguration::getInstance($this->commandLineArguments, $os);
-        $runConfiguration->getUserEnvironment();
-        $runConfiguration->configure();
-
-        
-        //Check help message
-        if($runConfiguration->hasCommandLineOption('help') || 
$runConfiguration->hasCommandLineOption('h')) {
-            echo rtText::get('help');
-            exit;
-        }
-
-        //Check the preconditions
-        $preConditionList = rtPreConditionList::getInstance($os);
-        $preConditionList->adaptList();
-
-        // $preConditionList->check($this->commandLine, 
$this->environmentVariables);
-        $preConditionList->check($runConfiguration);
-        
-        //Write PHP executable name to the array of env variables. Some 
-        //test cases expect to be able to use it.
-        $php = $runConfiguration->getSetting('PhpExecutable');
-        $runConfiguration->setEnvironmentVariable('TEST_PHP_EXECUTABLE', $php);
-        
-
-        if ($runConfiguration->getSetting('TestDirectories') != null) {
-
-               // make a list of subdirectories which contain tests, includes 
the top level directory
-               $subDirectories = array();
-            foreach ($runConfiguration->getSetting('TestDirectories') as 
$testDirectory) {
-               $subDirectories = array_merge($subDirectories, 
rtUtil::parseDir($testDirectory));
-            }
-           
-            // check for the cmd-line-option 'z' which defines 
parellel-execution
-            $processCount = 0;
-            if ($runConfiguration->hasCommandLineOption('z')) {
-               
-               $processCount = $runConfiguration->getCommandLineOption('z');
-               
-               if (!is_numeric($processCount) || $processCount < 0) {
-                       $processCount = 2;
-               }
-            }
-            
-
-            // check for the cmd-line-option 'v' which defines the 
report-status
-            $reportStatus = 0;
-            if ($runConfiguration->hasCommandLineOption('v')) {
-                               $reportStatus = 1;
-            } else if ($runConfiguration->hasCommandLineOption('vv')) {
-                               $reportStatus = 2;
-            } else if ($runConfiguration->hasCommandLineOption('vvv')) {
-                               $reportStatus = 3;
-            }
-               
-            // create the task-list
-            $taskList = array();
-            foreach ($subDirectories as $subDirectory) {
-               $taskList[] = new rtTaskTestGroup($runConfiguration, 
$subDirectory);
-            }
-                
-            // run the task-scheduler  
-            $scheduler = rtTaskScheduler::getInstance();
-            $scheduler->setTaskList($taskList);
-            $scheduler->setProcessCount($processCount);
-            $scheduler->setReportStatus($reportStatus);
-                       $scheduler->run();
+       protected $commandLineArguments;
+       protected $runConfiguration;
+       protected $redirectedTestCases;
+
+       public function __construct($argv)
+       {
+               $this->commandLineArguments = $argv;
+       }
+
+       public function run()
+       {
+               //Set SSH variables
+
+               // check the operation-system (win/unix)
+               $os = (substr(PHP_OS, 0, 3) == "WIN") ? 'Windows' : 'Unix';
+                
+               //Configure the test environment
+               $this->runConfiguration = 
rtRuntestsConfiguration::getInstance($this->commandLineArguments, $os);
+               $this->runConfiguration->getUserEnvironment();
+               $this->runConfiguration->configure();
+               
+
+
+               //Check help message
+               if($this->runConfiguration->hasCommandLineOption('help') || 
$this->runConfiguration->hasCommandLineOption('h')) {
+                       echo rtText::get('help');
+                       exit;
+               }
+
+               //Check the preconditions
+               $preConditionList = rtPreConditionList::getInstance($os);
+               $preConditionList->adaptList();
+
+               // $preConditionList->check($this->commandLine, 
$this->environmentVariables);
+               $preConditionList->check($this->runConfiguration);
+
+               //Write PHP executable name to the array of env variables. Some
+               //test cases expect to be able to use it.
+               $php = $this->runConfiguration->getSetting('PhpExecutable');
+               
$this->runConfiguration->setEnvironmentVariable('TEST_PHP_EXECUTABLE', $php);
+
+
+               if ($this->runConfiguration->getSetting('TestDirectories') != 
null) {
+
+                       
$this->run_group($this->runConfiguration->getSetting('TestDirectories'));
+
+               } else {
+
+                       if ($this->runConfiguration->getSetting('TestFiles') == 
null) {
+                               echo rtText::get('invalidTestFileName');
+                               exit();
+                       }else{
+                               
$this->run_tests($this->runConfiguration->getSetting('TestFiles'));
+                       }
+               }
+
+           if($this->redirectedTestCases != null) {
+            //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 
+            // configuration' which we don't have at the moment - so maybe we 
need one?
+            // re-implementing a differnt way would be nice. Just reading the 
config and not eval()ing it
+            //which seems unnecessary.
+            //
+            // for now, rtRedirectedSecion is part of 'config', not part of 
'executable';
+           }
+
+       }
+
+       public function run_group($testDirectories) {
+               // make a list of subdirectories which contain tests, includes 
the top level directory
+                
+               $subDirectories = array();
+               foreach ($testDirectories as $testDirectory) {
+                       $subDirectories = array_merge($subDirectories, 
rtUtil::parseDir($testDirectory));
+               }
+                
+               // check for the cmd-line-option 'z' which defines 
parellel-execution
+               $processCount = 0;
+               if ($this->runConfiguration->hasCommandLineOption('z')) {
+                        
+                       $processCount = 
$this->runConfiguration->getCommandLineOption('z');
+                        
+                       if (!is_numeric($processCount) || $processCount < 0) {
+                               $processCount = 2;
+                       }
+               }
+
+
+               // check for the cmd-line-option 'v' which defines the 
report-status
+               $reportStatus = 0;
+               if ($this->runConfiguration->hasCommandLineOption('v')) {
+                       $reportStatus = 1;
+               } else if ($this->runConfiguration->hasCommandLineOption('vv')) 
{
+                       $reportStatus = 2;
+               } else if 
($this->runConfiguration->hasCommandLineOption('vvv')) {
+                       $reportStatus = 3;
+               }
+                
+               // create the task-list
+               $taskList = array();
+               foreach ($subDirectories as $subDirectory) {
+                       $taskList[] = new 
rtTaskTestGroup($this->runConfiguration, $subDirectory);
+               }
+
+               // run the task-scheduler
+               $scheduler = rtTaskScheduler::getInstance();
+               $scheduler->setTaskList($taskList);
+               $scheduler->setProcessCount($processCount);
+               $scheduler->setReportStatus($reportStatus);
+               $scheduler->run();
                        
-                       $resultList = $scheduler->getResultList();
+               $resultList = $scheduler->getResultList();
                        
-                       //Check to see if there are any redirected tests.
+               //Check to see if there are any redirected tests.
                        
-                       $redirects = $scheduler->getRedirectedTestCases();
-               
-                       if($redirects != null) {
-                               for($i=0; $i<sizeof($subDirectories); $i++) {
-                                       foreach($redirects[$i] as 
$redirectedTestCase) {
-                                               echo "\nTest not executed, 
requires redirect. : ".$redirectedTestCase->getName();
-                                       }
-                               }
-                       }
+               $this->redirectedTestCases = 
$scheduler->getRedirectedTestCases();
+                       
+               // create output
+               $type = null;
+               if ($this->runConfiguration->hasCommandLineOption('o')) {
+                       $type = 
$this->runConfiguration->getCommandLineOption('o');
+               }
                        
-                       // create output
-                       $type = null;
-               if ($runConfiguration->hasCommandLineOption('o')) {
-               $type = $runConfiguration->getCommandLineOption('o');
-               }
+               $outputWriter = rtTestOutputWriter::getInstance($type);
+               $outputWriter->setResultList($resultList);
+               $outputWriter->printOverview(sizeof($taskList), 
$scheduler->getProcessCount());
+
+               $filename = null;
+               if ($this->runConfiguration->hasCommandLineOption('s')) {
+                       $filename = 
$this->runConfiguration->getCommandLineOption('s');
+               }
                        
-                       $outputWriter = rtTestOutputWriter::getInstance($type);
-                       $outputWriter->setResultList($resultList);
-                       $outputWriter->printOverview(sizeof($taskList), 
$scheduler->getProcessCount());
+               if ($type || $filename) {
+                       $outputWriter->write($filename);
+               }
+                
+                
+       }
+       public function run_tests($testNames) {
+
+               //This section deals with running single test cases, or lists 
of test cases.
 
-                       $filename = null;
-                       if ($runConfiguration->hasCommandLineOption('s')) {
-                               $filename = 
$runConfiguration->getCommandLineOption('s');
+               foreach ($testNames as $testName) {
+
+                       if (!file_exists($testName)) {
+                               echo rtText::get('invalidTestFileName', 
array($testName));
+                               exit();
                        }
-                       
-               if ($type || $filename) {
-                   $outputWriter->write($filename);    
-            }
-
-        } else {
-
-            if ($runConfiguration->getSetting('TestFiles') == null) {
-                echo rtText::get('invalidTestFileName');
-                exit();
-            } else {
-                foreach ($runConfiguration->getSetting('TestFiles') as 
$testName) {
-
-                    if (!file_exists($testName)) {
-                        echo rtText::get('invalidTestFileName', 
array($testName));
-                        exit();
-                    }
-
-                    //Read the test file
-                    $testFile = new rtPhpTestFile();
-                    $testFile->doRead($testName);
-                    $testFile->normaliseLineEndings();
-                    
-                   // var_dump($testFile->getSectionHeadings());
-                   // var_dump($testFile->getContents());
-                    
-                    $testStatus = new rtTestStatus($testFile->getTestName());
-                   
-
-                    if ($testFile->arePreconditionsMet()) {
-                        $testCase = new rtPhpTest($testFile->getContents(), 
$testFile->getTestName(), $testFile->getSectionHeadings(), $runConfiguration, 
$testStatus);
-                         
-                        //Setup and set the local environment for the test case
-                        $testCase->executeTest($runConfiguration);
-
-                        $results = new rtTestResults($testCase);
-                        $results->processResults($testCase, $runConfiguration);
-
-                    } elseif (in_array("REDIRECTTEST", 
$testFile->getSectionHeadings())) {
-                       
-                               //Redirect handler
-                               
-                               $testCase = new 
rtPhpTest($testFile->getContents(), $testFile->getTestName(), 
$testFile->getSectionHeadings(), $runConfiguration, $testStatus);
-                       
-                               $testStatus->setTrue('redirected');
-                        $testStatus->setMessage('redirected', 
$testFile->getExitMessage());
-                        $results = new rtTestResults(null, $testStatus);
-                    } else {
-                        $testStatus->setTrue('bork');
-                        $testStatus->setMessage('bork', 
$testFile->getExitMessage());
-                        $results = new rtTestResults(null, $testStatus);
-                    }
-
-                    rtTestOutputWriter::flushResult(array($results), 3);
-                }
-            }
-        }
-    }
+
+                       //Read the test file
+                       $testFile = new rtPhpTestFile();
+                       $testFile->doRead($testName);
+                       $testFile->normaliseLineEndings();
+
+                       // var_dump($testFile->getSectionHeadings());
+                       // var_dump($testFile->getContents());
+
+                       $testStatus = new 
rtTestStatus($testFile->getTestName());
+                        
+
+                       if ($testFile->arePreconditionsMet()) {
+                               $testCase = new 
rtPhpTest($testFile->getContents(), $testFile->getTestName(), 
$testFile->getSectionHeadings(), $this->runConfiguration, $testStatus);
+                                
+                               //Setup and set the local environment for the 
test case
+                               $testCase->executeTest($this->runConfiguration);
+
+                               $results = new rtTestResults($testCase);
+                               $results->processResults($testCase, 
$this->runConfiguration);
+
+                       } elseif (in_array("REDIRECTTEST", 
$testFile->getSectionHeadings())) {
+                                
+                               //Redirect handler
+                               //Build a list of redirected test cases
+                                
+                               $this->redirectedTestCases[] = new 
rtPhpTest($testFile->getContents(), $testFile->getTestName(), 
$testFile->getSectionHeadings(), $this->runConfiguration, $testStatus);
+                                
+                               $testStatus->setTrue('redirected');
+                               $testStatus->setMessage('redirected', 
$testFile->getExitMessage());
+                               $results = new rtTestResults(null, $testStatus);
+                       } else {
+                               $testStatus->setTrue('bork');
+                               $testStatus->setMessage('bork', 
$testFile->getExitMessage());
+                               $results = new rtTestResults(null, $testStatus);
+                       }
+
+                       rtTestOutputWriter::flushResult(array($results), 3);
+               }
+                                
+       }
 }
 ?>
-- 
PHP Quality Assurance Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to