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

Tests: allow for recording code coverage + add @covers tags #2225

Merged
merged 3 commits into from
Apr 18, 2023

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Apr 17, 2023

Tests: allow for recording code coverage + add @covers tags

... to all unit test files, as well as enable strict coverage recording.

Includes:

  • PHPUnit config: add code coverage configuration.
    By default, when there is a code coverage configuration and Xdebug is enabled, code coverage will be generated.
    Note: generating code coverage is slow.
  • Git ignore the build directory as created by PHPUnit to store the log files (as set up in the config file).
  • Composer: add coverage script and adjust the test script.
    • When running the "normal" run-tests, no code coverage will be created.
    • To run the tests with code coverage, the new coverage script has been added.

When running PHPUnit locally, I'd recommend copying the phpunit.xml.dist file to phpunit.xml and replacing the clover logging with the following to allow for locally using the HTML report:

        <log type="coverage-html" target="./build/coverage-html/"/>

Note: this commit does not set up code coverage checking for PRs via an external service like Coveralls or CodeCov, though I imagine we could set this up in the future as the WP organisation already has a CodeCov account (we'd need to check if we can or need permission).

Tests: add @covers tags for Helpers

As the Helpers in WPCS do not have dedicated tests, but are tested via the sniffs using them, I'm adding @covers tags for these to select sniffs.

At a later point in time, we can revisit whether or not to add dedicated tests for the Helpers.

Tests: add @covers tags for abstract base sniff classes

As the abstract sniff base classes in WPCS do not have dedicated tests, but are tested via the sniffs using them, I'm adding @covers tags for these to select sniffs.

As the majority of these will at some point in the future be replaced by (fully tested) abstracts from PHPCSUtils, I'm not concerned with adding dedicated tests for these, so this will do until they are deprecated/removed.

... to all unit test files, as well as enable strict coverage recording.

Includes:
* PHPUnit config: add code coverage configuration.
    By default, when there is a code coverage configuration and Xdebug is enabled, code coverage will be generated.
    Note: generating code coverage is slow.
* Git ignore the `build` directory as created by PHPUnit to store the log files (as set up in the config file).
* Composer: add coverage script and adjust the test script.
    * When running the "normal" `run-tests`, no code coverage will be created.
    * To run the tests with code coverage, the new `coverage` script has been added.

When running PHPUnit locally, I'd recommend copying the `phpunit.xml.dist` file to `phpunit.xml` and replacing the `clover` logging with the following to allow for locally using the HTML report:
```xml
        <log type="coverage-html" target="./build/coverage-html/"/>
```

NOte: this commit does not set up code coverage checking for PRs via an external service like Coveralls or CodeCov, though I imagine we could set this up in the future as the WP organisation already has a CodeCov account (we'd need to check if we can or need permission).
As the `Helpers` in WPCS do not have dedicated tests, but are tested via the sniffs using them, I'm adding `@covers` tags for these to select sniffs.

At a later point in time, we can revisit whether or not to add dedicated tests for the Helpers.
As the abstract sniff base classes in WPCS do not have dedicated tests, but are tested via the sniffs using them, I'm adding `@covers` tags for these to select sniffs.

As the majority of these will at some point in the future be replaced by (fully tested) abstracts from PHPCSUtils, I'm not concerned with adding dedicated tests for these, so this will do until they are deprecated/removed.
Copy link
Member

@GaryJones GaryJones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dingo-d dingo-d merged commit de872bb into develop Apr 18, 2023
@dingo-d dingo-d deleted the feature/allow-for-coverage-recording branch April 18, 2023 07:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants