Back to index

php5  5.3.10
gtTestCase.php
Go to the documentation of this file.
00001 <?php
00002 
00006 abstract class gtTestCase {
00007 
00008 
00014   protected $subject;
00015 
00016 
00022   protected $testCase;
00023 
00024 
00030   protected $optionalSections;
00031 
00032 
00038   public function toString() {
00039     $testCaseString = "";
00040     foreach($this->testCase as $line) {
00041       $testCaseString .= $line."\n";
00042     }
00043     return $testCaseString;
00044   }
00045 
00046 
00047 
00053   public function getTestCase() {
00054     return $this->testCase;
00055   }
00056 
00057 
00062   public function ConstructCommonHeaders() {
00063     $this->testHeader();
00064 
00065     if($this->optionalSections->hasSkipif()) {
00066       $this->addSkipif();
00067     }
00068 
00069     if($this->optionalSections->hasIni()) {
00070       $this->addIni();
00071     }
00072 
00073     $this->fileOpening();
00074   }
00075 
00076 
00081   public function ConstructCommonClosing() {
00082     $this->fileClosing();
00083      
00084     if ($this->optionalSections->hasDone()) {
00085       $this->addDone();
00086     }
00087      
00088     if ($this->optionalSections->hasClean()) {
00089       $this->addClean();
00090     }
00091 
00092     $this->addExpectf();
00093   }
00094 
00099   public function fileOpening() {
00100     $this->testCase[] = "--FILE--";
00101     $this->testCase[] = "<?php";
00102     $this->testCase = gtCodeSnippet::appendBlankLines(2, $this->testCase );
00103   }
00104 
00105 
00110   public function constructorArgInit() {
00111     $conStatements = $this->subject->getConstructorInitStatements();
00112     foreach($conStatements as $statement) {
00113       $this->testCase[] = $statement;
00114     }
00115   }
00116 
00117 
00122   public function constructorCreateInstance() {
00123     $constructorList = $this->subject->getConstructorArgumentList();
00124     $this->testCase[] = "\$class = new ".$this->subject->getClassName()."( ".$constructorList." );";
00125     $this->testCase = gtCodeSnippet::appendBlankLines(2, $this->testCase );
00126   }
00127 
00128 
00133   public function argInit() {
00134     $statements = $this->subject->getInitialisationStatements();
00135     foreach($statements as $statement) {
00136       $this->testCase[] = $statement;
00137     }
00138     $this->testCase = gtCodeSnippet::appendBlankLines(2, $this->testCase );
00139   }
00140 
00141 
00146   public function fileClosing() {
00147     $this->testCase[] = "?>";
00148   }
00149 
00150 
00155   public function addSkipif() {
00156     $this->testCase[] = "--SKIPIF--";
00157     $this->testCase[] = "<?php";
00158     if($this->optionalSections->hasSkipifKey()) {
00159       $key = $this->optionalSections->getSkipifKey();
00160       //test standard skipif sections
00161       if($key == 'win') {
00162         $this->testCase = gtCodeSnippet::append('skipifwin', $this->testCase);
00163       }
00164       if($key == 'notwin' ) {
00165         $this->testCase = gtCodeSnippet::append('skipifnotwin', $this->testCase);
00166       }
00167 
00168       if($key == '64b' ) {
00169         $this->testCase = gtCodeSnippet::append('skipif64b', $this->testCase);
00170       }
00171 
00172       if($key == 'not64b' ) {
00173         $this->testCase = gtCodeSnippet::append('skipifnot64b', $this->testCase);
00174       }
00175     }
00176 
00177     if($this->optionalSections->hasSkipifExt()) {
00178       $ext = $this->optionalSections->getSkipifExt();
00179       $this->testCase[] = "if (!extension_loaded('$ext')) die ('skip $ext extension not available in this build');";
00180     }
00181     $this->testCase[] = "?>";
00182   }
00183 
00184 
00189   public function addIni() {
00190     $this->testCase[] = "--INI--";
00191     $this->testCase[] = "";
00192   }
00193 
00194 
00199   public function addClean() {
00200     $this->testCase[] = "--CLEAN--";
00201     $this->testCase[] = "<?php";
00202     $this->testCase[] = "?>";
00203   }
00204 
00205 
00210   public function addDone() {
00211     $this->testCase[] = "===DONE===";
00212   }
00213 
00214 
00219   public function addExpectf() {
00220     $this->testCase[] = "--EXPECTF--";
00221     if ($this->optionalSections->hasDone() ){
00222       $this->testCase[] = '===DONE===';
00223     }
00224   }
00225 
00226   public function getOpt() {
00227     return $this->optionalSections;
00228   }
00229 }
00230 ?>