Back to index

php5  5.3.10
Public Member Functions | Static Public Member Functions | Protected Attributes
gtBasicTestCaseFunction Class Reference

Basic test case for a PHP function. More...

Inheritance diagram for gtBasicTestCaseFunction:
Inheritance graph
[legend]
Collaboration diagram for gtBasicTestCaseFunction:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 __construct ($opt)
 setFunction ($function)
 Set the function name.
 constructTestCase ()
 testHeader ()
 Construct test case header.
 subjectCalls ()
 Add the test section to call the function.
 constructSubjectCalls ()
 addBasicEcho ()
 toString ()
 Convert test case from array to string.
 getTestCase ()
 Returns test case as a array.
 ConstructCommonHeaders ()
 Construct the common headers (title, file section..) of the test case.
 ConstructCommonClosing ()
 Construct the common closing statements (clean, done, EXPECTF...)
 fileOpening ()
 Start the FILE section of the test.
 constructorArgInit ()
 Add contructor argument initialisation to test case.
 constructorCreateInstance ()
 Create instance of class in the test case.
 argInit ()
 Add function or method initilaisation statements to the test case.
 fileClosing ()
 Add FILE section closing tag to the test case.
 addSkipif ()
 Add a skipif section to the test case.
 addIni ()
 Add an INI section to the test case.
 addClean ()
 Add a clean section to the test case.
 addDone ()
 Add a ===DONE=== statement to the test case.
 addExpectf ()
 Add an EXPECTF section.
 getOpt ()

Static Public Member Functions

static getInstance ($optionalSections, $type= 'function')
 Returns an instance of a test case for a method or a function.

Protected Attributes

 $subject
 $testCase
 $optionalSections

Detailed Description

Basic test case for a PHP function.

Definition at line 7 of file gtBasicTestCaseFunction.php.


Constructor & Destructor Documentation

Definition at line 10 of file gtBasicTestCaseFunction.php.

                                    {
    $this->optionalSections = $opt;
  }

Member Function Documentation

Definition at line 32 of file gtBasicTestCase.php.

                                 {
    $this->testCase[] = "echo \"*** Test by calling method or function with its expected arguments ***\\n\";";
    $this->testCase = gtCodeSnippet::appendBlankLines(1, $this->testCase );
  }

Here is the call graph for this function:

Here is the caller graph for this function:

gtTestCase::addClean ( ) [inherited]

Add a clean section to the test case.

Definition at line 199 of file gtTestCase.php.

                             {
    $this->testCase[] = "--CLEAN--";
    $this->testCase[] = "<?php";
    $this->testCase[] = "?>";
  }

Here is the caller graph for this function:

gtTestCase::addDone ( ) [inherited]

Add a ===DONE=== statement to the test case.

Definition at line 210 of file gtTestCase.php.

                            {
    $this->testCase[] = "===DONE===";
  }

Here is the caller graph for this function:

gtTestCase::addExpectf ( ) [inherited]

Add an EXPECTF section.

Definition at line 219 of file gtTestCase.php.

                               {
    $this->testCase[] = "--EXPECTF--";
    if ($this->optionalSections->hasDone() ){
      $this->testCase[] = '===DONE===';
    }
  }

Here is the caller graph for this function:

gtTestCase::addIni ( ) [inherited]

Add an INI section to the test case.

Definition at line 189 of file gtTestCase.php.

                           {
    $this->testCase[] = "--INI--";
    $this->testCase[] = "";
  }

Here is the caller graph for this function:

gtTestCase::addSkipif ( ) [inherited]

Add a skipif section to the test case.

