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

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