Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7170661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:15:26+00:00 2026-05-28T15:15:26+00:00

PHP_CodeCoverage 1.1 removed the singleton accessor for PHP_CodeCoverage_Filter that allowed our PHPUnit bootstrap.php files

  • 0

PHP_CodeCoverage 1.1 removed the singleton accessor for PHP_CodeCoverage_Filter that allowed our PHPUnit bootstrap.php files to add directories to the white/blacklists. PHPUnit 3.5 used the blacklist to strip classes from exception stack traces, and CC uses the whitelist to limit tracking. We used both of these features.

How can I get the PHP_CodeCoverage_Filter instance that PHPUnit will use from the bootstrap.php file?

Note: We cannot put these into phpunit.xml because the paths are built from environment variables and config files.

Update: I see that PHPUnit_Util_Filter no longer uses the code coverage blacklist for filtering stack traces. This is fine, and since this class is designed for static access I could add a method to add user directories to the list. It would be an easy change and solve half of this question.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T15:15:27+00:00Added an answer on May 28, 2026 at 3:15 pm

    This is an ugly hack, but it works in PHPUnit 3.6. We already have our own custom test case base class that all others extend. If it doesn’t matter when the files get added to the whitelist you could do this using a fake test case just to handle this part.

    First, bootstrap.php calls BaseTestCase::addXXXToCodeCoverageWhitelist() as many times as necessary to populate an internal array of files to add later. Next, the first test to be executed adds those files to the code coverage filter via the TestResult.

    abstract class BaseTestCase extends PHPUnit_Framework_TestCase
    {
        private static $_codeCoverageFiles = array();
    
        public static function addDirectoryToCodeCoverageWhitelist($path) {
            self::addFilesToCodeCoverageWhitelist(self::getFilesForDirectory($path));
        }
    
        public static function addFileToCodeCoverageWhitelist($path) {
            self::addFilesToCodeCoverageWhitelist(array($path));
        }
    
        public static function addFilesToCodeCoverageWhitelist(array $paths) {
            self::$_codeCoverageFiles = array_merge(self::$_codeCoverageFiles, $paths);
        }
    
        public static function getFilesForDirectory($path) {
            $facade = new File_Iterator_Facade;
            return $facade->getFilesAsArray($path, '.php');
        }
    
        private static function setCodeCoverageWhitelist(PHP_CodeCoverage $coverage = null) {
            if ($coverage && self::$_codeCoverageFiles) {
                $coverage->setProcessUncoveredFilesFromWhitelist(true); // pick your poison
                $coverage->filter()->addFilesToWhitelist(self::$_codeCoverageFiles);
                self::$_codeCoverageFiles = array();
            }
        }
    
        public function runBare() {
            self::setCodeCoverageWhitelist($this->getTestResultObject()->getCodeCoverage());
            parent::runBare();
        }
    }
    

    Update: For anyone that used the blacklist to keep framework classes from showing up in assertion failure stack traces as we did, add the following methods to the above class and call them from your bootstrap.php. This requires setAccessible() from PHP 5.3.

        public static function ignoreDirectoryInStackTraces($path) {
            ignoreFilesInStackTraces(self::getFilesForDirectory($path));
        }
    
        public static function ignoreFileInStackTraces($path) {
            ignoreFilesInStackTraces(array($path));
        }
    
        public static function ignoreFilesInStackTraces($files) {
            static $reflector = null;
            if (!$reflector) {
                PHPUnit_Util_GlobalState::phpunitFiles();
                $reflector = new ReflectionProperty('PHPUnit_Util_GlobalState', 'phpunitFiles');
                $reflector->setAccessible(true);
            }
            $map = $reflector->getValue();
            foreach ($files as $file) {
                $map[$file] = $file;
            }
            $reflector->setValue($map);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In our project, we are running PHPUnit tests that uses Selenium and Curl to
General Info: PHP 5.3.3 PHPUnit 3.4 Zend Framework 1.10.8 Phing build target <target name=test>
php curl is reading style(css) files and downloading gifs,jpegs,pngs and everything. so curl is
In php, is there a tool that can generate a code coverage report without
PHP imap_sort has an undocumented $search_criteria parameter. I'm writing a little script that should
I'm using PHPUnit 3.6.7, PHP_CodeCoverage 1.1.1, and Xdebug 2.1.2. When I have PHPUnit write
PHP creates files with apache:apache ownership which seems to be causing issues with other
Is there any code coverage tool available for PHP? I wish to check the
PHP has a great function called htmlspecialcharacters() where you pass it a string and
PHP's explode function returns an array of strings split on some provided substring. It

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.