summaryrefslogtreecommitdiff
path: root/scripts/dev/generate-phpt/src/generate-phpt.php
blob: 4f57a70b54a9d5bce25e76f62863d007b1c71f21 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
/**
 * Main code for test case generation
 */

require_once dirname(__FILE__) . '/gtAutoload.php';

//Version check. Will not run on less than PHP53;

list($major, $minor, $bug) = explode(".", phpversion(), 3);
 if($major == 5) {
       if($minor < 3) { die("Sorry, you need PHP version 5.3 or greater to run this.\n"); }
   }
   if ($major < 5) { die ("Seriously, you need to upgrade you PHP level\n"); }


$options = new gtCommandLineOptions();
$optionalSections = new gtOptionalSections();

try{
  $options->parse($argv);
} catch (exception $e) {
  echo $e->getMessage()."\n";
  die();
}

if($options->hasOption('h')) {
  die(gtText::get('help'));
}

try {
  $preConditions = new gtPreConditionList();
  $preConditions->check($options);
} catch (exception $e) {
  echo $e->getMessage()."\n";
  die();
}

if($options->hasOption('s')) {
  $optionalSections->setOptions($options);
}
  


if($options->hasOption('c')) {
  $name = $options->getOption('c')."_".$options->getOption('m');
  $method = new gtMethod($options->getOption('c'), $options->getOption('m'));
  
  $method->setArgumentNames();
  $method->setArgumentLists();
  $method->setInitialisationStatements();
  
  $method->setConstructorArgumentNames();
  $method->setConstructorInitStatements();
  $method->setConstructorArgumentList();
}

if($options->hasOption('f')) {
  $name = $options->getOption('f');
  $function = new gtFunction($name);
  $function->setArgumentNames();
  $function->setArgumentLists();
  $function->setInitialisationStatements();
}


if($options->hasOption('b')) {
  if($options->hasOption('c')) {
    $testCase = gtBasicTestCase::getInstance($optionalSections, 'method');
    $testCase->setMethod($method);
  } else {
    $testCase = gtBasicTestCase::getInstance($optionalSections);
    $testCase->setFunction($function);
  }

  $testCase->constructTestCase();
  gtTestCaseWriter::write($name, $testCase->toString(), 'b');
}

if($options->hasOption('e')) {
  if($options->hasOption('c')) {
    $testCase = gtErrorTestCase::getInstance($optionalSections, 'method');
    $testCase->setMethod($method);
  } else {
    $testCase = gtErrorTestCase::getInstance($optionalSections);
    $testCase->setFunction($function);
  }

  $testCase->constructTestCase();
  gtTestCaseWriter::write($name, $testCase->toString(), 'e');
}



if($options->hasOption('v')) {
  if($options->hasOption('c')) {
    $testCaseContainer = gtVariationContainer::getInstance($optionalSections, 'method');
    $testCaseContainer->setMethod($method);
  } else {
    $testCaseContainer = gtVariationContainer::getInstance ($optionalSections);
    $testCaseContainer->setFunction($function);
  }

  $testCaseContainer->constructAll();

  $tests = $testCaseContainer->getVariationTests();

  $count = 1;
  foreach($tests as $test) {
    gtTestCaseWriter::write($name, $test, 'v', $count);
    $count++;
  }

}
?>