4
* Class for all test cases
6
abstract class gtTestCase {
10
* The subject of the test, may be either a function (gtFunction) or a method (gtMethod)
12
* @var gtMethod or gtFunction
18
* Arry of strings containing the test case
26
* Object containing teh ooptional sections that may be added to the test case
28
* @var gtOptionalSections
30
protected $optionalSections;
34
* Convert test case from array to string
38
public function toString() {
40
foreach($this->testCase as $line) {
41
$testCaseString .= $line."\n";
43
return $testCaseString;
49
* Returns test case as a array
53
public function getTestCase() {
54
return $this->testCase;
59
* Construct the common headers (title, file section..) of the test case
62
public function ConstructCommonHeaders() {
65
if($this->optionalSections->hasSkipif()) {
69
if($this->optionalSections->hasIni()) {
78
* Construct the common closing statements (clean, done, EXPECTF...)
81
public function ConstructCommonClosing() {
84
if ($this->optionalSections->hasDone()) {
88
if ($this->optionalSections->hasClean()) {
96
* Start the FILE section of the test
99
public function fileOpening() {
100
$this->testCase[] = "--FILE--";
101
$this->testCase[] = "<?php";
102
$this->testCase = gtCodeSnippet::appendBlankLines(2, $this->testCase );
107
* Add contructor argument initialisation to test case
110
public function constructorArgInit() {
111
$conStatements = $this->subject->getConstructorInitStatements();
112
foreach($conStatements as $statement) {
113
$this->testCase[] = $statement;
119
* Create instance of class in the test case
122
public function constructorCreateInstance() {
123
$constructorList = $this->subject->getConstructorArgumentList();
124
$this->testCase[] = "\$class = new ".$this->subject->getClassName()."( ".$constructorList." );";
125
$this->testCase = gtCodeSnippet::appendBlankLines(2, $this->testCase );
130
* Add function or method initilaisation statements to the test case
133
public function argInit() {
134
$statements = $this->subject->getInitialisationStatements();
135
foreach($statements as $statement) {
136
$this->testCase[] = $statement;
138
$this->testCase = gtCodeSnippet::appendBlankLines(2, $this->testCase );
143
* Add FILE section closing tag to teh test case
146
public function fileClosing() {
147
$this->testCase[] = "?>";
152
* Add a skipif section to the test case
155
public function addSkipif() {
156
$this->testCase[] = "--SKIPIF--";
157
$this->testCase[] = "<?php";
158
if($this->optionalSections->hasSkipifKey()) {
159
$key = $this->optionalSections->getSkipifKey();
160
//test standard skipif sections
162
$this->testCase = gtCodeSnippet::append('skipifwin', $this->testCase);
164
if($key == 'notwin' ) {
165
$this->testCase = gtCodeSnippet::append('skipifnotwin', $this->testCase);
169
$this->testCase = gtCodeSnippet::append('skipif64b', $this->testCase);
172
if($key == 'not64b' ) {
173
$this->testCase = gtCodeSnippet::append('skipifnot64b', $this->testCase);
177
if($this->optionalSections->hasSkipifExt()) {
178
$ext = $this->optionalSections->getSkipifExt();
179
$this->testCase[] = "if (!extension_loaded('$ext')) die ('skip $ext extension not available in this build');";
181
$this->testCase[] = "?>";
186
* Add an INI section to the test case
189
public function addIni() {
190
$this->testCase[] = "--INI--";
191
$this->testCase[] = "";
196
* Add a clean section to the test case
199
public function addClean() {
200
$this->testCase[] = "--CLEAN--";
201
$this->testCase[] = "<?php";
202
$this->testCase[] = "?>";
207
* Add a ===DONE=== statement to the test case
210
public function addDone() {
211
$this->testCase[] = "===DONE===";
216
* Add an EXPECTF section
219
public function addExpectf() {
220
$this->testCase[] = "--EXPECTF--";
221
if ($this->optionalSections->hasDone() ){
222
$this->testCase[] = '===DONE===';
226
public function getOpt() {
227
return $this->optionalSections;
b'\\ No newline at end of file'