You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As can be seen there, code coverage for the sniffs is pretty good, but for most other areas of the code... not so much.
The test suite should be expanded to allow for merging with (more) confidence.
Some thoughts on this:
While there are tests covering parts of the PHP_CodeSniffer\Tokenizers\PHP class, these tests don't currently register code coverage due to the test set up. This may be fixable with some tweaks to the existing AbstractMethodUnitTest test case, but may also require a separate test case class to get this working. I will probably look into this myself.
Fixed via Tests: fix recording code coverage for Tokenizer tests #314
For both the Generators as well as the Reports, a new abstract test case may need to be introduced to get those tests set up more easily.
Getting started
Adding additional tests for individual sniffs will likely be most straight forward for new contributors. The CONTRIBUTING guide contains information about writing sniff related tests.
When creating additional tests for sniffs, don't get too focused on covering uncovered lines.
Think about what the sniff is checking for and get creative with writing horribly formatted code to make sure the sniff detects this correctly.
Also keep in mind that some sniffs are pretty "old" and may or may not take all new PHP syntaxes into account correctly.
Adding tests with modern PHP syntaxes is a huge help, cause even if the sniff already handles this syntax correctly, the tests will safeguard that it continues to do so, even when the code in the sniff changes.
Another area which should be reasonably straight forward to add tests for are some of the methods in the src/Util directory, like those in the Timing and Common classes.
Writing new tests for non-sniff code will be more complicated and may require some creativeness in setting those up. When in doubt on whether your approach is the right one, please discuss before execute.
When writing tests, keep in mind that the tests need to be able to run on PHP 5.4 (PHPUnit 4.x) up to PHP 8.3/4 (PHPUnit 9.x).
PRs related to this task should preferably only touch the tests for one sniff/one class/one function per PR.
As of PR #144, code coverage will now be measured and recorded for every PR and push.
The resulting reports can be found here: https://coveralls.io/github/PHPCSStandards/PHP_CodeSniffer
As can be seen there, code coverage for the sniffs is pretty good, but for most other areas of the code... not so much.
The test suite should be expanded to allow for merging with (more) confidence.
Some thoughts on this:
While there are tests covering parts of thePHP_CodeSniffer\Tokenizers\PHPclass, these tests don't currently register code coverage due to the test set up.This may be fixable with some tweaks to the existingAbstractMethodUnitTesttest case, but may also require a separate test case class to get this working.I will probably look into this myself.Fixed via Tests: fix recording code coverage for Tokenizer tests #314
Generatorsas well as theReports, a new abstract test case may need to be introduced to get those tests set up more easily.Getting started
Think about what the sniff is checking for and get creative with writing horribly formatted code to make sure the sniff detects this correctly.
Adding tests with modern PHP syntaxes is a huge help, cause even if the sniff already handles this syntax correctly, the tests will safeguard that it continues to do so, even when the code in the sniff changes.
src/Utildirectory, like those in theTimingandCommonclasses.Writing new tests for non-sniff code will be more complicated and may require some creativeness in setting those up. When in doubt on whether your approach is the right one, please discuss before execute.
When writing tests, keep in mind that the tests need to be able to run on PHP 5.4 (PHPUnit 4.x) up to PHP 8.3/4 (PHPUnit 9.x).
PRs related to this task should preferably only touch the tests for one sniff/one class/one function per PR.