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/AssignmentInCondition: improve sniff code coverage #163

Conversation

rodrigoprimo
Copy link
Contributor

Description

This PR improves the code coverage for the AssignementInCondition sniff. This sniff has some defensive code to protect against parse errors, and those were not exercised by the tests. I followed the instructions on #143 for creating parse error tests.

I also checked if there are new assignment operators added in more recent versions of PHP that are not supported by this sniff, but I did not find anything.

Suggested changelog entry

Improve AssignementInCondition sniff code coverage

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.

@rodrigoprimo rodrigoprimo force-pushed the update-assignement-in-condition-code-coverage branch from 8ac9a3e to 225c9cf Compare December 13, 2023 14:19
@jrfnl jrfnl changed the title Improve AssignementInCondition sniff code coverage Generic/AssignmentInCondition: improve sniff code coverage Dec 13, 2023
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.

LGTM with only one small remark. Will merge it once that's been fixed up. (Feel free to just amend the existing commit) Thanks @rodrigoprimo !

Doing this to be able to add more test case files to cover defensive code
in the AssignmentInCondition sniff that protects it when checking code
with parse errors.
This commit improves the test coverage for the AssignmentInCondition
sniff by adding a few more test case files to exercise the parts of the
sniff code that checks for invalid syntax.
@rodrigoprimo rodrigoprimo force-pushed the update-assignement-in-condition-code-coverage branch from 225c9cf to 1fad6ab Compare December 14, 2023 13:42
@rodrigoprimo
Copy link
Contributor Author

Thanks for reviewing this PR, @jrfnl. I implemented the change you requested and I believe it is now ready to be merged.

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.

LGTM! Thanks @rodrigoprimo.

@jrfnl jrfnl merged commit 88d3cec into PHPCSStandards:master Dec 14, 2023
38 checks passed
rodrigoprimo added a commit to rodrigoprimo/PHP_CodeSniffer that referenced this pull request Dec 15, 2023
Replacing the default value with an empty string. Per Juliette's comment
(PHPCSStandards#163 (comment))
there are three reasons why we want to do that:

- The default value has no value in practice. It is an optional argument which is not enforced via the abstract functions, but is passed in all cases, so the default is never used in practice.
- Setting the default value as file 1 also has an assumption implied, while IMO assumptions have no place in a test suite.
- Maintainability - one less thing to have to keep in sync and to guard against typos
rodrigoprimo added a commit to rodrigoprimo/PHP_CodeSniffer that referenced this pull request Dec 15, 2023
Replacing the default value with an empty string. Per Juliette's comment
(PHPCSStandards#163 (comment))
there are three reasons why we want to do that:

- The default value has no value in practice. It is an optional argument which is not enforced via the abstract functions, but is passed in all cases, so the default is never used in practice.
- Setting the default value as file 1 also has an assumption implied, while IMO assumptions have no place in a test suite.
- Maintainability - one less thing to have to keep in sync and to guard against typos
@rodrigoprimo rodrigoprimo deleted the update-assignement-in-condition-code-coverage branch December 15, 2023 13:48
jrfnl pushed a commit that referenced this pull request Dec 15, 2023
Replacing the default value with an empty string. Per Juliette's comment
(#163 (comment))
there are three reasons why we want to do that:

- The default value has no value in practice. It is an optional argument which is not enforced via the abstract functions, but is passed in all cases, so the default is never used in practice.
- Setting the default value as file 1 also has an assumption implied, while IMO assumptions have no place in a test suite.
- Maintainability - one less thing to have to keep in sync and to guard against typos
jrfnl pushed a commit that referenced this pull request Dec 15, 2023
Replacing the default value with an empty string. Per Juliette's comment
(#163 (comment))
there are three reasons why we want to do that:

- The default value has no value in practice. It is an optional argument which is not enforced via the abstract functions, but is passed in all cases, so the default is never used in practice.
- Setting the default value as file 1 also has an assumption implied, while IMO assumptions have no place in a test suite.
- Maintainability - one less thing to have to keep in sync and to guard against typos
dingo-d pushed a commit to dingo-d/PHP_CodeSniffer that referenced this pull request Dec 23, 2023
Replacing the default value with an empty string. Per Juliette's comment
(PHPCSStandards#163 (comment))
there are three reasons why we want to do that:

- The default value has no value in practice. It is an optional argument which is not enforced via the abstract functions, but is passed in all cases, so the default is never used in practice.
- Setting the default value as file 1 also has an assumption implied, while IMO assumptions have no place in a test suite.
- Maintainability - one less thing to have to keep in sync and to guard against typos
dingo-d pushed a commit to dingo-d/PHP_CodeSniffer that referenced this pull request Dec 23, 2023
Replacing the default value with an empty string. Per Juliette's comment
(PHPCSStandards#163 (comment))
there are three reasons why we want to do that:

- The default value has no value in practice. It is an optional argument which is not enforced via the abstract functions, but is passed in all cases, so the default is never used in practice.
- Setting the default value as file 1 also has an assumption implied, while IMO assumptions have no place in a test suite.
- Maintainability - one less thing to have to keep in sync and to guard against typos
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