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.3.1
  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.         'cleanCode'     => null,
  97.         'expectedValue' => null,
  98.         'actualValue'   => null,
  99.     );
  100.  
  101.     /**
  102.      * Array of ini settings to pass to the process of the testcase.
  103.      *
  104.      * @var array $iniSettings 
  105.      * @access public
  106.      */
  107.     public $iniSettings = array(
  108.         'output_handler'       => '',
  109.         'output_buffering'     => '0',
  110.         'safe_mode'            => '0',
  111.         'display_errors'       => '1',
  112.         'error_prepend_string' => '',
  113.         'error_append_string'  => '',
  114.         'auto_prepend_file'    => '',
  115.         'auto_append_file'     => '',
  116.     );
  117.  
  118.     // }}}
  119.     // __toString() {{{
  120.  
  121.     /**
  122.      * String representation of the test.
  123.      *
  124.      * @return string 
  125.      * @access public
  126.      */
  127.     public function __toString()
  128.     {
  129.         return $this->name;
  130.     }
  131.  
  132.     // }}}
  133.     // __set() {{{
  134.  
  135.     /**
  136.      * Overloaded setter.
  137.      *
  138.      * @param string $name  name of property
  139.      * @param mixed  $value value of property
  140.      *
  141.      * @return void 
  142.      * @access public
  143.      */
  144.     public function __set($name$value)
  145.     {
  146.         $this->_properties[$name$value;
  147.     }
  148.  
  149.     // }}}
  150.     // __get() {{{
  151.  
  152.     /**
  153.      * Overloaded getter.
  154.      *
  155.      * @param string $name name of property
  156.      *
  157.      * @return mixed 
  158.      * @access public
  159.      */
  160.     public function __get($name)
  161.     {
  162.         if (isset($this->_properties[$name])) {
  163.             if ($name == 'name'{
  164.                 if ($this->altname !== null{
  165.                     return $this->altname;
  166.                 else {
  167.                     return $this->level ' ' $this->_properties['name'];
  168.                 }
  169.             }
  170.             return $this->_properties[$name];
  171.         }
  172.         return null;
  173.     }
  174.  
  175.     // }}}
  176.     // hasFlag() {{{
  177.  
  178.     /**
  179.      * Return true if the test has the flag $flag set or not.
  180.      *
  181.      * <code>
  182.      * require_once "Testing/DocTest.php";
  183.      * $test = new Testing_DocTest_TestCase();
  184.      * $test->flags  = Testing_DocTest::FLAG_ELLIPSIS
  185.      *               | Testing_DocTest::FLAG_NORMALIZE_WHITESPACE
  186.      *               | Testing_DocTest::FLAG_CASE_INSENSITIVE;
  187.      * $test->flags &= ~Testing_DocTest::FLAG_CASE_INSENSITIVE;
  188.      * var_dump($test->flags);
  189.      * var_dump($test->hasFlag(Testing_DocTest::FLAG_ELLIPSIS));
  190.      * var_dump($test->hasFlag(Testing_DocTest::FLAG_NORMALIZE_WHITESPACE));
  191.      * var_dump($test->hasFlag(Testing_DocTest::FLAG_CASE_INSENSITIVE));
  192.      * // expects:
  193.      * // int(9)
  194.      * // bool(true)
  195.      * // bool(true)
  196.      * // bool(false)
  197.      * </code>
  198.      *
  199.      * @param int $flag one of the DOCTEST::FLAG_* constants.
  200.      *
  201.      * @return boolean 
  202.      * @access public
  203.      */
  204.     public function hasFlag($flag)
  205.     {
  206.         return ($this->flags $flag=== $flag;
  207.     }
  208.  
  209.     // }}}
  210. }

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