Description
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\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 existingAbstractMethodUnitTest
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 theReports
, 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. - When adding tests for sniff code which is related to parse errors, keep the guidelines outlined in Tests: parse error tests for sniffs should be in their own file #143 in mind.
- When creating additional tests for sniffs, don't get too focused on covering uncovered lines.
- 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 theTiming
andCommon
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.