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

QA/Tests: various code coverage tweaks #331

Merged
merged 3 commits into from Jun 29, 2022

Conversation

jrfnl
Copy link
Member

@jrfnl jrfnl commented Jun 29, 2022

GH Actions/coverage: add extra (debug) step

While the feedback shown in the setup-php step is awesome, it doesn't show the version of Xdebug used when running code coverage, while, in case of issues, the version number of Xdebug is crucial to know.

This extra step allows for that information to always be available.

I've only added the step to the code coverage job though as that's the only one for which the Xdebug version is relevant.

Also see: shivammathur/setup-php#610

PHPUnit config: isolate a number of tests from the main test suite

The functions being tested in these three test classes all use function local static variables for optimization.

Having the function local static variable will often prevent code coverage from being recorded correctly for the code as the code for setting the static will only be run when the function is first called, which may not be in the dedicated test for the function, so it makes code coverage recording highly dependent on the order in which tests are run.

In these three cases, I do believe the function local static variable is justified (for the time being, benchmarking should be able to determine for sure at some point in the future).

To still prevent missed lines in the code coverage reports, I'm moving the tests for these three functions into a separate test suite, which will run first.
This should ensure the code which sets the static will be run first when the dedicated tests for these methods are run and should allow the correct registration of code coverage for this code.

Mind: if at some point the executionOrder configuration would be added to the config/enabled, it needs to be verified how that behaves in combination with multiple test suites. But that's for later.

Ref: sebastianbergmann/php-code-coverage#913

Tests: add select @codeCoverageIgnore annotations

... for code which is only in place as defensive coding, but shouldn't be reachable under normal circumstances.

While the feedback shown in the `setup-php` step is awesome, it doesn't show the version of Xdebug used when running code coverage, while, in case of issues, the version number of Xdebug is crucial to know.

This extra step allows for that information to always be available.

I've only added the step to the code coverage job though as that's the only one for which the Xdebug version is relevant.
The functions being tested in these three test classes all use function local `static` variables for optimization.

Having the function local `static` variable will often prevent code coverage from being recorded correctly for the code as the code for setting the static will only be run when the function is first called, which may not be in the dedicated test for the function, so it makes code coverage recording highly dependant on the order in which tests are run.

In these three cases, I do believe the function local `static` variable is justified (for the time being, benchmarking should be able to determine for sure at some point in the future).

To still prevent missed lines in the code coverage reports, I'm moving the tests for these three functions into a separate test suite, which will run first.
This should ensure the code which sets the static will be run first when the dedicated tests for these methods are run and should allow the correct registration of code coverage for this code.

Mind: if at some point the `executionOrder` configuration would be added to the config/enabled, it needs to be verified how that behaves in combination with multiple test suites. But that's for later.

Ref: sebastianbergmann/php-code-coverage#913
... for code which is only in place as defensive coding, but shouldn't be reachable under normal circumstances.
@jrfnl jrfnl added this to the 1.0.0-alpha4 milestone Jun 29, 2022
@jrfnl jrfnl merged commit cbcf363 into develop Jun 29, 2022
@jrfnl jrfnl deleted the feature/various-code-coverage-fixes branch June 29, 2022 10:26
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

1 participant