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.
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.phpcalls 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 theTestResult.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 requiressetAccessible()from PHP 5.3.