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-2005 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.6.2.2 2005/02/04 10:01:55 sebastian Exp $
  16. //
  17.  
  18. require_once 'PHPUnit2/Framework/AssertionFailedError.php';
  19. require_once 'PHPUnit2/Framework/Test.php';
  20. require_once 'PHPUnit2/Framework/TestListener.php';
  21. require_once 'PHPUnit2/Framework/TestSuite.php';
  22. require_once 'PHPUnit2/Extensions/TestDox/NamePrettifier.php';
  23. require_once 'PHPUnit2/Util/Printer.php';
  24.  
  25. /**
  26.  * @author      Sebastian Bergmann <sb@sebastian-bergmann.de>
  27.  * @copyright   Copyright &copy; 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>
  28.  * @license     http://www.php.net/license/3_0.txt The PHP License, Version 3.0
  29.  * @category    Testing
  30.  * @package     PHPUnit2
  31.  * @subpackage  Extensions
  32.  * @since       2.1.0
  33.  */
  34.     // {{{ Instance Variables
  35.  
  36.     /**
  37.     * @var    PHPUnit2_Extensions_TestDox_NamePrettifier 
  38.     * @access protected
  39.     */
  40.     protected $prettifier;
  41.  
  42.     /**
  43.     * @var    string 
  44.     * @access protected
  45.     */
  46.     protected $testClass = '';
  47.  
  48.     /**
  49.     * @var    boolean 
  50.     * @access protected
  51.     */
  52.     protected $testFailed = FALSE;
  53.  
  54.     // }}}
  55.     // {{{ public function __construct($out = NULL)
  56.  
  57.     /**
  58.     * Constructor.
  59.     *
  60.     * @param  resource  $out 
  61.     * @access public
  62.     */
  63.     public function __construct($out = NULL{
  64.         parent::__construct($out);
  65.  
  66.         $this->startRun();
  67.     }
  68.  
  69.     // }}}
  70.     // {{{ public function __destruct()
  71.  
  72.     /**
  73.     * Destructor.
  74.     *
  75.     * @access public
  76.     */
  77.     public function __destruct({
  78.         $this->endClass($this->prettifier->prettifyTestClass($this->testClass));
  79.         $this->endRun();
  80.  
  81.         parent::__destruct();
  82.     }
  83.  
  84.     // }}}
  85.     // {{{ public function factory($type, $out)
  86.  
  87.     /**
  88.     * Abstract Factory.
  89.     *
  90.     * @param  string    $type 
  91.     * @param  resource  $out 
  92.     * @access public
  93.     * @static
  94.     */
  95.     public static function factory($type$out = NULL{
  96.         $class 'PHPUnit2_Extensions_TestDox_ResultPrinter_' $type;
  97.  
  98.         if (@require_once('PHPUnit2/Extensions/TestDox/ResultPrinter/' $type '.php')) {
  99.             $object = new $class($out);
  100.  
  101.             return $object;
  102.         else {
  103.             throw new Exception(
  104.               sprintf(
  105.                 'Could not load class %s.',
  106.                 $class
  107.               )
  108.             );
  109.         }
  110.     }
  111.  
  112.     // }}}
  113.     // {{{ public function addError(PHPUnit2_Framework_Test $test, Exception $e)
  114.  
  115.     /**
  116.     * An error occurred.
  117.     *
  118.     * @param  PHPUnit2_Framework_Test $test 
  119.     * @param  Exception               $e 
  120.     * @access public
  121.     */
  122.     public function addError(PHPUnit2_Framework_Test $testException $e{
  123.         $this->testFailed = TRUE;
  124.     }
  125.  
  126.     // }}}
  127.     // {{{ public function addFailure(PHPUnit2_Framework_Test $test, PHPUnit2_Framework_AssertionFailedError $e)
  128.  
  129.     /**
  130.     * A failure occurred.
  131.     *
  132.     * @param  PHPUnit2_Framework_Test                 $test 
  133.     * @param  PHPUnit2_Framework_AssertionFailedError $e 
  134.     * @access public
  135.     */
  136.     public function addFailure(PHPUnit2_Framework_Test $testPHPUnit2_Framework_AssertionFailedError $e{
  137.         $this->testFailed = TRUE;
  138.     }
  139.  
  140.     // }}}
  141.     // {{{ public function addIncompleteTest(PHPUnit2_Framework_Test $test, Exception $e)
  142.  
  143.     /**
  144.     * Incomplete test.
  145.     *
  146.     * @param  PHPUnit2_Framework_Test $test 
  147.     * @param  Exception               $e 
  148.     * @access public
  149.     */
  150.     public function addIncompleteTest(PHPUnit2_Framework_Test $testException $e{
  151.         $this->testFailed = TRUE;
  152.     }
  153.  
  154.     // }}}
  155.     // {{{ public function startTestSuite(PHPUnit2_Framework_TestSuite $suite)
  156.  
  157.     /**
  158.     * A testsuite started.
  159.     *
  160.     * @param  PHPUnit2_Framework_TestSuite $suite 
  161.     * @access public
  162.     * @since  2.2.0
  163.     */
  164.     public function startTestSuite(PHPUnit2_Framework_TestSuite $suite{
  165.     }
  166.  
  167.     // }}}
  168.     // {{{ public function endTestSuite(PHPUnit2_Framework_TestSuite $suite)
  169.  
  170.     /**
  171.     * A testsuite ended.
  172.     *
  173.     * @param  PHPUnit2_Framework_TestSuite $suite 
  174.     * @access public
  175.     * @since  2.2.0
  176.     */
  177.     public function endTestSuite(PHPUnit2_Framework_TestSuite $suite{
  178.     }
  179.  
  180.     // }}}
  181.     // {{{ public function startTest(PHPUnit2_Framework_Test $test)
  182.  
  183.     /**
  184.     * A test started.
  185.     *
  186.     * @param  PHPUnit2_Framework_Test $test 
  187.     * @access public
  188.     */
  189.     public function startTest(PHPUnit2_Framework_Test $test{
  190.         $class get_class($test);
  191.  
  192.         if ($this->testClass != $class{
  193.             if ($this->testClass != ''{
  194.                 $this->endClass($this->prettifier->prettifyTestClass($this->testClass));
  195.             }
  196.  
  197.             $this->startClass($this->prettifier->prettifyTestClass($class));
  198.             $this->testClass = $class;
  199.         }
  200.  
  201.         $this->testFailed = FALSE;
  202.     }
  203.  
  204.     // }}}
  205.     // {{{ public function endTest(PHPUnit2_Framework_Test $test)
  206.  
  207.     /**
  208.     * A test ended.
  209.     *
  210.     * @param  PHPUnit2_Framework_Test $test 
  211.     * @access public
  212.     */
  213.     public function endTest(PHPUnit2_Framework_Test $test{
  214.         if (!$this->testFailed{
  215.             $this->onTest($this->prettifier->prettifyTestMethod($test->getName()));
  216.         }
  217.     }
  218.  
  219.     // }}}
  220.     // {{{ abstract protected function startClass($name)
  221.  
  222.     /**
  223.     * Handler for 'start class' event.
  224.     *
  225.     * @param  string $name 
  226.     * @access public
  227.     * @abstract
  228.     */
  229.     abstract protected function startClass($name);
  230.  
  231.     // }}}
  232.     // {{{ abstract protected function onTest($name)
  233.  
  234.     /**
  235.     * Handler for 'on test' event.
  236.     *
  237.     * @param  string $name 
  238.     * @access public
  239.     * @abstract
  240.     */
  241.     abstract protected function onTest($name);
  242.  
  243.     // }}}
  244.     // {{{ abstract protected function endClass($name)
  245.  
  246.     /**
  247.     * Handler for 'end class' event.
  248.     *
  249.     * @param  string $name 
  250.     * @access public
  251.     * @abstract
  252.     */
  253.     abstract protected function endClass($name);
  254.  
  255.     // }}}
  256.     // {{{ abstract protected function startRun()
  257.  
  258.     /**
  259.     * Handler for 'start run' event.
  260.     *
  261.     * @access public
  262.     * @abstract
  263.     */
  264.     abstract protected function startRun();
  265.  
  266.     // }}}
  267.     // {{{ abstract protected function endRun()
  268.  
  269.     /**
  270.     * Handler for 'end run' event.
  271.     *
  272.     * @access public
  273.     * @abstract
  274.     */
  275.     abstract protected function endRun();
  276.  
  277.     // }}}
  278. }
  279.  
  280. /*
  281.  * vim600:  et sw=2 ts=2 fdm=marker
  282.  * vim<600: et sw=2 ts=2
  283.  */
  284. ?>

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