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

Source for file Filter.php

Documentation is available at Filter.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: Filter.php,v 1.15.2.6 2004/10/30 19:46:08 sebastian Exp $
  16. //
  17.  
  18. /**
  19.  * Utility class for code filtering.
  20.  *
  21.  * @author      Sebastian Bergmann <sb@sebastian-bergmann.de>
  22.  * @copyright   Copyright &copy; 2002-2004 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  Util
  27.  */
  28.     // {{{ Members
  29.  
  30.     /**
  31.     * Source files that are to be filtered.
  32.     *
  33.     * @var    array 
  34.     * @access protected
  35.     * @static
  36.     */
  37.     protected static $filteredFiles = array(
  38.       'PHPUnit2/Extensions/CodeCoverage/Renderer/HTML.php',
  39.       'PHPUnit2/Extensions/CodeCoverage/Renderer/Text.php',
  40.       'PHPUnit2/Extensions/CodeCoverage/Renderer.php',
  41.       'PHPUnit2/Extensions/TestDox/ResultPrinter/HTML.php',
  42.       'PHPUnit2/Extensions/TestDox/ResultPrinter/Text.php',
  43.       'PHPUnit2/Extensions/TestDox/NamePrettifier.php',
  44.       'PHPUnit2/Extensions/TestDox/ResultPrinter.php',
  45.       'PHPUnit2/Extensions/ExceptionTestCase.php',
  46.       'PHPUnit2/Extensions/PerformanceTestCase.php',
  47.       'PHPUnit2/Extensions/RepeatedTest.php',
  48.       'PHPUnit2/Extensions/TestDecorator.php',
  49.       'PHPUnit2/Extensions/TestSetup.php',
  50.       'PHPUnit2/Extensions/Log/PEAR.php',
  51.       'PHPUnit2/Extensions/Log/XML.php',
  52.       'PHPUnit2/Framework/Assert.php',
  53.       'PHPUnit2/Framework/AssertionFailedError.php',
  54.       'PHPUnit2/Framework/ComparisonFailure.php',
  55.       'PHPUnit2/Framework/IncompleteTest.php',
  56.       'PHPUnit2/Framework/IncompleteTestError.php',
  57.       'PHPUnit2/Framework/Test.php',
  58.       'PHPUnit2/Framework/TestCase.php',
  59.       'PHPUnit2/Framework/TestFailure.php',
  60.       'PHPUnit2/Framework/TestListener.php',
  61.       'PHPUnit2/Framework/TestResult.php',
  62.       'PHPUnit2/Framework/TestSuite.php',
  63.       'PHPUnit2/Framework/Warning.php',
  64.       'PHPUnit2/Runner/BaseTestRunner.php',
  65.       'PHPUnit2/Runner/IncludePathTestCollector.php',
  66.       'PHPUnit2/Runner/StandardTestSuiteLoader.php',
  67.       'PHPUnit2/Runner/TestCollector.php',
  68.       'PHPUnit2/Runner/TestRunListener.php',
  69.       'PHPUnit2/Runner/TestSuiteLoader.php',
  70.       'PHPUnit2/Runner/Version.php',
  71.       'PHPUnit2/TextUI/ResultPrinter.php',
  72.       'PHPUnit2/TextUI/TestRunner.php',
  73.       'PHPUnit2/Util/Filter.php',
  74.       'PHPUnit2/Util/Printer.php',
  75.       'PHPUnit2/Util/Skeleton.php',
  76.       'Benchmark/Timer.php',
  77.       'Console/Getopt.php',
  78.       'Log/composite.php',
  79.       'Log/console.php',
  80.       'Log/display.php',
  81.       'Log/error.php',
  82.       'Log/file.php',
  83.       'Log/mail.php',
  84.       'Log/mcal.php',
  85.       'Log/null.php',
  86.       'Log/observer.php',
  87.       'Log/sql.php',
  88.       'Log/sqlite.php',
  89.       'Log/syslog.php',
  90.       'Log/win.php',
  91.       'Log.php',
  92.       'PEAR.php'
  93.     );
  94.  
  95.     // }}}
  96.     // {{{ public static function addFileToFilter($filename)
  97.  
  98.     /**
  99.     * Adds a new file to be filtered.
  100.     *
  101.     * @param  string 
  102.     * @access public
  103.     * @static
  104.     * @since  2.1.0
  105.     */
  106.     public static function addFileToFilter($filename{
  107.         $filename = self::getCanonicalFilename($filename);
  108.  
  109.         if (!self::isFiltered($filename)) {
  110.             self::$filteredFiles[$filename;
  111.         }
  112.     }
  113.  
  114.     // }}}
  115.     // {{{ public static function removeFileFromFilter($filename)
  116.  
  117.     /**
  118.     * Removes a file from the filter.
  119.     *
  120.     * @param  string 
  121.     * @access public
  122.     * @static
  123.     * @since  2.1.0
  124.     */
  125.     public static function removeFileFromFilter($filename{
  126.         $filename = self::getCanonicalFilename($filename);
  127.         $keys     array_keys(self::$filteredFiles);
  128.  
  129.         for ($i = 0; $i < sizeof($keys)$i++{
  130.             if (self::$filteredFiles[$keys[$i]] == $filename{
  131.                 unset(self::$filteredFiles[$keys[$i]]);
  132.                 break;
  133.             }
  134.         }
  135.     }
  136.  
  137.     // }}}
  138.     // {{{ public static function getFilteredCodeCoverage($codeCoverageInformation)
  139.  
  140.     /**
  141.     * Filters source lines from PHPUnit classes.
  142.     *
  143.     * @param  array 
  144.     * @return array 
  145.     * @access public
  146.     * @static
  147.     */
  148.     public static function getFilteredCodeCoverage($codeCoverageInformation{
  149.         $files = array_keys($codeCoverageInformation);
  150.  
  151.         foreach ($files as $file{
  152.             if (self::isFiltered($file)) {
  153.                 unset($codeCoverageInformation[$file]);
  154.             }
  155.         }
  156.  
  157.         return $codeCoverageInformation;
  158.     }
  159.  
  160.     // }}}
  161.     // {{{ public static function getFilteredStacktrace(Exception $e)
  162.  
  163.     /**
  164.     * Filters stack frames from PHPUnit classes.
  165.     *
  166.     * @param  Exception $e 
  167.     * @return string 
  168.     * @access public
  169.     * @static
  170.     */
  171.     public static function getFilteredStacktrace(Exception $e{
  172.         $filteredStacktrace '';
  173.         $stacktrace         $e->getTrace();
  174.  
  175.         foreach ($stacktrace as $frame{
  176.             $filtered = FALSE;
  177.  
  178.             if (isset($frame['file']&& !self::isFiltered($frame['file'])) {
  179.                 $filteredStacktrace .= sprintf(
  180.                   "%s:%s\n",
  181.  
  182.                   $frame['file'],
  183.                   isset($frame['line']$frame['line''?'
  184.                 );
  185.             }
  186.         }
  187.  
  188.         return $filteredStacktrace;
  189.     }
  190.  
  191.     // }}}
  192.     // {{{ protected static function getCanonicalFilename($filename)
  193.  
  194.     /**
  195.     * Canonicalizes a source file name.
  196.     *
  197.     * @param  string $filename 
  198.     * @return string 
  199.     * @access public
  200.     * @static
  201.     */
  202.     protected static function getCanonicalFilename($filename{
  203.         foreach (array('PHPUnit2''Benchmark''Console''PEAR'as $package{
  204.             $pos strpos($filename$package);
  205.  
  206.             if ($pos !== FALSE{
  207.                 $filename substr($filename$pos);
  208.                 break;
  209.             }
  210.         }
  211.  
  212.         return str_replace(
  213.           '\\',
  214.           '/',
  215.           $filename
  216.         );
  217.     }
  218.  
  219.     // }}}
  220.     // {{{ protected static function isFiltered($filename)
  221.  
  222.     /**
  223.     * @param  string $filename 
  224.     * @return boolean 
  225.     * @access public
  226.     * @static
  227.     * @since  2.1.3
  228.     */
  229.     protected static function isFiltered($filename{
  230.         if (substr($filename-7== 'phpunit' ||
  231.             in_array(self::getCanonicalFilename($filename)self::$filteredFiles)) {
  232.             return TRUE;
  233.         }
  234.  
  235.         return FALSE;
  236.     }
  237.  
  238.     // }}}
  239. }
  240.  
  241. /*
  242.  * vim600:  et sw=2 ts=2 fdm=marker
  243.  * vim<600: et sw=2 ts=2
  244.  */
  245. ?>

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