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

Source for file Default.php

Documentation is available at Default.php

  1. <?php
  2.  
  3. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  4.  
  5. /**
  6.  * This file is part of the PEAR Testing_DocTest package.
  7.  *
  8.  * PHP version 5
  9.  *
  10.  * LICENSE: This source file is subject to the MIT license that is available
  11.  * through the world-wide-web at the following URI:
  12.  * http://opensource.org/licenses/mit-license.php
  13.  *
  14.  * @category  Testing
  15.  * @package   Testing_DocTest
  16.  * @author    David JEAN LOUIS <izimobil@gmail.com>
  17.  * @copyright 2008 David JEAN LOUIS
  18.  * @license   http://opensource.org/licenses/mit-license.php MIT License
  19.  * @version   CVS: $Id$
  20.  * @link      http://pear.php.net/package/Testing_DocTest
  21.  * @since     File available since release 0.1.0
  22.  * @filesource
  23.  */
  24.  
  25. /**
  26.  * Required file
  27.  */
  28. require_once 'Testing/DocTest/OutputterInterface.php';
  29.  
  30. /**
  31.  * DocTest Outputter default class.
  32.  *
  33.  * @category  Testing
  34.  * @package   Testing_DocTest
  35.  * @author    David JEAN LOUIS <izimobil@gmail.com>
  36.  * @copyright 2008 David JEAN LOUIS
  37.  * @license   http://opensource.org/licenses/mit-license.php MIT License
  38.  * @version   Release: 0.3.0
  39.  * @link      http://pear.php.net/package/Testing_DocTest
  40.  * @since     Class available since release 0.1.0
  41.  */
  42. class Testing_DocTest_Outputter_Default implements Testing_DocTest_OutputterInterface
  43. {
  44.     // properties {{{
  45.  
  46.     /**
  47.      * Timer beginning time.
  48.      *
  49.      * @var float time
  50.      * @access private
  51.      */
  52.     private $_time = 0;
  53.  
  54.     /**
  55.      * Opened log file.
  56.      *
  57.      * @var resource $_logfile 
  58.      * @access private
  59.      */
  60.     private $_logfile = false;
  61.  
  62.     // }}}
  63.     // __construct() {{{
  64.  
  65.     /**
  66.      * Constructor.
  67.      *
  68.      * @access public
  69.      */
  70.     public function __construct()
  71.     {
  72.         $reg Testing_DocTest_Registry::singleton();
  73.         if ($reg->logfile{
  74.             $this->_logfile fopen($reg->logfile'wb');
  75.         }
  76.         $time        explode(' 'microtime());
  77.         $this->_time $time[1$time[0];
  78.     }
  79.  
  80.     // }}}
  81.     // __destruct() {{{
  82.  
  83.     /**
  84.      * Destructor.
  85.      * Will eventually close the opened logfile.
  86.      *
  87.      * @access public
  88.      */
  89.     public function __destruct()
  90.     {
  91.         if (false !== $this->_logfile && is_resource($this->_logfile)) {
  92.             fclose($this->_logfile);
  93.         }
  94.     }
  95.  
  96.     // }}}
  97.     // begin() {{{
  98.  
  99.     /**
  100.      * Begin of the DocTest session.
  101.      *
  102.      * @param array $files a multidimensional array of file=>testcase array
  103.      *
  104.      * @access public
  105.      * @return void 
  106.      */
  107.     public function begin(array $files)
  108.     {
  109.         if (empty($files)) {
  110.             $this->_output("Nothing to process.\n");
  111.         }
  112.     }
  113.  
  114.     // }}}
  115.     // end() {{{
  116.  
  117.     /**
  118.      * End of the DocTest session.
  119.      *
  120.      * @param array $files a multidimensional array of file=>testcase array
  121.      *
  122.      * @access public
  123.      * @return void 
  124.      */
  125.     public function end(array $files)
  126.     {
  127.         if (empty($files)) {
  128.             return;
  129.         }
  130.         $time   explode(' 'microtime());
  131.         $t      ($time[1$time[0]$this->_time;
  132.         $passed $skipped $failed $error = 0;
  133.         foreach ($files as $file=>$tbArray{
  134.             foreach ($tbArray as $tb{
  135.                 if ($tb->state == Testing_DocTest_TestCase::STATE_SKIPPED{
  136.                     $skipped++;
  137.                 else if (
  138.                     $tb->state == Testing_DocTest_TestCase::STATE_PASSED{
  139.                     $passed++;
  140.                 else {
  141.                     $failed++;
  142.                 }
  143.             }
  144.         }
  145.         $this->_output(sprintf("\nTotal time    : %.4f sec.\n"$t));
  146.         $this->_output("Passed tests  : $passed\n");
  147.         $this->_output("Skipped tests : $skipped\n");
  148.         $this->_output("Failed tests  : $failed\n\n");
  149.     }
  150.  
  151.     // }}}
  152.     // beginFile() {{{
  153.  
  154.     /**
  155.      * Begin of file parsing.
  156.      *
  157.      * @param string $file          path to the file that will be processed
  158.      * @param array  $testCaseArray an array of test case instances
  159.      *
  160.      * @access public
  161.      * @return void 
  162.      */
  163.     public function beginFile($filearray $testCaseArray)
  164.     {
  165.     }
  166.  
  167.     // }}}
  168.     // endFile() {{{
  169.  
  170.     /**
  171. /**
  172.      * End of file parsing.
  173.      *
  174.      * @param string $file          path to the file that will be processed
  175.      * @param array  $testCaseArray an array of test case instances
  176.      *
  177.      * @access public
  178.      * @return void 
  179.      */
  180.     public function endFile($filearray $testCaseArray)
  181.     {
  182.     }
  183.  
  184.     // }}}
  185.     // beginTestCase() {{{
  186.  
  187.     /**
  188. /**
  189.      * Begin of test case parsing.
  190.      *
  191.      * @param object $testCase a test case instance
  192.      *
  193.      * @access public
  194.      * @return void 
  195.      */
  196.     public function beginTestCase(Testing_DocTest_TestCase $testCase)
  197.     {
  198.     }
  199.  
  200.     // }}}
  201.     // endTestCase() {{{
  202.  
  203.     /**
  204.      * End of test case parsing.
  205.      *
  206.      * @param object $testCase a test case instance
  207.      *
  208.      * @access public
  209.      * @return void 
  210.      */
  211.     public function endTestCase(Testing_DocTest_TestCase $testCase)
  212.     {
  213.         $name sprintf("%s in file \"%s\"\n"
  214.             $testCase->name$testCase->file);
  215.         if ($testCase->state == Testing_DocTest_TestCase::STATE_SKIPPED{
  216.             $this->_output('[SKIP]  '33);
  217.             $this->_output($name);
  218.         else {
  219.             if ($testCase->state == Testing_DocTest_TestCase::STATE_PASSED{
  220.                 $this->_output('[PASS]  '32);
  221.                 $this->_output($name);
  222.             else {
  223.                 if ($testCase->state == Testing_DocTest_TestCase::STATE_ERROR{
  224.                     $this->_output('[ERROR] '31true);
  225.                 else {
  226.                     $this->_output('[FAIL]  '31true);
  227.                 }
  228.                 $this->_output($namefalsetrue);
  229.                 $this->_output(str_repeat('-'31" Expected " 
  230.                     . str_repeat('-'31"\n"falsetrue);
  231.                 $this->_output($testCase->expectedValue . "\n"falsetrue);
  232.                 $this->_output(str_repeat('-'31"  Actual  " 
  233.                     . str_repeat('-'31"\n"falsetrue);
  234.                 $this->_output($testCase->actualValue . "\n"falsetrue);
  235.                 $this->_output(str_repeat('-'72"\n"falsetrue);
  236.             }
  237.         }
  238.     }
  239.  
  240.     // }}}
  241.     // _output() {{{
  242.  
  243.     /**
  244.      * Writes the message $msg to STDOUT or to the logfile.
  245.      *
  246.      * @param string $msg   the message to output
  247.      * @param int    $color the color code (optional)
  248.      * @param bool   $force force output even if quiet mode
  249.      *
  250.      * @return void 
  251.      * @access private
  252.      */
  253.     private function _output($msg$color=false$force=false)
  254.     {
  255.         $reg Testing_DocTest_Registry::singleton();
  256.         if ($reg->quiet && !$force{
  257.             return;
  258.         }
  259.         if ($color && !$reg->no_colors && !$this->_logfile{
  260.             echo "\033[{$color}m" . $msg "\033[0;0m";
  261.         else {
  262.             if ($this->_logfile{
  263.                 fwrite($this->_logfile$msg);
  264.             else {
  265.                 echo $msg;
  266.             }
  267.         }
  268.     }
  269.  
  270.     // }}}
  271. }

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