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

Source for file ResultPrinter.php

Documentation is available at ResultPrinter.php

  1. <?php
  2. //
  3. // +------------------------------------------------------------------------+
  4. // | PEAR :: PHPUnit                                                        |
  5. // +------------------------------------------------------------------------+
  6. // | Copyright (c) 2002-2004 Sebastian Bergmann <sb@sebastian-bergmann.de>. |
  7. // +------------------------------------------------------------------------+
  8. // | This source file is subject to version 3.00 of the PHP License,        |
  9. // | that is available at http://www.php.net/license/3_0.txt.               |
  10. // | If you did not receive a copy of the PHP license and are unable to     |
  11. // | obtain it through the world-wide-web, please send a note to            |
  12. // | license@php.net so we can mail you a copy immediately.                 |
  13. // +------------------------------------------------------------------------+
  14. //
  15. // $Id: ResultPrinter.php,v 1.1.2.3 2004/10/01 06:11:53 sebastian Exp $
  16. //
  17.  
  18. require_once 'PHPUnit2/Framework/TestListener.php';
  19. require_once 'PHPUnit2/Extensions/TestDox/NamePrettifier.php';
  20. require_once 'PHPUnit2/Util/Printer.php';
  21.  
  22. /**
  23.  * @author      Sebastian Bergmann <sb@sebastian-bergmann.de>
  24.  * @copyright   Copyright &copy; 2002-2004 Sebastian Bergmann <sb@sebastian-bergmann.de>
  25.  * @license     http://www.php.net/license/3_0.txt The PHP License, Version 3.0
  26.  * @category    Testing
  27.  * @package     PHPUnit2
  28.  * @subpackage  Extensions
  29.  * @since       2.1.0
  30.  */
  31.     // {{{ Members
  32.  
  33.     /**
  34.     * @var    PHPUnit2_Extensions_TestDox_NamePrettifier 
  35.     * @access protected
  36.     */
  37.     protected $prettifier;
  38.  
  39.     /**
  40.     * @var    string 
  41.     * @access protected
  42.     */
  43.     protected $testClass = '';
  44.  
  45.     /**
  46.     * @var    boolean 
  47.     * @access protected
  48.     */
  49.     protected $testFailed = FALSE;
  50.  
  51.     // }}}
  52.     // {{{ public function __construct($out = NULL)
  53.  
  54.     /**
  55.     * Constructor.
  56.     *
  57.     * @param  resource  $out 
  58.     * @access public
  59.     */
  60.     public function __construct($out = NULL{
  61.         parent::__construct($out);
  62.  
  63.         $this->startRun();
  64.     }
  65.  
  66.     // }}}
  67.     // {{{ public function __destruct()
  68.  
  69.     /**
  70.     * Destructor.
  71.     *
  72.     * @access public
  73.     */
  74.     public function __destruct({
  75.         $this->endClass($this->prettifier->prettifyTestClass($this->testClass));
  76.         $this->endRun();
  77.  
  78.         parent::__destruct();
  79.     }
  80.  
  81.     // }}}
  82.     // {{{ public function factory($type, $out)
  83.  
  84.     /**
  85.     * Abstract Factory.
  86.     *
  87.     * @param  string    $type 
  88.     * @param  resource  $out 
  89.     * @access public
  90.     * @static
  91.     */
  92.     public static function factory($type$out = NULL{
  93.         $class 'PHPUnit2_Extensions_TestDox_ResultPrinter_' $type;
  94.  
  95.         if (@require_once('PHPUnit2/Extensions/TestDox/ResultPrinter/' $type '.php')) {
  96.             $object = new $class($out);
  97.  
  98.             return $object;
  99.         else {
  100.             throw new Exception(
  101.               sprintf(
  102.                 'Could not load class %s.',
  103.                 $class
  104.               )
  105.             );
  106.         }
  107.     }
  108.  
  109.     // }}}
  110.     // {{{ public function addError(PHPUnit2_Framework_Test $test, Exception $e)
  111.  
  112.     /**
  113.     * An error occurred.
  114.     *
  115.     * @param  PHPUnit2_Framework_Test $test 
  116.     * @param  Exception               $e 
  117.     * @access public
  118.     */
  119.     public function addError(PHPUnit2_Framework_Test $testException $e{
  120.         $this->testFailed = TRUE;
  121.     }
  122.  
  123.     // }}}
  124.     // {{{ public function addFailure(PHPUnit2_Framework_Test $test, PHPUnit2_Framework_AssertionFailedError $e)
  125.  
  126.     /**
  127.     * A failure occurred.
  128.     *
  129.     * @param  PHPUnit2_Framework_Test                 $test 
  130.     * @param  PHPUnit2_Framework_AssertionFailedError $e 
  131.     * @access public
  132.     */
  133.     public function addFailure(PHPUnit2_Framework_Test $testPHPUnit2_Framework_AssertionFailedError $e{
  134.         $this->testFailed = TRUE;
  135.     }
  136.  
  137.     // }}}
  138.     // {{{ public function addIncompleteTest(PHPUnit2_Framework_Test $test, Exception $e)
  139.  
  140.     /**
  141.     * Incomplete test.
  142.     *
  143.     * @param  PHPUnit2_Framework_Test $test 
  144.     * @param  Exception               $e 
  145.     * @access public
  146.     */
  147.     public function addIncompleteTest(PHPUnit2_Framework_Test $testException $e{
  148.         $this->testFailed = TRUE;
  149.     }
  150.  
  151.     // }}}
  152.     // {{{ public function endTest(PHPUnit2_Framework_Test $test)
  153.  
  154.     /**
  155.     * A test ended.
  156.     *
  157.     * @param  PHPUnit2_Framework_Test $test 
  158.     * @access public
  159.     */
  160.     public function endTest(PHPUnit2_Framework_Test $test{
  161.         if (!$this->testFailed{
  162.             $this->onTest($this->prettifier->prettifyTestMethod($test->getName()));
  163.         }
  164.     }
  165.  
  166.     // }}}
  167.     // {{{ public function startTest(PHPUnit2_Framework_Test $test)
  168.  
  169.     /**
  170.     * A test started.
  171.     *
  172.     * @param  PHPUnit2_Framework_Test $test 
  173.     * @access public
  174.     */
  175.     public function startTest(PHPUnit2_Framework_Test $test{
  176.         $class get_class($test);
  177.  
  178.         if ($this->testClass != $class{
  179.             if ($this->testClass != ''{
  180.                 $this->endClass($this->prettifier->prettifyTestClass($this->testClass));
  181.             }
  182.  
  183.             $this->startClass($this->prettifier->prettifyTestClass($class));
  184.             $this->testClass = $class;
  185.         }
  186.  
  187.         $this->testFailed = FALSE;
  188.     }
  189.  
  190.     // }}}
  191.     // {{{ abstract protected function startClass($name)
  192.  
  193.     /**
  194.     * Handler for 'start class' event.
  195.     *
  196.     * @param  string $name 
  197.     * @access public
  198.     * @abstract
  199.     */
  200.     abstract protected function startClass($name);
  201.  
  202.     // }}}
  203.     // {{{ abstract protected function onTest($name)
  204.  
  205.     /**
  206.     * Handler for 'on test' event.
  207.     *
  208.     * @param  string $name 
  209.     * @access public
  210.     * @abstract
  211.     */
  212.     abstract protected function onTest($name);
  213.  
  214.     // }}}
  215.     // {{{ abstract protected function endClass($name)
  216.  
  217.     /**
  218.     * Handler for 'end class' event.
  219.     *
  220.     * @param  string $name 
  221.     * @access public
  222.     * @abstract
  223.     */
  224.     abstract protected function endClass($name);
  225.  
  226.     // }}}
  227.     // {{{ abstract protected function startRun()
  228.  
  229.     /**
  230.     * Handler for 'start run' event.
  231.     *
  232.     * @access public
  233.     * @abstract
  234.     */
  235.     abstract protected function startRun();
  236.  
  237.     // }}}
  238.     // {{{ abstract protected function endRun()
  239.  
  240.     /**
  241.     * Handler for 'end run' event.
  242.     *
  243.     * @access public
  244.     * @abstract
  245.     */
  246.     abstract protected function endRun();
  247.  
  248.     // }}}
  249. }
  250.  
  251. /*
  252.  * vim600:  et sw=2 ts=2 fdm=marker
  253.  * vim<600: et sw=2 ts=2
  254.  */
  255. ?>

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