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 :: PHPUnit2                                                       |
  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.8.2.1 2004/10/01 06:11:54 sebastian Exp $
  16. //
  17.  
  18. require_once 'PHPUnit2/Framework/TestFailure.php';
  19. require_once 'PHPUnit2/Framework/TestListener.php';
  20. require_once 'PHPUnit2/Framework/TestResult.php';
  21. require_once 'PHPUnit2/Util/Filter.php';
  22. require_once 'PHPUnit2/Util/Printer.php';
  23.  
  24. /**
  25.  * @author      Sebastian Bergmann <sb@sebastian-bergmann.de>
  26.  * @copyright   Copyright &copy; 2002-2004 Sebastian Bergmann <sb@sebastian-bergmann.de>
  27.  * @license     http://www.php.net/license/3_0.txt The PHP License, Version 3.0
  28.  * @category    Testing
  29.  * @package     PHPUnit2
  30.  * @subpackage  TextUI
  31.  */
  32.     // {{{ Members
  33.  
  34.     /**
  35.     * @var    integer 
  36.     * @access private
  37.     */
  38.     private $column = 0;
  39.  
  40.     /**
  41.     * @var    boolean 
  42.     * @access private
  43.     */
  44.     private $lastTestFailed = false;
  45.  
  46.     // }}}
  47.     // {{{ public function printResult(PHPUnit2_Framework_TestResult $result, $timeElapsed)
  48.  
  49.     /**
  50.     * @param  PHPUnit2_Framework_TestResult $result 
  51.     * @param  float                         $runTime 
  52.     * @access public
  53.     */
  54.     public function printResult(PHPUnit2_Framework_TestResult $result$timeElapsed{
  55.         $this->printHeader($timeElapsed);
  56.         $this->printErrors($result);
  57.         $this->printFailures($result);
  58.         $this->printIncompletes($result);
  59.         $this->printFooter($result);
  60.     }
  61.  
  62.     // }}}
  63.     // {{{ protected function printDefects($defects, $count, $type)
  64.  
  65.     /**
  66.     * @param  array   $defects 
  67.     * @param  integer $count 
  68.     * @param  string  $type 
  69.     * @access protected
  70.     */
  71.     protected function printDefects($defects$count$type{
  72.         if ($count == 0{
  73.             return;
  74.         }
  75.  
  76.         $this->write(
  77.           sprintf(
  78.             "There %s %d %s%s:\n",
  79.  
  80.             ($count == 1'was' 'were',
  81.             $count,
  82.             $type,
  83.             ($count == 1'' 's'
  84.           )
  85.         );
  86.  
  87.         $i = 1;
  88.  
  89.         foreach ($defects as $defect{
  90.             $this->printDefect($defect$i++);
  91.         }
  92.     }
  93.  
  94.     // }}}
  95.     // {{{ protected function printDefect(PHPUnit2_Framework_TestFailure $defect, $count)
  96.  
  97.     /**
  98.     * @param  PHPUnit2_Framework_TestFailure $defect 
  99.     * @param  integer                        $count 
  100.     * @access protected
  101.     */
  102.     protected function printDefect(PHPUnit2_Framework_TestFailure $defect$count{
  103.         $this->printDefectHeader($defect$count);
  104.         $this->printDefectTrace($defect);
  105.     }
  106.  
  107.     // }}}
  108.     // {{{ protected function printDefectHeader(PHPUnit2_Framework_TestFailure $defect, $count)
  109.  
  110.     /**
  111.     * @param  PHPUnit2_Framework_TestFailure $defect 
  112.     * @param  integer                        $count 
  113.     * @access protected
  114.     */
  115.     protected function printDefectHeader(PHPUnit2_Framework_TestFailure $defect$count{
  116.         $name $defect->failedTest()->getName();
  117.  
  118.         if ($name === NULL{
  119.             $class = new ReflectionClass($defect->failedTest());
  120.             $name  $class->name;
  121.         }
  122.  
  123.         $this->write(
  124.           sprintf(
  125.             "%d) %s\n",
  126.  
  127.             $count,
  128.             $name
  129.           )
  130.         );
  131.     }
  132.  
  133.     // }}}
  134.     // {{{ protected function printDefectTrace(PHPUnit2_Framework_TestFailure $defect)
  135.  
  136.     /**
  137.     * @param  PHPUnit2_Framework_TestFailure $defect 
  138.     * @access protected
  139.     */
  140.     protected function printDefectTrace(PHPUnit2_Framework_TestFailure $defect{
  141.         $e       $defect->thrownException();
  142.         $message method_exists($e'toString'$e->toString($e->getMessage();
  143.  
  144.         $this->write($message "\n");
  145.  
  146.         $this->write(
  147.             $defect->thrownException()
  148.           )
  149.         );
  150.     }
  151.  
  152.     // }}}
  153.     // {{{ protected function printErrors(PHPUnit2_Framework_TestResult $result)
  154.  
  155.     /**
  156.     * @param  PHPUnit2_Framework_TestResult  $result 
  157.     * @access protected
  158.     */
  159.     protected function printErrors(PHPUnit2_Framework_TestResult $result{
  160.         $this->printDefects($result->errors()$result->errorCount()'error');
  161.     }
  162.  
  163.     // }}}
  164.     // {{{ protected function printFailures(PHPUnit2_Framework_TestResult $result)
  165.  
  166.     /**
  167.     * @param  PHPUnit2_Framework_TestResult  $result 
  168.     * @access protected
  169.     */
  170.     protected function printFailures(PHPUnit2_Framework_TestResult $result{
  171.         $this->printDefects($result->failures()$result->failureCount()'failure');
  172.     }
  173.  
  174.     // }}}
  175.     // {{{ protected function printIncompletes(PHPUnit2_Framework_TestResult $result)
  176.  
  177.     /**
  178.     * @param  PHPUnit2_Framework_TestResult  $result 
  179.     * @access protected
  180.     */
  181.     protected function printIncompletes(PHPUnit2_Framework_TestResult $result{
  182.         $this->printDefects($result->notImplemented()$result->notImplementedCount()'incomplete testcase');
  183.     }
  184.  
  185.     // }}}
  186.     // {{{ protected function printHeader($timeElapsed)
  187.  
  188.     /**
  189.     * @param  float   $timeElapsed 
  190.     * @access protected
  191.     */
  192.     protected function printHeader($timeElapsed{
  193.         $this->write(
  194.           sprintf(
  195.             "\n\nTime: %s\n",
  196.  
  197.             $timeElapsed
  198.           )
  199.         );
  200.     }
  201.  
  202.     // }}}
  203.     // {{{ protected function printFooter(PHPUnit2_Framework_TestResult $result)
  204.  
  205.     /**
  206.     * @param  PHPUnit2_Framework_TestResult  $result 
  207.     * @access protected
  208.     */
  209.     protected function printFooter(PHPUnit2_Framework_TestResult $result{
  210.         if ($result->allCompletlyImplemented(&&
  211.             $result->wasSuccessful()) {
  212.             $this->write(
  213.               sprintf(
  214.                 "\nOK (%d test%s)\n",
  215.  
  216.                 $result->runCount(),
  217.                 ($result->runCount(== 1'' 's'
  218.               )
  219.             );
  220.         }
  221.         
  222.         else if (!$result->allCompletlyImplemented(&&
  223.                  $result->wasSuccessful()) {
  224.             $this->write(
  225.               sprintf(
  226.                 "\nOK, but incomplete test cases!!!\nTests run: %d, incomplete test cases: %d.\n",
  227.  
  228.                 $result->runCount(),
  229.                 $result->notImplementedCount()
  230.               )
  231.             );
  232.         }        
  233.         
  234.         else {
  235.             $this->write(
  236.               sprintf(
  237.                 "\nFAILURES!!!\nTests run: %d, Failures: %d, Errors: %d, Incomplete Tests: %d.\n",
  238.  
  239.                 $result->runCount(),
  240.                 $result->failureCount(),
  241.                 $result->errorCount(),
  242.                 $result->notImplementedCount()
  243.               )
  244.             );
  245.         }
  246.     }
  247.  
  248.     // }}}
  249.     // {{{ public function printWaitPrompt()
  250.  
  251.     /**
  252.     * @access public
  253.     */
  254.     public function printWaitPrompt({
  255.         $this->write("\n<RETURN> to continue\n");
  256.     }
  257.  
  258.     // }}}
  259.     // {{{ public function addError(PHPUnit2_Framework_Test $test, Exception $e)
  260.  
  261.     /**
  262.     * An error occurred.
  263.     *
  264.     * @param  PHPUnit2_Framework_Test $test 
  265.     * @param  Exception               $e 
  266.     * @access public
  267.     */
  268.     public function addError(PHPUnit2_Framework_Test $testException $e{
  269.         $this->write('E');
  270.         $this->nextColumn();
  271.  
  272.         $this->lastTestFailed = true;
  273.     }
  274.  
  275.     // }}}
  276.     // {{{ public function addFailure(PHPUnit2_Framework_Test $test, PHPUnit2_Framework_AssertionFailedError $e)
  277.  
  278.     /**
  279.     * A failure occurred.
  280.     *
  281.     * @param  PHPUnit2_Framework_Test                 $test 
  282.     * @param  PHPUnit2_Framework_AssertionFailedError $e 
  283.     * @access public
  284.     */
  285.     public function addFailure(PHPUnit2_Framework_Test $testPHPUnit2_Framework_AssertionFailedError $e{
  286.         $this->write('F');
  287.         $this->nextColumn();
  288.  
  289.         $this->lastTestFailed = true;
  290.     }
  291.  
  292.     // }}}
  293.     // {{{ public function addIncompleteTest(PHPUnit2_Framework_Test $test, Exception $e)
  294.  
  295.     /**
  296.     * Incomplete test.
  297.     *
  298.     * @param  PHPUnit2_Framework_Test $test 
  299.     * @param  Exception               $e 
  300.     * @access public
  301.     */
  302.     public function addIncompleteTest(PHPUnit2_Framework_Test $testException $e{
  303.         $this->write('I');
  304.         $this->nextColumn();
  305.  
  306.         $this->lastTestFailed = true;
  307.     }
  308.  
  309.     // }}}
  310.     // {{{ public function endTest(PHPUnit2_Framework_Test $test)
  311.  
  312.     /**
  313.     * A test ended.
  314.     *
  315.     * @param  PHPUnit2_Framework_Test $test 
  316.     * @access public
  317.     */
  318.     public function endTest(PHPUnit2_Framework_Test $test{
  319.         if (!$this->lastTestFailed{
  320.             $this->write('.');
  321.             $this->nextColumn();
  322.         }
  323.  
  324.         $this->lastTestFailed = false;
  325.     }
  326.  
  327.     // }}}
  328.     // {{{ public function startTest(PHPUnit2_Framework_Test $test)
  329.  
  330.     /**
  331.     * A test started.
  332.     *
  333.     * @param  PHPUnit2_Framework_Test $test 
  334.     * @access public
  335.     */
  336.     public function startTest(PHPUnit2_Framework_Test $test{
  337.     }
  338.  
  339.     // }}}
  340.     // {{{ private function nextColumn()
  341.  
  342.     /**
  343.     * @access private
  344.     */
  345.     private function nextColumn({
  346.         if ($this->column++ >= 40{
  347.             $this->column = 0;
  348.             $this->write("\n");
  349.         }
  350.     }
  351.  
  352.     // }}}
  353. }
  354.  
  355. /*
  356.  * vim600:  et sw=2 ts=2 fdm=marker
  357.  * vim<600: et sw=2 ts=2
  358.  */
  359. ?>

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