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

[Performance] Add files to coverage whitelist instead of the whole directories when --filter or --git-diff-filter are used #1543

Merged
merged 3 commits into from Aug 5, 2021

Commits on Aug 4, 2021

  1. Performance improvement: add files to coverage whitelist instead of t…

    …he whole directories when `--filter` or `--git-diff-filter` are used
    
    Currently, when we build the initial tests `phpunit.xml` config, we add (if doesn't exist) the following coverage whitelist:
    
    ```xml
    <phpunit>
        <coverage>
            <include>
                <directory>src/</directory>
                <directory>example/</directory>
            </include>
        </coverage>
    </phpunit>
    ```
    
    It means that **all** the files from directories `src/` and `example/` will be processed by coverage driver (be it `xdebug`, `pcov` or `phpdbg`
    ).
    
    Collecting code coverage costs a lot, that's why this change tries to reduce the number of files added to coverage whitelist, replacing `<directory>` tag with N `<file>` tags if possible.
    
    And one of the case is when we use `--filter=src/path/to/File1.php,src/path/to/File2.php` option, or when we use `--git-diff-filter=AM` option, that results internally to `--filter=X,Y,Z`.
    
    When the filter is used, we 100% know that we will mutate only particular files, so we need the code coverage only for them.
    
    Result initial `phpunit.xml` file will be like this:
    
    ```
    infection --filter=src/path/to/File1.php,src/path/to/File2.php
    ```
    
    ```xml
    <phpunit>
        <coverage>
            <include>
                <file>src/path/to/File1.php/</file>
                <file>src/path/to/File2.php/</file>
            </include>
        </coverage>
    </phpunit>
    ```
    
    This will dramatically decrease the time needed for collecting coverage data since we reduce the number of processed files.
    maks-rafalko committed Aug 4, 2021
    Configuration menu
    Copy the full SHA
    83523a9 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    3f04813 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    a615d7c View commit details
    Browse the repository at this point in the history