Source for file colortext_reporter.php

Documentation is available at colortext_reporter.php

  1. <?php
  2.     /**
  3.      *  Base include file for SimpleTest
  4.      *  @package        SimpleTest
  5.      *  @subpackage     UnitTester
  6.      *  @version        $Id: colortext_reporter.php 1631 2008-01-20 14:31:16Z pp11 $
  7.      */
  8.  
  9. /**
  10.  * include base reporter
  11.  */
  12. require_once(dirname(__FILE__'/../reporter.php');
  13.  
  14.  
  15. /**
  16.  * Provides an ANSI-colored {@link TextReporter} for viewing test results.
  17.  *
  18.  * This code is made available under the same terms as SimpleTest.  It is based
  19.  * off of code that Jason Sweat originally published on the SimpleTest mailing
  20.  * list.
  21.  *
  22.  * @author Jason Sweat (original code)
  23.  * @author Travis Swicegood <development@domain51.com>
  24.  * @package SimpleTest
  25.  * @subpackage UnitTester
  26.  */
  27. class ColorTextReporter extends TextReporter 
  28.     var $_failColor = 41;
  29.     var $_passColor = 42;
  30.     
  31.     /**
  32.      * Handle initialization
  33.      *
  34.      * @param {@link TextReporter}
  35.      */
  36.     function ColorTextReporter({
  37.         parent::TextReporter();
  38.     }
  39.     
  40.     /**
  41.      * Capture the attempt to display the final test results and insert the
  42.      * ANSI-color codes in place.
  43.      *
  44.      * @param string 
  45.      * @see TextReporter
  46.      * @access public
  47.      */
  48.     function paintFooter($test_name{
  49.         ob_start();
  50.         parent::paintFooter($test_name);
  51.         $output trim(ob_get_clean());
  52.         if ($output{
  53.             if (($this->getFailCount($this->getExceptionCount()) == 0{
  54.                 $color $this->_passColor;
  55.             else {
  56.                 $color $this->_failColor;
  57.             }
  58.             
  59.             $this->_setColor($color);
  60.             echo $output;
  61.             $this->_resetColor();
  62.         }
  63.     }
  64.     
  65.     
  66.     /**
  67.      * Sets the terminal to an ANSI-standard $color
  68.      *
  69.      * @param int 
  70.      * @access protected
  71.      */
  72.     function _setColor($color{
  73.         printf("%s[%sm\n"chr(27)$color);
  74.     }
  75.     
  76.     
  77.     /**
  78.      * Resets the color back to normal.
  79.      *
  80.      * @access protected
  81.      */
  82.     function _resetColor({
  83.         $this->_setColor(0);
  84.     }
  85. }

Documentation generated on Sun, 04 May 2008 09:21:21 -0500 by phpDocumentor 1.3.0