Testing_DocTest
[ class tree: Testing_DocTest ] [ index: Testing_DocTest ] [ all elements ]

Source for file TestCase.php

Documentation is available at TestCase.php

  1. <?php
  2.  
  3. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  4.  
  5. /**
  6.  * This file is part of the PEAR Testing_DocTest package.
  7.  *
  8.  * PHP version 5
  9.  *
  10.  * LICENSE: This source file is subject to the MIT license that is available
  11.  * through the world-wide-web at the following URI:
  12.  * http://opensource.org/licenses/mit-license.php
  13.  *
  14.  * @category  Testing
  15.  * @package   Testing_DocTest
  16.  * @author    David JEAN LOUIS <izimobil@gmail.com>
  17.  * @copyright 2008 David JEAN LOUIS
  18.  * @license   http://opensource.org/licenses/mit-license.php MIT License
  19.  * @version   CVS: $Id$
  20.  * @link      http://pear.php.net/package/Testing_DocTest
  21.  * @since     File available since release 0.1.0
  22.  * @filesource
  23.  */
  24.  
  25. /**
  26.  * This class represents a <code></code> block that contains the doc test.
  27.  *
  28.  * <code>
  29.  * $tb        = new Testing_DocTest_TestCase();
  30.  * $tb->level = 'function';
  31.  * $tb->name  = 'someFunction';
  32.  * echo $tb->name . "\n";
  33.  * $tb->altname = 'Alt name';
  34.  * echo $tb->name;
  35.  * // expects:
  36.  * // function someFunction
  37.  * // Alt name
  38.  * </code>
  39.  *
  40.  * @category  Testing
  41.  * @package   Testing_DocTest
  42.  * @author    David JEAN LOUIS <izimobil@gmail.com>
  43.  * @copyright 2008 David JEAN LOUIS
  44.  * @license   http://opensource.org/licenses/mit-license.php MIT License
  45.  * @version   Release: 0.6.0
  46.  * @link      http://pear.php.net/package/Testing_DocTest
  47.  * @since     Class available since release 0.1.0
  48.  */
  49. {
  50.     // State constants {{{
  51.  
  52.     /**
  53.      * State of the test before it is run.
  54.      */
  55.     const STATE_NOT_RUN = 0;
  56.  
  57.     /**
  58.      * State of a test that have been skipped.
  59.      */
  60.     const STATE_SKIPPED = 1;
  61.  
  62.     /**
  63.      * State of a test that passed.
  64.      */
  65.     const STATE_PASSED = 2;
  66.  
  67.     /**
  68.      * State of a test that failed.
  69.      */
  70.     const STATE_FAILED = 3;
  71.  
  72.     /**
  73.      * State of a test that had a php error.
  74.      */
  75.     const STATE_ERROR = 4;
  76.  
  77.     // }}}
  78.     // Properties {{{
  79.  
  80.     /**
  81.      * The registry items array.
  82.      *
  83.      * @var array $_properties 
  84.      * @access private
  85.      */
  86.     private $_properties = array(
  87.         'name'          => null,
  88.         'altname'       => null,
  89.         'state'         => self::STATE_NOT_RUN,
  90.         'level'         => null,
  91.         'suite'         => null,
  92.         'docComment'    => null,
  93.         'code'          => null,
  94.         'flags'         => 0,
  95.         'skipIfCode'    => null,
  96.         'tmplCode'      => null,
  97.         'cleanCode'     => null,
  98.         'setupCode'     => null,
  99.         'expectedValue' => null,
  100.         'parsingError' => null,
  101.         'lineNumber' => null,
  102.         'actualValue'   => null,
  103.     );
  104.  
  105.     /**
  106.      * Array of ini settings to pass to the process of the testcase.
  107.      *
  108.      * @var array $iniSettings 
  109.      * @access public
  110.      */
  111.     public $iniSettings = array(
  112.         'output_handler'       => '',
  113.         'output_buffering'     => '0',
  114.         'safe_mode'            => '0',
  115.         'display_errors'       => '1',
  116.         'error_prepend_string' => '',
  117.         'error_append_string'  => '',
  118.         'auto_prepend_file'    => '',
  119.         'auto_append_file'     => '',
  120.     );
  121.  
  122.     // }}}
  123.     // __toString() {{{
  124.  
  125.     /**
  126.      * String representation of the test.
  127.      *
  128.      * @return string 
  129.      * @access public
  130.      */
  131.     public function __toString()
  132.     {
  133.         return $this->name;
  134.     }
  135.  
  136.     // }}}
  137.     // __set() {{{
  138.  
  139.     /**
  140.      * Overloaded setter.
  141.      *
  142.      * @param string $name  name of property
  143.      * @param mixed  $value value of property
  144.      *
  145.      * @return void 
  146.      * @access public
  147.      */
  148.     public function __set($name$value)
  149.     {
  150.         $this->_properties[$name$value;
  151.     }
  152.  
  153.     // }}}
  154.     // __get() {{{
  155.  
  156.     /**
  157.      * Overloaded getter.
  158.      *
  159.      * @param string $name name of property
  160.      *
  161.      * @return mixed 
  162.      * @access public
  163.      */
  164.     public function __get($name)
  165.     {
  166.         if (isset($this->_properties[$name])) {
  167.             if ($name == 'name'{
  168.                 if ($this->altname !== null{
  169.                     return $this->altname;
  170.                 else {
  171.                     return $this->level ' ' $this->_properties['name'];
  172.                 }
  173.             }
  174.             return $this->_properties[$name];
  175.         }
  176.         return null;
  177.     }
  178.  
  179.     // }}}
  180.     // hasFlag() {{{
  181.  
  182.     /**
  183.      * Return true if the test has the flag $flag set or not.
  184.      *
  185.      * <code>
  186.      * require_once "Testing/DocTest.php";
  187.      * $test = new Testing_DocTest_TestCase();
  188.      * $test->flags  = Testing_DocTest::FLAG_ELLIPSIS
  189.      *               | Testing_DocTest::FLAG_NORMALIZE_WHITESPACE
  190.      *               | Testing_DocTest::FLAG_CASE_INSENSITIVE;
  191.      * $test->flags &= ~Testing_DocTest::FLAG_CASE_INSENSITIVE;
  192.      * var_dump($test->flags);
  193.      * var_dump($test->hasFlag(Testing_DocTest::FLAG_ELLIPSIS));
  194.      * var_dump($test->hasFlag(Testing_DocTest::FLAG_NORMALIZE_WHITESPACE));
  195.      * var_dump($test->hasFlag(Testing_DocTest::FLAG_CASE_INSENSITIVE));
  196.      * // expects:
  197.      * // int(9)
  198.      * // bool(true)
  199.      * // bool(true)
  200.      * // bool(false)
  201.      * </code>
  202.      *
  203.      * @param int $flag one of the DOCTEST::FLAG_* constants.
  204.      *
  205.      * @return boolean 
  206.      * @access public
  207.      */
  208.     public function hasFlag($flag)
  209.     {
  210.         return ($this->flags $flag=== $flag;
  211.     }
  212.  
  213.     // }}}
  214. }

Documentation generated on Mon, 11 Mar 2019 15:52:27 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.