Definition at line 155 of file gtTestCase.php.

                              {
    $this->testCase[] = "--SKIPIF--";
    $this->testCase[] = "<?php";
    if($this->optionalSections->hasSkipifKey()) {
      $key = $this->optionalSections->getSkipifKey();
      //test standard skipif sections
      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[] = "?>";
  }

Here is the call graph for this function:

Here is the caller graph for this function:

gtTestCase::argInit ( ) [inherited]

Add function or method initilaisation statements to the test case.

Definition at line 133 of file gtTestCase.php.

                            {
    $statements = $this->subject->getInitialisationStatements();
    foreach($statements as $statement) {
      $this->testCase[] = $statement;
    }
    $this->testCase = gtCodeSnippet::appendBlankLines(2, $this->testCase );
  }

Here is the call graph for this function:

Here is the caller graph for this function:

Construct the common closing statements (clean, done, EXPECTF...)

Definition at line 81 of file gtTestCase.php.

                                           {
    $this->fileClosing();
     
    if ($this->optionalSections->hasDone()) {
      $this->addDone();
    }
     
    if ($this->optionalSections->hasClean()) {
      $this->addClean();
    }

    $this->addExpectf();
  }

Here is the call graph for this function:

Construct the common headers (title, file section..) of the test case.

Definition at line 62 of file gtTestCase.php.

                                           {
    $this->testHeader();

    if($this->optionalSections->hasSkipif()) {
      $this->addSkipif();
    }

    if($this->optionalSections->hasIni()) {
      $this->addIni();
    }

    $this->fileOpening();
  }

Here is the call graph for this function:

Add contructor argument initialisation to test case.

Definition at line 110 of file gtTestCase.php.

                                       {
    $conStatements = $this->subject->getConstructorInitStatements();
    foreach($conStatements as $statement) {
      $this->testCase[] = $statement;
    }
  }

Here is the caller graph for this function:

Create instance of class in the test case.

Definition at line 122 of file gtTestCase.php.

                                              {
    $constructorList = $this->subject->getConstructorArgumentList();
    $this->testCase[] = "\$class = new ".$this->subject->getClassName()."( ".$constructorList." );";
    $this->testCase = gtCodeSnippet::appendBlankLines(2, $this->testCase );
  }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 27 of file gtBasicTestCase.php.

                                          {
        $this->argInit();
        $this->subjectCalls();
  }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 23 of file gtBasicTestCaseFunction.php.

                                      {
    $this->constructCommonHeaders();
    
    $this->addBasicEcho();
    
    $this->constructSubjectCalls();
    
    $this->constructCommonClosing();
   
  }

Here is the call graph for this function:

gtTestCase::fileClosing ( ) [inherited]

Add FILE section closing tag to the test case.

Definition at line 146 of file gtTestCase.php.

                                {
    $this->testCase[] = "?>";
  }

Here is the caller graph for this function:

gtTestCase::fileOpening ( ) [inherited]

Start the FILE section of the test.

Definition at line 99 of file gtTestCase.php.

                                {
    $this->testCase[] = "--FILE--";
    $this->testCase[] = "<?php";
    $this->testCase = gtCodeSnippet::appendBlankLines(2, $this->testCase );
  }

Here is the call graph for this function:

Here is the caller graph for this function:

static gtBasicTestCase::getInstance ( optionalSections,
type = 'function' 
) [static, inherited]

Returns an instance of a test case for a method or a function.

Parameters:
string$type
Returns:
test case object

Definition at line 18 of file gtBasicTestCase.php.

                                                                            {
    if($type == 'function') {
      return new gtBasicTestCaseFunction($optionalSections);
    }
    if($type =='method') {
      return new gtBasicTestCaseMethod($optionalSections);
    }
  }

Here is the caller graph for this function:

gtTestCase::getOpt ( ) [inherited]

Definition at line 226 of file gtTestCase.php.

gtTestCase::getTestCase ( ) [inherited]

Returns test case as a array.

Returns:
array

Definition at line 53 of file gtTestCase.php.

                                {
    return $this->testCase;
  }

Set the function name.

Parameters:
gtFunction$function

Definition at line 19 of file gtBasicTestCaseFunction.php.

                                         {
    $this->subject = $function;
  }

Add the test section to call the function.

Definition at line 49 of file gtBasicTestCaseFunction.php.

                                 {
    // Construct the argument list to pass to the function being tested
    $lists = $this->subject->getValidArgumentLists();

    foreach($lists as $list){

      $this->testCase = gtCodeSnippet::appendBlankLines(1, $this->testCase );
      $this->testCase[] = "var_dump(".$this->subject->getName()."( ".$list." ) );";
    }
    $this->testCase = gtCodeSnippet::appendBlankLines(2, $this->testCase );
  }

Here is the call graph for this function:

Construct test case header.

Definition at line 39 of file gtBasicTestCaseFunction.php.

                               {
    //Opening section and start of test case array.
    $this->testCase[] = "--TEST--";
    $this->testCase[] = "Test function ".$this->subject->getName()."() by calling it with its expected arguments";
  }
gtTestCase::toString ( ) [inherited]

Convert test case from array to string.

Returns:
string

Definition at line 38 of file gtTestCase.php.

                             {
    $testCaseString = "";
    foreach($this->testCase as $line) {
      $testCaseString .= $line."\n";
    }
    return $testCaseString;
  }

Member Data Documentation

gtTestCase::$optionalSections [protected, inherited]

Definition at line 30 of file gtTestCase.php.

gtBasicTestCase::$subject [protected, inherited]

Reimplemented from gtTestCase.

Definition at line 9 of file gtBasicTestCase.php.

gtTestCase::$testCase [protected, inherited]

Reimplemented in gtVariationTestCaseMethod, and gtVariationTestCaseFunction.

Definition at line 22 of file gtTestCase.php.


The documentation for this class was generated from the following file: