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

Source for file Renderer.php

Documentation is available at Renderer.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: Renderer.php,v 1.12.2.1 2004/12/22 08:06:07 sebastian Exp $
  16. //
  17.  
  18. /**
  19.  * Abstract base class for Code Coverage renderers.
  20.  *
  21.  * @author      Sebastian Bergmann <sb@sebastian-bergmann.de>
  22.  * @copyright   Copyright &copy; 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>
  23.  * @license     http://www.php.net/license/3_0.txt The PHP License, Version 3.0
  24.  * @category    Testing
  25.  * @package     PHPUnit2
  26.  * @subpackage  Extensions
  27.  * @since       2.1.0
  28.  * @abstract
  29.  */
  30.     // {{{ Instance Variables
  31.  
  32.     /**
  33.     * @var    array 
  34.     * @access protected
  35.     */
  36.     protected $codeCoverageInformation;
  37.  
  38.     /**
  39.     * @var    boolean 
  40.     * @access protected
  41.     */
  42.     protected $useSummary = TRUE;
  43.  
  44.     // }}}
  45.     // {{{ protected function __construct($codeCoverageInformation)
  46.  
  47.     /**
  48.     * Constructor.
  49.     *
  50.     * @param  array $codeCoverageInformation 
  51.     * @access protected
  52.     */
  53.     protected function __construct($codeCoverageInformation{
  54.         $this->codeCoverageInformation = $codeCoverageInformation;
  55.     }
  56.  
  57.     // }}}
  58.     // {{{ public function factory($rendererName, $codeCoverageInformation)
  59.  
  60.     /**
  61.     * Abstract Factory.
  62.     *
  63.     * @param  string  $rendererName 
  64.     * @param  array   $codeCoverageInformation 
  65.     * @access public
  66.     */
  67.     public function factory($rendererName$codeCoverageInformation{
  68.         $class 'PHPUnit2_Extensions_CodeCoverage_Renderer_' $rendererName;
  69.  
  70.         @require_once 'PHPUnit2/Extensions/CodeCoverage/Renderer/' $rendererName '.php';
  71.  
  72.         if (class_exists($class)) {
  73.             return new $class($codeCoverageInformation);
  74.         else {
  75.             throw new Exception(
  76.               sprintf(
  77.                 'Could not load class %s.',
  78.                 $class
  79.               )
  80.             );
  81.         }
  82.     }
  83.  
  84.     // }}}
  85.     // {{{ public final function render()
  86.  
  87.     /**
  88.     * Visualizes the result array of
  89.     * PHPUnit2_Framework_TestResult::getCodeCoverageInformation().
  90.     *
  91.     * @return string 
  92.     * @access public
  93.     * @final
  94.     */
  95.     public final function render({
  96.         $buffer $this->header();
  97.  
  98.         if ($this->useSummary{
  99.             foreach ($this->getSummary(as $sourceFile => $executedLines{
  100.                 $buffer .= $this->startSourceFile($sourceFile);
  101.                 $buffer .= $this->renderSourceFile(file($sourceFile)$executedLines);
  102.                 $buffer .= $this->endSourceFile($sourceFile);
  103.             }
  104.         else {
  105.         }
  106.  
  107.         return $buffer $this->footer();
  108.     }
  109.  
  110.     // }}}
  111.     // {{{ public function renderToFile($filename)
  112.  
  113.     /**
  114.     * Visualizes the result array of
  115.     * PHPUnit2_Framework_TestResult::getCodeCoverageInformation()
  116.     * and writes it to a file.
  117.     *
  118.     * @param  string $filename 
  119.     * @access public
  120.     * @since  2.2.0
  121.     */
  122.     public function renderToFile($filename{
  123.         if ($fp fopen($filename'w')) {
  124.             fputs(
  125.               $fp,
  126.               $this->render()
  127.             );
  128.  
  129.             fclose($fp);
  130.         }
  131.     }
  132.  
  133.     // }}}
  134.     // {{{ protected function getSummary()
  135.  
  136.     /**
  137.     * Returns summarized Code Coverage data.
  138.     *
  139.     * Format of the result array:
  140.     *
  141.     * <code>
  142.     * array(
  143.     *   "/tested/code.php" => array(
  144.     *     linenumber => flag
  145.     *   )
  146.     * )
  147.     * </code>
  148.     *
  149.     * flag > 1: line was executed.
  150.     * flag < 1: line is executable but was not executed.
  151.     *
  152.     * @return array 
  153.     * @access protected
  154.     * @since  2.2.0
  155.     */
  156.     protected function getSummary({
  157.         $summary = array();
  158.  
  159.         foreach ($this->codeCoverageInformation as $testCaseName => $sourceFiles{
  160.             foreach ($sourceFiles as $sourceFile => $executedLines{
  161.                 foreach ($executedLines as $lineNumber => $flag{
  162.                     if (!isset($summary[$sourceFile][$lineNumber])) {
  163.                         $summary[$sourceFile][$lineNumber$flag;
  164.                     }
  165.  
  166.                     else if ($flag > 0{
  167.                         $summary[$sourceFile][$lineNumber$flag;
  168.                     }
  169.                 }
  170.             }
  171.         }
  172.  
  173.         return $summary;
  174.     }
  175.  
  176.     // }}}
  177.     // {{{ protected function header()
  178.  
  179.     /**
  180.     * @return string 
  181.     * @access protected
  182.     * @since  2.1.1
  183.     */
  184.     protected function header({
  185.     }
  186.  
  187.     // }}}
  188.     // {{{ protected function footer()
  189.  
  190.     /**
  191.     * @return string 
  192.     * @access protected
  193.     * @since  2.1.1
  194.     */
  195.     protected function footer({
  196.     }
  197.  
  198.     // }}}
  199.     // {{{ protected function startSourceFile($sourceFile)
  200.  
  201.     /**
  202.     * @param  string $sourceFile 
  203.     * @return string 
  204.     * @access protected
  205.     */
  206.     protected function startSourceFile($sourceFile{
  207.     }
  208.  
  209.     // }}}
  210.     // {{{ protected function endSourceFile($sourceFile)
  211.  
  212.     /**
  213.     * @param  string $sourceFile 
  214.     * @return string 
  215.     * @access protected
  216.     */
  217.     protected function endSourceFile($sourceFile{
  218.     }
  219.  
  220.     // }}}
  221.     // {{{ abstract protected function renderSourceFile($codeLines, $executedLines)
  222.  
  223.     /**
  224.     * @param  array $codeLines 
  225.     * @param  array $executedLines 
  226.     * @return string 
  227.     * @access protected
  228.     * @abstract
  229.     */
  230.     abstract protected function renderSourceFile($codeLines$executedLines);
  231.  
  232.     // }}}
  233. }
  234.  
  235. /*
  236.  * vim600:  et sw=2 ts=2 fdm=marker
  237.  * vim<600: et sw=2 ts=2
  238.  */
  239. ?>

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