Back to index

php5  5.3.10
generate-phpt.php
Go to the documentation of this file.
00001 <?php
00006 require_once dirname(__FILE__) . '/gtAutoload.php';
00007 
00008 //Version check. Will not run on less than PHP53;
00009 
00010 list($major, $minor, $bug) = explode(".", phpversion(), 3);
00011  if($major == 5) {
00012        if($minor < 3) { die("Sorry, you need PHP version 5.3 or greater to run this.\n"); }
00013    }
00014    if ($major < 5) { die ("Seriously, you need to upgrade you PHP level\n"); }
00015 
00016 
00017 $options = new gtCommandLineOptions();
00018 $optionalSections = new gtOptionalSections();
00019 
00020 try{
00021   $options->parse($argv);
00022 } catch (exception $e) {
00023   echo $e->getMessage()."\n";
00024   die();
00025 }
00026 
00027 if($options->hasOption('h')) {
00028   die(gtText::get('help'));
00029 }
00030 
00031 try {
00032   $preConditions = new gtPreConditionList();
00033   $preConditions->check($options);
00034 } catch (exception $e) {
00035   echo $e->getMessage()."\n";
00036   die();
00037 }
00038 
00039 if($options->hasOption('s')) {
00040   $optionalSections->setOptions($options);
00041 }
00042   
00043 
00044 
00045 if($options->hasOption('c')) {
00046   $name = $options->getOption('c')."_".$options->getOption('m');
00047   $method = new gtMethod($options->getOption('c'), $options->getOption('m'));
00048   
00049   $method->setArgumentNames();
00050   $method->setArgumentLists();
00051   $method->setInitialisationStatements();
00052   
00053   $method->setConstructorArgumentNames();
00054   $method->setConstructorInitStatements();
00055   $method->setConstructorArgumentList();
00056 }
00057 
00058 if($options->hasOption('f')) {
00059   $name = $options->getOption('f');
00060   $function = new gtFunction($name);
00061   $function->setArgumentNames();
00062   $function->setArgumentLists();
00063   $function->setInitialisationStatements();
00064 }
00065 
00066 
00067 if($options->hasOption('b')) {
00068   if($options->hasOption('c')) {
00069     $testCase = gtBasicTestCase::getInstance($optionalSections, 'method');
00070     $testCase->setMethod($method);
00071   } else {
00072     $testCase = gtBasicTestCase::getInstance($optionalSections);
00073     $testCase->setFunction($function);
00074   }
00075 
00076   $testCase->constructTestCase();
00077   gtTestCaseWriter::write($name, $testCase->toString(), 'b');
00078 }
00079 
00080 if($options->hasOption('e')) {
00081   if($options->hasOption('c')) {
00082     $testCase = gtErrorTestCase::getInstance($optionalSections, 'method');
00083     $testCase->setMethod($method);
00084   } else {
00085     $testCase = gtErrorTestCase::getInstance($optionalSections);
00086     $testCase->setFunction($function);
00087   }
00088 
00089   $testCase->constructTestCase();
00090   gtTestCaseWriter::write($name, $testCase->toString(), 'e');
00091 }
00092 
00093 
00094 
00095 if($options->hasOption('v')) {
00096   if($options->hasOption('c')) {
00097     $testCaseContainer = gtVariationContainer::getInstance($optionalSections, 'method');
00098     $testCaseContainer->setMethod($method);
00099   } else {
00100     $testCaseContainer = gtVariationContainer::getInstance ($optionalSections);
00101     $testCaseContainer->setFunction($function);
00102   }
00103 
00104   $testCaseContainer->constructAll();
00105 
00106   $tests = $testCaseContainer->getVariationTests();
00107 
00108   $count = 1;
00109   foreach($tests as $test) {
00110     gtTestCaseWriter::write($name, $test, 'v', $count);
00111     $count++;
00112   }
00113 
00114 }
00115 ?>