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

Generic/UnnecessaryFinalModifier: improve code coverage #241

Conversation

rodrigoprimo
Copy link
Contributor

Description

This PR improves the code coverage of the Generic.CodeAnalysis.UnnecessaryFinalModifier sniff. There was only one line that was not already exercised by the tests that bails early if it finds a class without a body.

I considered adding more tests with different class definitions, but I was not able to think of examples that felt relevant enough and also different enough from the tests that are already in place.

Related issues/external references

Part of #146

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
    • This change is only breaking for integrators, not for external standards or end-users.
  • Documentation improvement

PR checklist

  • I have checked there is no other PR open for the same change.
  • I have read the Contribution Guidelines.
  • I grant the project the right to include and distribute the code under the BSD-3-Clause license (and I have the right to grant these rights).
  • I have added tests to cover my changes.
  • I have verified that the code complies with the projects coding standards.
  • [Required for new sniffs] I have added XML documentation for the sniff.

Copy link
Member

@jrfnl jrfnl left a comment

Choose a reason for hiding this comment

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

Thanks for this PR @rodrigoprimo !

I considered adding more tests with different class definitions, but I was not able to think of examples that felt relevant enough and also different enough from the tests that are already in place.

What about adding some tests with final class constants as allowed since PHP 8.1 ?

@jrfnl jrfnl added this to the 3.8.x Next milestone Jan 12, 2024
@rodrigoprimo
Copy link
Contributor Author

Thanks for the review, @jrfnl!

What about adding some tests with final class constants as allowed since PHP 8.1 ?

Good point, I just pushed a new commit adding tests with final class constants.

Copy link
Member

@jrfnl jrfnl left a comment

Choose a reason for hiding this comment

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

Thanks for adding those extra tests @rodrigoprimo !

Doing this to be able to create a test with a syntax error on a separate
file.
This commit add one more test case file to exercise defensive code that
makes the sniff bail early if the class has no body.
@jrfnl jrfnl force-pushed the test-coverage-unnecessary-final-modifier branch from d1c0413 to d09b571 Compare January 12, 2024 15:45
@jrfnl
Copy link
Member

jrfnl commented Jan 12, 2024

FYI: I've rebased the PR without changes to get the code coverage to report. Will merge once the build passes.
image

@jrfnl jrfnl merged commit e419a21 into PHPCSStandards:master Jan 12, 2024
38 checks passed
@rodrigoprimo rodrigoprimo deleted the test-coverage-unnecessary-final-modifier branch January 12, 2024 16:56
@jrfnl jrfnl modified the milestones: 3.8.x Next, 3.9.0 Jan 19, 2024
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.

2 participants