Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to generate code coverage whitelist filter script for Xdebug #3272

sebastianbergmann opened this issue Sep 7, 2018 · 1 comment
type/enhancement A new idea that should be implemented


Copy link

sebastianbergmann commented Sep 7, 2018

PHPUnit (or rather php-code-coverage currently lets Xdebug collect all code coverage information and then filters it itself (in PHP code) based on the configured whitelist. Delegating this filter operation to Xdebug (where it's implemented in C) would lead to significant improvements in resource consumption.

In Xdebug 2.6, @derickr added filter capabilities to tracing, stack traces, and code coverage. Xdebug's filter must be configured, though, before any of the sourcecode files that are to be filtered are loaded. This means that leveraging this new feature of Xdebug for PHPUnit is not as simple as originally anticipated.

This ticket proposes the addition of a new command-line option to PHPUnit, --dump-xdebug-filter, that instructs PHPUnit to load the phpunit.xml configuration file for a project and dump the configured whitelist to a PHP script. This PHP script contains the code to configure Xdebug's whitelist. It needs to be loaded as early as possible to have an impact on code coverage related resource consumption. Early experience shows that it is for many scenarios already "good enough" to use this generated script as (part of) the PHPUnit bootstrap script (--bootstrap, bootstrap= in phpunit.xml).

Using the PHP script generated by the new command-line option proposed above will not prevent php-code-coverage from applying the same whitelist a second time. However, a performance improvement can still be observed. A next step could be to not perform the whitelist filtering in php-code-coverage when it has already been performed by Xdebug.

@sebastianbergmann sebastianbergmann added the type/enhancement A new idea that should be implemented label Sep 7, 2018
@sebastianbergmann sebastianbergmann added this to the PHPUnit 7.4 milestone Sep 7, 2018
sebastianbergmann pushed a commit that referenced this issue Sep 8, 2018
This adds the new CLI option --dump-xdebug-filter which will generate a PHP
script that can be used to set a whitelist filter for XDebug's code coverage
collector in order to speed up test runs.

The whitelist is based on the filter configuration in PHPUnit's XML
configuration. If the configuration only contains includes for files and
directories without prefixes and suffixes other than '.php', the XDebug script
will contain the same whitelist items.

If, however, the filter configuration is more complex, the XDebug script will
contain the resolved list of files, which will have a negative impact on
Copy link
Owner Author

Thanks, @belanur!

sebastianbergmann pushed a commit that referenced this issue Sep 8, 2018
XDebugFilterScriptGenerator now completely ignores the <exclude>
part of the filter configuration and always creates the script
based on the whitelist only. Letting PHPUnit filter out the
excluded paths proved to be much faster than providing a long
list of individual files to xdebug_set_filter().
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
type/enhancement A new idea that should be implemented
None yet

No branches or pull requests

1 participant