<?php
abstract class gtTestCase {
protected $subject;
protected $testCase;
protected $optionalSections;
public function toString() {
$testCaseString = "";
foreach($this->testCase as $line) {
$testCaseString .= $line."\n";
}
return $testCaseString;
}
public function getTestCase() {
return $this->testCase;
}
public function ConstructCommonHeaders() {
$this->testHeader();
if($this->optionalSections->hasSkipif()) {
$this->addSkipif();
}
if($this->optionalSections->hasIni()) {
$this->addIni();
}
$this->fileOpening();
}
public function ConstructCommonClosing() {
$this->fileClosing();
if ($this->optionalSections->hasDone()) {
$this->addDone();
}
if ($this->optionalSections->hasClean()) {
$this->addClean();
}
$this->addExpectf();
}
public function fileOpening() {
$this->testCase[] = "--FILE--";
$this->testCase[] = "<?php";
$this->testCase = gtCodeSnippet::appendBlankLines(2, $this->testCase );
}
public function constructorArgInit() {
$conStatements = $this->subject->getConstructorInitStatements();
foreach($conStatements as $statement) {
$this->testCase[] = $statement;
}
}
public function constructorCreateInstance() {
$constructorList = $this->subject->getConstructorArgumentList();
$this->testCase[] = "\$class = new ".$this->subject->getClassName()."( ".$constructorList." );";
$this->testCase = gtCodeSnippet::appendBlankLines(2, $this->testCase );
}
public function argInit() {
$statements = $this->subject->getInitialisationStatements();
foreach($statements as $statement) {
$this->testCase[] = $statement;
}
$this->testCase = gtCodeSnippet::appendBlankLines(2, $this->testCase );
}
public function fileClosing() {
$this->testCase[] = "?>";
}
public function addSkipif() {
$this->testCase[] = "--SKIPIF--";
$this->testCase[] = "<?php";
if($this->optionalSections->hasSkipifKey()) {
$key = $this->optionalSections->getSkipifKey();
if($key == 'win') {
$this->testCase = gtCodeSnippet::append('skipifwin', $this->testCase);
}
if($key == 'notwin' ) {
$this->testCase = gtCodeSnippet::append('skipifnotwin', $this->testCase);
}
if($key == '64b' ) {
$this->testCase = gtCodeSnippet::append('skipif64b', $this->testCase);
}
if($key == 'not64b' ) {
$this->testCase = gtCodeSnippet::append('skipifnot64b', $this->testCase);
}
}
if($this->optionalSections->hasSkipifExt()) {
$ext = $this->optionalSections->getSkipifExt();
$this->testCase[] = "if (!extension_loaded('$ext')) die ('skip $ext extension not available in this build');";
}
$this->testCase[] = "?>";
}
public function addIni() {
$this->testCase[] = "--INI--";
$this->testCase[] = "";
}
public function addClean() {
$this->testCase[] = "--CLEAN--";
$this->testCase[] = "<?php";
$this->testCase[] = "?>";
}
public function addDone() {
$this->testCase[] = "===DONE===";
}
public function addExpectf() {
$this->testCase[] = "--EXPECTF--";
if ($this->optionalSections->hasDone() ){
$this->testCase[] = '===DONE===';
}
}
public function getOpt() {
return $this->optionalSections;
}
}
?>