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

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