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 / ResultPrinter.php < prev   
Encoding:
PHP Script  |  2008-07-02  |  8.1 KB  |  300 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: ResultPrinter.php,v 1.2.2.6 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. require_once 'PHPUnit2/Framework/TestListener.php';
  50. require_once 'PHPUnit2/Util/TestDox/NamePrettifier.php';
  51. require_once 'PHPUnit2/Util/Printer.php';
  52.  
  53. /**
  54.  * Base class for printers of TestDox documentation.
  55.  *
  56.  * @category   Testing
  57.  * @package    PHPUnit2
  58.  * @author     Sebastian Bergmann <sb@sebastian-bergmann.de>
  59.  * @copyright  2002-2006 Sebastian Bergmann <sb@sebastian-bergmann.de>
  60.  * @license    http://www.opensource.org/licenses/bsd-license.php  BSD License
  61.  * @version    Release: 2.3.6
  62.  * @link       http://pear.php.net/package/PHPUnit2
  63.  * @since      Class available since Release 2.1.0
  64.  * @abstract
  65.  */
  66. abstract class PHPUnit2_Util_TestDox_ResultPrinter extends PHPUnit2_Util_Printer implements PHPUnit2_Framework_TestListener {
  67.     /**
  68.      * @var    PHPUnit2_Util_TestDox_NamePrettifier
  69.      * @access protected
  70.      */
  71.     protected $prettifier;
  72.  
  73.     /**
  74.      * @var    string
  75.      * @access protected
  76.      */
  77.     protected $testClass = '';
  78.  
  79.     /**
  80.      * @var    boolean
  81.      * @access protected
  82.      */
  83.     protected $testFailed = FALSE;
  84.  
  85.     /**
  86.      * @var    array
  87.      * @access protected
  88.      */
  89.     protected $tests = array();
  90.  
  91.     /**
  92.      * Constructor.
  93.      *
  94.      * @param  resource  $out
  95.      * @access public
  96.      */
  97.     public function __construct($out = NULL) {
  98.         parent::__construct($out);
  99.  
  100.         $this->prettifier = new PHPUnit2_Util_TestDox_NamePrettifier;
  101.         $this->startRun();
  102.     }
  103.  
  104.     /**
  105.      * Destructor.
  106.      *
  107.      * @access public
  108.      */
  109.     public function __destruct() {
  110.         $this->doEndClass();
  111.         $this->endRun();
  112.  
  113.         parent::__destruct();
  114.     }
  115.  
  116.     /**
  117.      * Abstract Factory.
  118.      *
  119.      * @param  string    $type
  120.      * @param  resource  $out
  121.      * @throws Exception
  122.      * @access public
  123.      * @static
  124.      */
  125.     public static function factory($type, $out = NULL) {
  126.         require_once 'PHPUnit2/Util/TestDox/ResultPrinter/' . $type . '.php';
  127.  
  128.         $class = 'PHPUnit2_Util_TestDox_ResultPrinter_' . $type;
  129.         return new $class($out);
  130.     }
  131.  
  132.     /**
  133.      * An error occurred.
  134.      *
  135.      * @param  PHPUnit2_Framework_Test $test
  136.      * @param  Exception               $e
  137.      * @access public
  138.      */
  139.     public function addError(PHPUnit2_Framework_Test $test, Exception $e) {
  140.         $this->testFailed = TRUE;
  141.     }
  142.  
  143.     /**
  144.      * A failure occurred.
  145.      *
  146.      * @param  PHPUnit2_Framework_Test                 $test
  147.      * @param  PHPUnit2_Framework_AssertionFailedError $e
  148.      * @access public
  149.      */
  150.     public function addFailure(PHPUnit2_Framework_Test $test, PHPUnit2_Framework_AssertionFailedError $e) {
  151.         $this->testFailed = TRUE;
  152.     }
  153.  
  154.     /**
  155.      * Incomplete test.
  156.      *
  157.      * @param  PHPUnit2_Framework_Test $test
  158.      * @param  Exception               $e
  159.      * @access public
  160.      */
  161.     public function addIncompleteTest(PHPUnit2_Framework_Test $test, Exception $e) {
  162.         $this->testFailed = TRUE;
  163.     }
  164.  
  165.     /**
  166.      * A testsuite started.
  167.      *
  168.      * @param  PHPUnit2_Framework_TestSuite $suite
  169.      * @access public
  170.      * @since  Method available since Release 2.2.0
  171.      */
  172.     public function startTestSuite(PHPUnit2_Framework_TestSuite $suite) {
  173.     }
  174.  
  175.     /**
  176.      * A testsuite ended.
  177.      *
  178.      * @param  PHPUnit2_Framework_TestSuite $suite
  179.      * @access public
  180.      * @since  Method available since Release 2.2.0
  181.      */
  182.     public function endTestSuite(PHPUnit2_Framework_TestSuite $suite) {
  183.     }
  184.  
  185.     /**
  186.      * A test started.
  187.      *
  188.      * @param  PHPUnit2_Framework_Test $test
  189.      * @access public
  190.      */
  191.     public function startTest(PHPUnit2_Framework_Test $test) {
  192.         $class = get_class($test);
  193.  
  194.         if ($this->testClass != $class) {
  195.             if ($this->testClass != '') {
  196.                 $this->doEndClass();
  197.             }
  198.  
  199.             $this->startClass($this->prettifier->prettifyTestClass($class));
  200.  
  201.             $this->testClass = $class;
  202.             $this->tests     = array();
  203.         }
  204.  
  205.         $this->testFailed = FALSE;
  206.     }
  207.  
  208.     /**
  209.      * A test ended.
  210.      *
  211.      * @param  PHPUnit2_Framework_Test $test
  212.      * @access public
  213.      */
  214.     public function endTest(PHPUnit2_Framework_Test $test) {
  215.         $prettifiedName = $this->prettifier->prettifyTestMethod($test->getName());
  216.  
  217.         if (!isset($this->tests[$prettifiedName])) {
  218.             if (!$this->testFailed) {
  219.                 $this->tests[$prettifiedName]['success'] = 1;
  220.                 $this->tests[$prettifiedName]['failure'] = 0;
  221.             } else {
  222.                 $this->tests[$prettifiedName]['success'] = 0;
  223.                 $this->tests[$prettifiedName]['failure'] = 1;
  224.             }
  225.         } else {
  226.             if (!$this->testFailed) {
  227.                 $this->tests[$prettifiedName]['success']++;
  228.             } else {
  229.                 $this->tests[$prettifiedName]['failure']++;
  230.             }
  231.         }
  232.     }
  233.  
  234.     /**
  235.      * @access private
  236.      * @since  Method available since Release 2.3.0
  237.      */
  238.     private function doEndClass() {
  239.         foreach ($this->tests as $name => $data) {
  240.             if ($data['failure'] == 0) {
  241.                 $this->onTest($name);
  242.             }
  243.         }
  244.  
  245.         $this->endClass($this->prettifier->prettifyTestClass($this->testClass));
  246.     }
  247.  
  248.     /**
  249.      * Handler for 'start run' event.
  250.      *
  251.      * @access protected
  252.      */
  253.     protected function startRun() {
  254.     }
  255.  
  256.     /**
  257.      * Handler for 'start class' event.
  258.      *
  259.      * @param  string $name
  260.      * @access protected
  261.      * @abstract
  262.      */
  263.     abstract protected function startClass($name);
  264.  
  265.     /**
  266.      * Handler for 'on test' event.
  267.      *
  268.      * @param  string $name
  269.      * @access protected
  270.      * @abstract
  271.      */
  272.     abstract protected function onTest($name);
  273.  
  274.     /**
  275.      * Handler for 'end class' event.
  276.      *
  277.      * @param  string $name
  278.      * @access protected
  279.      * @abstract
  280.      */
  281.     abstract protected function endClass($name);
  282.  
  283.     /**
  284.      * Handler for 'end run' event.
  285.      *
  286.      * @access protected
  287.      */
  288.     protected function endRun() {
  289.     }
  290. }
  291.  
  292. /*
  293.  * Local variables:
  294.  * tab-width: 4
  295.  * c-basic-offset: 4
  296.  * c-hanging-comment-ender-p: nil
  297.  * End:
  298.  */
  299. ?>
  300.