home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / php / PEAR / PHPUnit2 / Util / TestDox / NamePrettifier.php next >
Encoding:
PHP Script  |  2008-07-02  |  4.9 KB  |  166 lines

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  3.  
  4. /**
  5.  * PHP Version 5
  6.  *
  7.  * Copyright (c) 2002-2006, Sebastian Bergmann <sb@sebastian-bergmann.de>.
  8.  * All rights reserved.
  9.  *
  10.  * Redistribution and use in source and binary forms, with or without
  11.  * modification, are permitted provided that the following conditions
  12.  * are met:
  13.  *
  14.  *   * Redistributions of source code must retain the above copyright
  15.  *     notice, this list of conditions and the following disclaimer.
  16.  * 
  17.  *   * Redistributions in binary form must reproduce the above copyright
  18.  *     notice, this list of conditions and the following disclaimer in
  19.  *     the documentation and/or other materials provided with the
  20.  *     distribution.
  21.  *
  22.  *   * Neither the name of Sebastian Bergmann nor the names of his
  23.  *     contributors may be used to endorse or promote products derived
  24.  *     from this software without specific prior written permission.
  25.  *
  26.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  27.  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  28.  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  29.  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  30.  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  31.  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  32.  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  33.  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  34.  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC
  35.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  36.  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  37.  * POSSIBILITY OF SUCH DAMAGE.
  38.  *
  39.  * @category   Testing
  40.  * @package    PHPUnit2
  41.  * @author     Sebastian Bergmann <sb@sebastian-bergmann.de>
  42.  * @copyright  2002-2006 Sebastian Bergmann <sb@sebastian-bergmann.de>
  43.  * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License
  44.  * @version    CVS: $Id: NamePrettifier.php,v 1.2.2.2 2005/12/17 16:04:58 sebastian Exp $
  45.  * @link       http://pear.php.net/package/PHPUnit2
  46.  * @since      File available since Release 2.3.0
  47.  */
  48.  
  49. /**
  50.  * Prettifies class and method names for use in TestDox documentation.
  51.  *
  52.  * @category   Testing
  53.  * @package    PHPUnit2
  54.  * @author     Sebastian Bergmann <sb@sebastian-bergmann.de>
  55.  * @copyright  2002-2006 Sebastian Bergmann <sb@sebastian-bergmann.de>
  56.  * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License
  57.  * @version    Release: 2.3.6
  58.  * @link       http://pear.php.net/package/PHPUnit2
  59.  * @since      Class available since Release 2.1.0
  60.  */
  61. class PHPUnit2_Util_TestDox_NamePrettifier {
  62.     /**
  63.      * @var    string
  64.      * @access protected
  65.      */
  66.     protected $prefix = 'Test';
  67.  
  68.     /**
  69.      * @var    string
  70.      * @access protected
  71.      */
  72.     protected $suffix = 'Test';
  73.  
  74.     /**
  75.      * Tests if a method is a test method.
  76.      *
  77.      * @param  string  $testMethodName
  78.      * @return boolean
  79.      * @access public
  80.      */
  81.     public function isATestMethod($testMethodName) {
  82.         if (substr($testMethodName, 0, 4) == 'test') {
  83.             return TRUE;
  84.         }
  85.  
  86.         return FALSE;
  87.     }
  88.  
  89.     /**
  90.      * Prettifies the name of a test class.
  91.      *
  92.      * @param  string  $testClassName
  93.      * @return string
  94.      * @access public
  95.      */
  96.     public function prettifyTestClass($testClassName) {
  97.         $title = $testClassName;
  98.  
  99.         if ($this->suffix !== NULL &&
  100.             $this->suffix == substr($testClassName, -1 * strlen($this->suffix))) {
  101.             $title = substr($title, 0, strripos($title, $this->suffix));
  102.         }
  103.  
  104.         if ($this->prefix !== NULL &&
  105.             $this->prefix == substr($testClassName, 0, strlen($this->prefix))) {
  106.             $title = substr($title, strlen($this->prefix));
  107.         }
  108.  
  109.         return $title;
  110.     }
  111.  
  112.     /**
  113.      * Prettifies the name of a test method.
  114.      *
  115.      * @param  string  $testMethodName
  116.      * @return string
  117.      * @access public
  118.      */
  119.     public function prettifyTestMethod($testMethodName) {
  120.         $buffer = '';
  121.  
  122.         $testMethodName = preg_replace('#\d+$#', '', $testMethodName);
  123.  
  124.         for ($i = 4; $i < strlen($testMethodName); $i++) {
  125.             if ($i > 4 &&
  126.                 ord($testMethodName[$i]) >= 65 && 
  127.                 ord($testMethodName[$i]) <= 90) {
  128.                 $buffer .= ' ' . strtolower($testMethodName[$i]);
  129.             } else {
  130.                 $buffer .= $testMethodName[$i];
  131.             }
  132.         }
  133.  
  134.         return $buffer;
  135.     }
  136.  
  137.     /**
  138.      * Sets the prefix of test names.
  139.      *
  140.      * @param  string  $prefix
  141.      * @access public
  142.      */
  143.     public function setPrefix($prefix) {
  144.         $this->prefix = $prefix;
  145.     }
  146.  
  147.     /**
  148.      * Sets the suffix of test names.
  149.      *
  150.      * @param  string  $prefix
  151.      * @access public
  152.      */
  153.     public function setSuffix($suffix) {
  154.         $this->suffix = $suffix;
  155.     }
  156. }
  157.  
  158. /*
  159.  * Local variables:
  160.  * tab-width: 4
  161.  * c-basic-offset: 4
  162.  * c-hanging-comment-ender-p: nil
  163.  * End:
  164.  */
  165. ?>
  166.